[object Object]

← back to Designer Wallcoverings

TK-135: fix PG-mirror trigger abort — skip DW-prefix mfr_sku rows + make mirror step non-fatal (Shopify authoritative)

f26f24aecdf48319aa29efb945a7bd77a3a6f84e · 2026-07-27 18:58:32 -0700 · Steve

Files touched

Diff

commit f26f24aecdf48319aa29efb945a7bd77a3a6f84e
Author: Steve <steve@designerwallcoverings.com>
Date:   Mon Jul 27 18:58:32 2026 -0700

    TK-135: fix PG-mirror trigger abort — skip DW-prefix mfr_sku rows + make mirror step non-fatal (Shopify authoritative)
---
 shopify/scripts/tk135-apply-palette.js | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/shopify/scripts/tk135-apply-palette.js b/shopify/scripts/tk135-apply-palette.js
index ee1bbad5..7b62bc97 100644
--- a/shopify/scripts/tk135-apply-palette.js
+++ b/shopify/scripts/tk135-apply-palette.js
@@ -63,7 +63,9 @@ UPDATE shopify_products sp SET tags =
   CASE WHEN sp.tags IS NULL OR sp.tags='' THEN b.tag
        WHEN sp.tags ILIKE '%'||b.tag||'%' THEN sp.tags
        ELSE sp.tags || ', ' || b.tag END
-  FROM _tk135 b WHERE sp.shopify_id=b.gid;
+  FROM _tk135 b WHERE sp.shopify_id=b.gid
+    -- skip rows that would trip the mfr_sku/variant_sku integrity trigger (Shopify write still covers them; mirror re-syncs)
+    AND (sp.mfr_sku IS NULL OR sp.mfr_sku !~ '^DW[A-Z]{1,4}-[0-9]+$');
 SELECT count(*) FROM _tk135 b JOIN shopify_products sp ON sp.shopify_id=b.gid;
 COMMIT;`;
   return execFileSync('ssh', ['my-server', `sudo -u postgres psql -d dw_unified -v ON_ERROR_STOP=1 -t -A`],
@@ -95,8 +97,10 @@ function load() {
   const report = { ticket: 'TK-135', started: new Date().toISOString(), apply: APPLY, updated: [], failed: [] };
 
   if (APPLY) {
+    // PG mirror is best-effort: Shopify is the authoritative customer-facing write and the mirror re-syncs from it,
+    // so a mirror hiccup (e.g. integrity trigger) must NEVER block the Shopify write.
     try { const c = pgAppendTags(rows); console.log(`PG mirror tags appended — matched ${c}\n`); report.pg = c; }
-    catch (e) { console.error('PG write FAILED — aborting before Shopify:', e.message || e); process.exit(2); }
+    catch (e) { console.error('⚠ PG mirror write skipped (non-fatal — Shopify authoritative, mirror re-syncs):', (e.message || e).toString().split('\n')[0]); report.pgSkipped = true; }
   } else {
     console.log(`(dry-run) would PG-append ${rows.length} color tags, then Shopify metafield+tag each\n`);
     rows.slice(0, 8).forEach(r => console.log(`  · ${r.gid.split('/').pop()}  ${r.tag}  palette=${r.palette}`));

← f6f5377e TK-135: add resume (progress log) to palette apply; canary 2  ·  back to Designer Wallcoverings  ·  chore: v1.2.7 (session close — cleanWallpaper brand-aware fl 7421d43f →