| 37566 |
amit |
1 |
-- ============================================================================
|
|
|
2 |
-- Rollback: listings delisted on 2026-09-10 that had recent movement
|
|
|
3 |
-- 2026-09-10
|
|
|
4 |
-- The 2026-09-10 run of delist_inactive_listings_rolling_24m.sql predates the
|
|
|
5 |
-- v3 "not moved for a month" constraint (NEW 3). It therefore delisted 24
|
|
|
6 |
-- listings across 21 models whose partners had transacted them within the
|
|
|
7 |
-- previous month (partner movement 2026-08-12 .. 2026-09-09, while SD
|
|
|
8 |
-- warehouse movement was 2023 .. 2026-06). Under v3 those would have been
|
|
|
9 |
-- spared, so they are restored here.
|
|
|
10 |
--
|
|
|
11 |
-- THE ID LIST IS FROZEN, not re-derived. The predicate is relative to
|
|
|
12 |
-- CURDATE(), so re-deriving it on a later date -- or in another environment
|
|
|
13 |
-- whose scan tables have drifted -- would pick a different set. Pinning the
|
|
|
14 |
-- ids is what makes the same 24 listings come back everywhere.
|
|
|
15 |
--
|
|
|
16 |
-- Idempotent: re-running reactivates nothing further and reopens nothing.
|
|
|
17 |
-- ============================================================================
|
|
|
18 |
|
|
|
19 |
DROP TEMPORARY TABLE IF EXISTS _rb_listing;
|
|
|
20 |
CREATE TEMPORARY TABLE _rb_listing (tag_listing_id INT PRIMARY KEY);
|
|
|
21 |
INSERT INTO _rb_listing (tag_listing_id) VALUES
|
|
|
22 |
(5478), (5701), (5791), (5978), (5984), (6093), (6133), (6427),
|
|
|
23 |
(6550), (6594), (6624), (6645), (6780), (6851), (7038), (7935),
|
|
|
24 |
(7968), (7969), (8486), (8939), (8940), (8979), (8980), (9031);
|
|
|
25 |
|
|
|
26 |
-- ---------------------------------------------------------------------------
|
|
|
27 |
-- STEP 1 - relist
|
|
|
28 |
-- ---------------------------------------------------------------------------
|
|
|
29 |
UPDATE catalog.tag_listing tl
|
|
|
30 |
JOIN _rb_listing r ON r.tag_listing_id = tl.id
|
|
|
31 |
SET tl.active = 1,
|
|
|
32 |
tl.eol_date = NULL
|
|
|
33 |
WHERE tl.active = 0;
|
|
|
34 |
|
|
|
35 |
SELECT COUNT(*) AS relisted
|
|
|
36 |
FROM catalog.tag_listing tl
|
|
|
37 |
JOIN _rb_listing r ON r.tag_listing_id = tl.id
|
|
|
38 |
WHERE tl.active = 1;
|
|
|
39 |
|
|
|
40 |
-- ---------------------------------------------------------------------------
|
|
|
41 |
-- STEP 2 - revert the categorisation flips that depended on them.
|
|
|
42 |
--
|
|
|
43 |
-- Only models that are NO LONGER fully dark now that the listings above are
|
|
|
44 |
-- active again. A model that stays dark for other reasons keeps its OTHER
|
|
|
45 |
-- row, which is still correct.
|
|
|
46 |
-- ---------------------------------------------------------------------------
|
|
|
47 |
DROP TEMPORARY TABLE IF EXISTS _rb_model;
|
|
|
48 |
CREATE TEMPORARY TABLE _rb_model (catalog_id INT PRIMARY KEY, cc_id INT, prev_status VARCHAR(299));
|
|
|
49 |
|
|
|
50 |
INSERT INTO _rb_model (catalog_id, cc_id, prev_status)
|
|
|
51 |
SELECT x.catalog_id, x.cc_id, x.prev_status
|
|
|
52 |
FROM catalog._delist_cc_audit x
|
|
|
53 |
JOIN catalog.item i2 ON i2.catalog_item_id = x.catalog_id
|
|
|
54 |
JOIN catalog.tag_listing t2 ON t2.item_id = i2.id
|
|
|
55 |
JOIN _rb_listing r ON r.tag_listing_id = t2.id
|
|
|
56 |
WHERE x.run_date = '2026-09-10'
|
|
|
57 |
GROUP BY x.catalog_id, x.cc_id, x.prev_status;
|
|
|
58 |
|
|
|
59 |
SELECT COUNT(*) AS models_to_revert FROM _rb_model;
|
|
|
60 |
|
|
|
61 |
-- 2a. drop the OTHER row the run opened
|
|
|
62 |
DELETE cc FROM catalog.catagoriesd_catalog cc
|
|
|
63 |
JOIN _rb_model m ON m.catalog_id = cc.catalog_id
|
|
|
64 |
WHERE cc.status = 'OTHER'
|
|
|
65 |
AND cc.end_date IS NULL
|
|
|
66 |
AND cc.start_date = '2026-09-10';
|
|
|
67 |
|
|
|
68 |
-- 2b. reopen the row the run closed, restoring its original status
|
|
|
69 |
UPDATE catalog.catagoriesd_catalog cc
|
|
|
70 |
JOIN _rb_model m ON m.cc_id = cc.id
|
|
|
71 |
SET cc.end_date = NULL,
|
|
|
72 |
cc.status = m.prev_status
|
|
|
73 |
WHERE cc.end_date = '2026-09-09';
|
|
|
74 |
|
|
|
75 |
-- 2c. drop the audit rows for what we just reverted, so _delist_cc_audit keeps
|
|
|
76 |
-- describing only categorisation the job still owns
|
|
|
77 |
DELETE x FROM catalog._delist_cc_audit x
|
|
|
78 |
JOIN _rb_model m ON m.cc_id = x.cc_id
|
|
|
79 |
WHERE x.run_date = '2026-09-10';
|
|
|
80 |
|
|
|
81 |
-- ---------------------------------------------------------------------------
|
|
|
82 |
-- STEP 3 - drop the delist audit rows for the relisted listings, so
|
|
|
83 |
-- _delist_audit continues to describe only what is actually delisted.
|
|
|
84 |
-- ---------------------------------------------------------------------------
|
|
|
85 |
DELETE a FROM catalog._delist_audit a
|
|
|
86 |
JOIN _rb_listing r ON r.tag_listing_id = a.tag_listing_id
|
|
|
87 |
WHERE a.run_date = '2026-09-10';
|
|
|
88 |
|
|
|
89 |
-- ---------------------------------------------------------------------------
|
|
|
90 |
-- STEP 4 - Solr. As with the delist itself, no event is published; the
|
|
|
91 |
-- 06:00/18:00 reindex picks the relisting up, or force --pushDataToSolr.
|
|
|
92 |
-- ---------------------------------------------------------------------------
|