[object Object]

← back to Designer Wallcoverings

activate-gated: layer mfr_sku near-dupe guard + pre-2025 age gate onto re-intro guard (no old pattern activates as new, TK-10480)

0aa9680c009e52706e749ac4b79511018225fc4a · 2026-08-12 08:13:32 -0700 · Steve

Files touched

Diff

commit 0aa9680c009e52706e749ac4b79511018225fc4a
Author: Steve <steve@designerwallcoverings.com>
Date:   Wed Aug 12 08:13:32 2026 -0700

    activate-gated: layer mfr_sku near-dupe guard + pre-2025 age gate onto re-intro guard (no old pattern activates as new, TK-10480)
---
 shopify/scripts/cadence/activate-gated.js | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/shopify/scripts/cadence/activate-gated.js b/shopify/scripts/cadence/activate-gated.js
index 2878a076..057c735a 100644
--- a/shopify/scripts/cadence/activate-gated.js
+++ b/shopify/scripts/cadence/activate-gated.js
@@ -268,15 +268,30 @@ const SL = 'single_line_text_field';
           // standard_conforming_strings=on, so doubling single-quotes ('') is the complete,
           // correct Postgres string-literal escaping for the externally-sourced title.
           const t = String(n.title || '').replace(/'/g, "''");
-          const reintro = t && (psql(
+          const idEsc = String(n.id).replace(/'/g, "''");
+          const reintroTitle = t && (psql(
             `SELECT 1 FROM shopify_products WHERE title='${t}' `
             + `AND status IN ('ACTIVE','ARCHIVED','DELETED_FROM_SHOPIFY') `
-            + `AND shopify_id <> '${String(n.id).replace(/'/g,"''")}' LIMIT 1;`
+            + `AND shopify_id <> '${idEsc}' LIMIT 1;`
           ) || '').trim() === '1';
+          // ADDED (Steve 2026-08-12, TK-10480): the title guard alone let 285 mfr_sku
+          // colorway-dupes-of-ACTIVE + 665 pre-2025 OLD records stage as "new". Layer a
+          // MFR_SKU near-dupe guard (stable pattern identity) + a pre-2025 AGE GATE, keyed
+          // on this DRAFT's own mirror row. Fail-safe: only ever keeps DRAFT.
+          const reintroSkuOrOld = (psql(
+            `SELECT 1 FROM shopify_products d WHERE d.shopify_id='${idEsc}' AND (`
+            + ` d.created_at_shopify < '2025-01-01'`
+            + ` OR (coalesce(d.mfr_sku,'')<>'' AND EXISTS (SELECT 1 FROM shopify_products a`
+            + `   WHERE upper(trim(a.mfr_sku))=upper(trim(d.mfr_sku))`
+            + `   AND a.status IN ('ACTIVE','ARCHIVED','DELETED_FROM_SHOPIFY') AND a.shopify_id<>d.shopify_id))`
+            + `) LIMIT 1;`
+          ) || '').trim() === '1';
+          const reintro = reintroTitle || reintroSkuOrOld;
           if (reintro) {
             reintroBlocked++;
-            console.log(`  ↩︎ re-intro guard: "${n.title}" already on the store — kept DRAFT (not a new pattern)`);
-            fs.appendFileSync(AUDIT, JSON.stringify({ ts:new Date().toISOString(), vendor, dw_sku:(c&&c.dw_sku), product_id:n.id, action:'reintro-blocked', title:n.title }) + '\n');
+            const why = reintroTitle ? 'title already on store' : 'mfr_sku already on store / pre-2025 old record';
+            console.log(`  ↩︎ re-intro guard: "${n.title}" — ${why}, kept DRAFT (not a new pattern)`);
+            fs.appendFileSync(AUDIT, JSON.stringify({ ts:new Date().toISOString(), vendor, dw_sku:(c&&c.dw_sku), product_id:n.id, action:'reintro-blocked', reason:why, title:n.title }) + '\n');
             continue;
           }
           drafts.push({ gid: n.id, mfPush, dw_sku: (c && c.dw_sku) || '' });

← 7eebbd74 auto-data-snapshot: 2026-08-12T06:18:56 (2 data files) — sho  ·  back to Designer Wallcoverings  ·  auto-data-snapshot: 2026-08-12T09:56:27 (1 data files) — scr 83f09c93 →