Subversion Repositories SmartDukaan

Rev

Rev 37640 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 37640 Rev 37646
Line 162... Line 162...
162
--
162
--
163
--  start_date / end_date are still NOT NULL at this point (they are dropped in
163
--  start_date / end_date are still NOT NULL at this point (they are dropped in
164
--  schema PASS 3), so sentinel values are supplied.
164
--  schema PASS 3), so sentinel values are supplied.
165
-- ---------------------------------------------------------------------------
165
-- ---------------------------------------------------------------------------
166
 
166
 
-
 
167
-- ---------------------------------------------------------------------------
-
 
168
--  DEDUPE - one attributes row per catalog.
-
 
169
--
-
 
170
--  The old model allowed several date-windowed deals for the same catalog, so a
-
 
171
--  model re-promoted in a later window has more than one row. That is legal
-
 
172
--  history under the old design and a duplicate under the new one, where the
-
 
173
--  row IS the attributes. Keep the newest and drop the rest.
-
 
174
--
-
 
175
--  Found on prod 2026-09-15: catalog 1026529 (Realme) had two rows, created
-
 
176
--  2026-08-19 and 2026-09-02 by the same user, with IDENTICAL attributes - so
-
 
177
--  keeping the newest lost nothing. Verify that before running elsewhere; if the
-
 
178
--  attributes differ, decide which is current instead of taking MAX(id) blindly.
-
 
179
--
-
 
180
--  Must run before the unique key in schema PASS 2, which this is what makes
-
 
181
--  possible.
-
 
182
-- ---------------------------------------------------------------------------
-
 
183
DELETE m FROM catalog.model_hot_deal m
-
 
184
JOIN (SELECT catalog_item_id, MAX(id) AS keep_id
-
 
185
      FROM catalog.model_hot_deal
-
 
186
      GROUP BY catalog_item_id HAVING COUNT(*) > 1) d
-
 
187
  ON d.catalog_item_id = m.catalog_item_id AND m.id < d.keep_id;
-
 
188
 
167
-- existing rows: backfill oem_brand from the freeze table
189
-- existing rows: backfill oem_brand from the freeze table
168
UPDATE catalog.model_hot_deal mhd
190
UPDATE catalog.model_hot_deal mhd
169
JOIN catalog._hot_deal_brand_freeze f
191
JOIN catalog._hot_deal_brand_freeze f
170
     ON f.level = 'catalog' AND f.row_id = mhd.catalog_item_id
192
     ON f.level = 'catalog' AND f.row_id = mhd.catalog_item_id
171
SET mhd.oem_brand = f.old_brand
193
SET mhd.oem_brand = f.old_brand