| 37778 |
amit |
1 |
-- ============================================================================
|
|
|
2 |
-- Undo wrongly retired model categorisations 2026-09-24
|
|
|
3 |
--
|
|
|
4 |
-- The delist cron's STEP 4 used to scan house-wide for "fully dark" mobile
|
|
|
5 |
-- models and move them to OTHER. That also caught models that were dark only
|
|
|
6 |
-- because they were not listed yet (new launches) or were paused by hand,
|
|
|
7 |
-- and retired them the morning after they were categorised. Fixed in
|
|
|
8 |
-- CatalogDelistServiceImpl / delist_inactive_listings_rolling_24m.sql: STEP 4
|
|
|
9 |
-- now only retires a model whose listing that same run delisted.
|
|
|
10 |
--
|
|
|
11 |
-- This restores the models the fixed logic would NOT have retired:
|
|
|
12 |
-- * latest retirement run had no _delist_audit row for any of the model's
|
|
|
13 |
-- items on that run_date (the cron did not delist it), AND
|
|
|
14 |
-- * run after the 2026-09-10 backfill, or the model was added within 30
|
|
|
15 |
-- days before that run (older never-listed models in the backfill were
|
|
|
16 |
-- meant to be retired and stay OTHER), AND
|
|
|
17 |
-- * the model is still on the OTHER row that run opened (models already
|
|
|
18 |
-- restored by hand, e.g. Nothing 1026596-603, are left alone).
|
|
|
19 |
--
|
|
|
20 |
-- Restore = delete the OTHER row the cron opened and reopen the row it
|
|
|
21 |
-- closed (end_date -> NULL), so history reads as if it never happened.
|
|
|
22 |
-- 2026-09-24 preview: 16 models.
|
|
|
23 |
--
|
|
|
24 |
-- Rollback: catalog._bak_cc_restore_20260924 holds every row of the affected
|
|
|
25 |
-- catalogs as they were before this ran.
|
|
|
26 |
-- ============================================================================
|
|
|
27 |
|
|
|
28 |
DROP TEMPORARY TABLE IF EXISTS _cc_restore;
|
|
|
29 |
CREATE TEMPORARY TABLE _cc_restore (
|
|
|
30 |
catalog_id INT PRIMARY KEY,
|
|
|
31 |
other_id INT NOT NULL,
|
|
|
32 |
reopen_id INT NOT NULL
|
|
|
33 |
);
|
|
|
34 |
|
|
|
35 |
INSERT INTO _cc_restore (catalog_id, other_id, reopen_id)
|
|
|
36 |
SELECT a.catalog_id, o.id, a.cc_id
|
|
|
37 |
FROM catalog._delist_cc_audit a
|
|
|
38 |
JOIN catalog.catagoriesd_catalog o
|
|
|
39 |
ON o.catalog_id = a.catalog_id AND o.end_date IS NULL
|
|
|
40 |
AND o.status = 'OTHER' AND o.start_date = a.run_date
|
|
|
41 |
JOIN catalog.catagoriesd_catalog p
|
|
|
42 |
ON p.id = a.cc_id AND p.end_date = a.run_date - INTERVAL 1 DAY
|
|
|
43 |
WHERE a.run_date = (SELECT MAX(a2.run_date) FROM catalog._delist_cc_audit a2
|
|
|
44 |
WHERE a2.catalog_id = a.catalog_id)
|
|
|
45 |
AND NOT EXISTS (SELECT 1 FROM catalog._delist_audit d
|
|
|
46 |
JOIN catalog.item i ON i.id = d.item_id
|
|
|
47 |
WHERE i.catalog_item_id = a.catalog_id AND d.run_date = a.run_date)
|
|
|
48 |
AND (a.run_date > '2026-09-10'
|
|
|
49 |
OR (SELECT MIN(i.addedOn) FROM catalog.item i
|
|
|
50 |
WHERE i.catalog_item_id = a.catalog_id) >= a.run_date - INTERVAL 30 DAY);
|
|
|
51 |
|
|
|
52 |
CREATE TABLE catalog._bak_cc_restore_20260924 AS
|
|
|
53 |
SELECT cc.* FROM catalog.catagoriesd_catalog cc
|
|
|
54 |
WHERE cc.catalog_id IN (SELECT catalog_id FROM _cc_restore);
|
|
|
55 |
|
|
|
56 |
START TRANSACTION;
|
|
|
57 |
|
|
|
58 |
DELETE cc FROM catalog.catagoriesd_catalog cc
|
|
|
59 |
JOIN _cc_restore r ON r.other_id = cc.id;
|
|
|
60 |
|
|
|
61 |
UPDATE catalog.catagoriesd_catalog cc
|
|
|
62 |
JOIN _cc_restore r ON r.reopen_id = cc.id
|
|
|
63 |
SET cc.end_date = NULL;
|
|
|
64 |
|
|
|
65 |
COMMIT;
|
|
|
66 |
|
|
|
67 |
-- Solr picks this up at the next 06:00 / 18:00 full reindex.
|