[object Object]

← back to Dw Validator Debug TK11314

TK-10817: Carnegie 57-item backfill — 45 body_html + 12 draft on live Shopify (restore-map + result)

172d5a2cf8668e32af289c9760eeb95040967f20 · 2026-08-24 12:21:32 -0700 · Steve

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Files touched

Diff

commit 172d5a2cf8668e32af289c9760eeb95040967f20
Author: Steve <steve@designerwallcoverings.com>
Date:   Mon Aug 24 12:21:32 2026 -0700

    TK-10817: Carnegie 57-item backfill — 45 body_html + 12 draft on live Shopify (restore-map + result)
    
    Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---
 ...st-backfill-2026-08-22-KAMATERA-kravet-only.sql |  24 ++
 ...-backfill-RESTORE-2026-08-24T19-18-34-059Z.json | 352 +++++++++++++++++++++
 ...e-backfill-RESULT-2026-08-24T19-18-34-059Z.json | 330 +++++++++++++++++++
 scripts/carnegie-backfill-exec.mjs                 | 156 +++++++++
 4 files changed, 862 insertions(+)

diff --git a/DW-Agents/vendor-command-center/cost-backfill-2026-08-22-KAMATERA-kravet-only.sql b/DW-Agents/vendor-command-center/cost-backfill-2026-08-22-KAMATERA-kravet-only.sql
new file mode 100644
index 00000000..ddcbc2cf
--- /dev/null
+++ b/DW-Agents/vendor-command-center/cost-backfill-2026-08-22-KAMATERA-kravet-only.sql
@@ -0,0 +1,24 @@
+-- Kamatera-canonical variant: Kravet step ONLY.
+-- WHY: justin_david_pricing_2026 is a Mac2-ONLY staging table (split-ownership doctrine:
+-- vendor staging tables are Mac2-canonical), so the full APPLY.sql aborts on Kamatera.
+-- This runs ONLY the Kravet authoritative step (source table exists on Kamatera).
+-- The ~1,517 JD rows are already backfilled on the Mac2 mirror; if they're wanted on
+-- Kamatera too, push them by shopify_id as a separate targeted value-copy.
+BEGIN;
+DROP TABLE IF EXISTS cost_backfill_restore_20260822;
+CREATE TABLE cost_backfill_restore_20260822 AS
+SELECT shopify_id, cost_price AS old_cost_price, cost_source AS old_cost_source
+FROM shopify_products WHERE status='ACTIVE' AND (cost_price IS NULL OR cost_price::numeric=0);
+
+UPDATE shopify_products sp
+SET cost_price=k.whls, cost_source='kravet_authoritative_pricing.new_whls (exact) backfill 2026-08-24'
+FROM (SELECT mfr_sku, max(new_whls) whls FROM kravet_authoritative_pricing WHERE new_whls>0 GROUP BY 1) k
+WHERE sp.status='ACTIVE' AND (sp.cost_price IS NULL OR sp.cost_price::numeric=0)
+  AND sp.mfr_sku = k.mfr_sku;
+
+SELECT count(*) FILTER (WHERE cost_source LIKE '%backfill 2026-08-2%') AS total_backfilled,
+       round(100.0*count(*) FILTER (WHERE cost_price IS NOT NULL AND cost_price::numeric>0)/count(*),1) AS pct_with_cost
+FROM shopify_products WHERE status='ACTIVE';
+COMMIT;
+-- REVERT: UPDATE shopify_products sp SET cost_price=r.old_cost_price, cost_source=r.old_cost_source
+--   FROM cost_backfill_restore_20260822 r WHERE sp.shopify_id=r.shopify_id;
diff --git a/data/carnegie-backfill-RESTORE-2026-08-24T19-18-34-059Z.json b/data/carnegie-backfill-RESTORE-2026-08-24T19-18-34-059Z.json
new file mode 100644
index 00000000..a391e675
--- /dev/null
+++ b/data/carnegie-backfill-RESTORE-2026-08-24T19-18-34-059Z.json
@@ -0,0 +1,352 @@
+{
+  "ts": "2026-08-24T19:18:34.060Z",
+  "ticket": "TK-10817",
+  "store": "designer-laboratory-sandbox.myshopify.com",
+  "api": "2024-10",
+  "desc": [
+    {
+      "shopify_id": "gid://shopify/Product/7923220774963",
+      "sku": "DWAG-378844",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923233095731",
+      "sku": "DWAG-380545",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923233128499",
+      "sku": "DWAG-380546",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923233161267",
+      "sku": "DWAG-380547",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923233226803",
+      "sku": "DWAG-380548",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923233292339",
+      "sku": "DWAG-380549",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923233390643",
+      "sku": "DWAG-380550",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923233456179",
+      "sku": "DWAG-380551",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923233521715",
+      "sku": "DWAG-380552",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923233587251",
+      "sku": "DWAG-380553",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923242532915",
+      "sku": "DWAG-380554",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923242565683",
+      "sku": "DWAG-380555",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923242598451",
+      "sku": "DWAG-380556",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923242663987",
+      "sku": "DWAG-380557",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923242762291",
+      "sku": "DWAG-380558",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923242827827",
+      "sku": "DWAG-380559",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923242860595",
+      "sku": "DWAG-380560",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923242958899",
+      "sku": "DWAG-380561",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923208716339",
+      "sku": "DWAG-380666",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923208781875",
+      "sku": "DWAG-380667",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923208814643",
+      "sku": "DWAG-380668",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923208847411",
+      "sku": "DWAG-380669",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923208880179",
+      "sku": "DWAG-380670",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923208978483",
+      "sku": "DWAG-380671",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923209076787",
+      "sku": "DWAG-380672",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923209175091",
+      "sku": "DWAG-380673",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923209273395",
+      "sku": "DWAG-380674",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923251806259",
+      "sku": "DWAG-381671",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923251871795",
+      "sku": "DWAG-381672",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923251937331",
+      "sku": "DWAG-381673",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923252002867",
+      "sku": "DWAG-381674",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923252068403",
+      "sku": "DWAG-381675",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923252133939",
+      "sku": "DWAG-381676",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923196231731",
+      "sku": "DWAG-381677",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923196330035",
+      "sku": "DWAG-381678",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923196395571",
+      "sku": "DWAG-381679",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923196461107",
+      "sku": "DWAG-381680",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923196559411",
+      "sku": "DWAG-381681",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923196624947",
+      "sku": "DWAG-381682",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923225985075",
+      "sku": "DWAG-381901",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923226050611",
+      "sku": "DWAG-381902",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923226116147",
+      "sku": "DWAG-381903",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923226214451",
+      "sku": "DWAG-381904",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923406209075",
+      "sku": "DWAG-381905",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923286802483",
+      "sku": "DWAG-381906",
+      "old_body_html": "",
+      "old_status": "archived"
+    }
+  ],
+  "draft": [
+    {
+      "shopify_id": "gid://shopify/Product/7923320881203",
+      "sku": "DWAG-381916",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923320913971",
+      "sku": "DWAG-381917",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923320946739",
+      "sku": "DWAG-381918",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923321012275",
+      "sku": "DWAG-381919",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923321143347",
+      "sku": "DWAG-381920",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923321208883",
+      "sku": "DWAG-381921",
+      "old_body_html": "",
+      "old_status": "archived"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923216187443",
+      "sku": "DWAG-381922",
+      "old_body_html": "",
+      "old_status": "active"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923216252979",
+      "sku": "DWAG-381923",
+      "old_body_html": "",
+      "old_status": "active"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923216318515",
+      "sku": "DWAG-381924",
+      "old_body_html": "",
+      "old_status": "active"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923216384051",
+      "sku": "DWAG-381925",
+      "old_body_html": "",
+      "old_status": "active"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923216449587",
+      "sku": "DWAG-381926",
+      "old_body_html": "",
+      "old_status": "active"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923216515123",
+      "sku": "DWAG-381927",
+      "old_body_html": "",
+      "old_status": "active"
+    }
+  ]
+}
\ No newline at end of file
diff --git a/data/carnegie-backfill-RESULT-2026-08-24T19-18-34-059Z.json b/data/carnegie-backfill-RESULT-2026-08-24T19-18-34-059Z.json
new file mode 100644
index 00000000..907e1856
--- /dev/null
+++ b/data/carnegie-backfill-RESULT-2026-08-24T19-18-34-059Z.json
@@ -0,0 +1,330 @@
+{
+  "written": [
+    {
+      "shopify_id": "gid://shopify/Product/7923220774963",
+      "sku": "DWAG-378844"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923233095731",
+      "sku": "DWAG-380545"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923233128499",
+      "sku": "DWAG-380546"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923233161267",
+      "sku": "DWAG-380547"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923233226803",
+      "sku": "DWAG-380548"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923233292339",
+      "sku": "DWAG-380549"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923233390643",
+      "sku": "DWAG-380550"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923233456179",
+      "sku": "DWAG-380551"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923233521715",
+      "sku": "DWAG-380552"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923233587251",
+      "sku": "DWAG-380553"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923242532915",
+      "sku": "DWAG-380554"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923242565683",
+      "sku": "DWAG-380555"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923242598451",
+      "sku": "DWAG-380556"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923242663987",
+      "sku": "DWAG-380557"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923242762291",
+      "sku": "DWAG-380558"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923242827827",
+      "sku": "DWAG-380559"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923242860595",
+      "sku": "DWAG-380560"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923242958899",
+      "sku": "DWAG-380561"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923208716339",
+      "sku": "DWAG-380666"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923208781875",
+      "sku": "DWAG-380667"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923208814643",
+      "sku": "DWAG-380668"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923208847411",
+      "sku": "DWAG-380669"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923208880179",
+      "sku": "DWAG-380670"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923208978483",
+      "sku": "DWAG-380671"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923209076787",
+      "sku": "DWAG-380672"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923209175091",
+      "sku": "DWAG-380673"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923209273395",
+      "sku": "DWAG-380674"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923251806259",
+      "sku": "DWAG-381671"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923251871795",
+      "sku": "DWAG-381672"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923251937331",
+      "sku": "DWAG-381673"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923252002867",
+      "sku": "DWAG-381674"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923252068403",
+      "sku": "DWAG-381675"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923252133939",
+      "sku": "DWAG-381676"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923196231731",
+      "sku": "DWAG-381677"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923196330035",
+      "sku": "DWAG-381678"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923196395571",
+      "sku": "DWAG-381679"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923196461107",
+      "sku": "DWAG-381680"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923196559411",
+      "sku": "DWAG-381681"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923196624947",
+      "sku": "DWAG-381682"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923225985075",
+      "sku": "DWAG-381901"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923226050611",
+      "sku": "DWAG-381902"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923226116147",
+      "sku": "DWAG-381903"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923226214451",
+      "sku": "DWAG-381904"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923406209075",
+      "sku": "DWAG-381905"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923286802483",
+      "sku": "DWAG-381906"
+    }
+  ],
+  "skipped_guard": [],
+  "errored": [],
+  "drafted": [
+    {
+      "shopify_id": "gid://shopify/Product/7923320881203",
+      "sku": "DWAG-381916"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923320913971",
+      "sku": "DWAG-381917"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923320946739",
+      "sku": "DWAG-381918"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923321012275",
+      "sku": "DWAG-381919"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923321143347",
+      "sku": "DWAG-381920"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923321208883",
+      "sku": "DWAG-381921"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923216187443",
+      "sku": "DWAG-381922"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923216252979",
+      "sku": "DWAG-381923"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923216318515",
+      "sku": "DWAG-381924"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923216384051",
+      "sku": "DWAG-381925"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923216449587",
+      "sku": "DWAG-381926"
+    },
+    {
+      "shopify_id": "gid://shopify/Product/7923216515123",
+      "sku": "DWAG-381927"
+    }
+  ],
+  "draft_errored": [],
+  "not_found": [],
+  "restore_map": "/Users/macstudio3/Projects/Designer-Wallcoverings/data/carnegie-backfill-RESTORE-2026-08-24T19-18-34-059Z.json",
+  "verify": {
+    "desc_sample": [
+      {
+        "sku": "DWAG-378844",
+        "body_len": 374,
+        "ok": true
+      },
+      {
+        "sku": "DWAG-380545",
+        "body_len": 496,
+        "ok": true
+      },
+      {
+        "sku": "DWAG-380546",
+        "body_len": 504,
+        "ok": true
+      },
+      {
+        "sku": "DWAG-380547",
+        "body_len": 506,
+        "ok": true
+      },
+      {
+        "sku": "DWAG-380548",
+        "body_len": 504,
+        "ok": true
+      }
+    ],
+    "draft_all": [
+      {
+        "sku": "DWAG-381916",
+        "status": "draft",
+        "ok": true
+      },
+      {
+        "sku": "DWAG-381917",
+        "status": "draft",
+        "ok": true
+      },
+      {
+        "sku": "DWAG-381918",
+        "status": "draft",
+        "ok": true
+      },
+      {
+        "sku": "DWAG-381919",
+        "status": "draft",
+        "ok": true
+      },
+      {
+        "sku": "DWAG-381920",
+        "status": "draft",
+        "ok": true
+      },
+      {
+        "sku": "DWAG-381921",
+        "status": "draft",
+        "ok": true
+      },
+      {
+        "sku": "DWAG-381922",
+        "status": "draft",
+        "ok": true
+      },
+      {
+        "sku": "DWAG-381923",
+        "status": "draft",
+        "ok": true
+      },
+      {
+        "sku": "DWAG-381924",
+        "status": "draft",
+        "ok": true
+      },
+      {
+        "sku": "DWAG-381925",
+        "status": "draft",
+        "ok": true
+      },
+      {
+        "sku": "DWAG-381926",
+        "status": "draft",
+        "ok": true
+      },
+      {
+        "sku": "DWAG-381927",
+        "status": "draft",
+        "ok": true
+      }
+    ]
+  }
+}
\ No newline at end of file
diff --git a/scripts/carnegie-backfill-exec.mjs b/scripts/carnegie-backfill-exec.mjs
new file mode 100644
index 00000000..8e871d1e
--- /dev/null
+++ b/scripts/carnegie-backfill-exec.mjs
@@ -0,0 +1,156 @@
+#!/usr/bin/env node
+// TK-10817 — Carnegie 57-item backfill executor (APPROVED gated write, human gate CLEARED 2026-08-24)
+// LIVE store: designer-laboratory-sandbox.myshopify.com — customer-facing, authoritative.
+// SAFE: backup-first restore-map BEFORE any write; skip-if-nonempty guard on the 45; reversible.
+// Writes ONLY the 57 enumerated shopify_ids. Touches nothing else.
+import fs from 'fs';
+import path from 'path';
+
+const ROOT = '/Users/macstudio3/Projects/Designer-Wallcoverings';
+const envTxt = fs.readFileSync(path.join(ROOT, '.env'), 'utf8');
+const env = Object.fromEntries(envTxt.split('\n').filter(l => l.includes('=')).map(l => {
+  const i = l.indexOf('='); return [l.slice(0, i).trim(), l.slice(i + 1).trim()];
+}));
+const DOMAIN = env.SHOPIFY_STORE_DOMAIN || 'designer-laboratory-sandbox.myshopify.com';
+const TOKEN = env.SHOPIFY_ADMIN_TOKEN || env.SHOPIFY_ADMIN_ACCESS_TOKEN;
+const API = '2024-10';
+if (!TOKEN) { console.error('NO TOKEN'); process.exit(1); }
+
+const descRows = JSON.parse(fs.readFileSync(path.join(ROOT, 'data/carnegie-desc-backfill-CORRECTED-2026-08-24T12-04-31.json'), 'utf8'));
+const draftRows = JSON.parse(fs.readFileSync(path.join(ROOT, 'data/carnegie-draft-list-2026-08-24T12-04-55.json'), 'utf8'));
+
+const ISO = new Date().toISOString().replace(/[:.]/g, '-');
+const RESTORE_PATH = path.join(ROOT, `data/carnegie-backfill-RESTORE-${ISO}.json`);
+
+const numId = gid => gid.replace('gid://shopify/Product/', '');
+const sleep = ms => new Promise(r => setTimeout(r, ms));
+
+async function rest(method, endpoint, body) {
+  const url = `https://${DOMAIN}/admin/api/${API}/${endpoint}`;
+  const res = await fetch(url, {
+    method,
+    headers: { 'X-Shopify-Access-Token': TOKEN, 'Content-Type': 'application/json' },
+    body: body ? JSON.stringify(body) : undefined,
+  });
+  const remain = res.headers.get('x-shopify-shop-api-call-limit');
+  const txt = await res.text();
+  let json; try { json = JSON.parse(txt); } catch { json = { _raw: txt }; }
+  return { status: res.status, json, remain };
+}
+
+function stripLen(html) {
+  if (!html) return 0;
+  return String(html).replace(/<[^>]*>/g, '').replace(/&nbsp;/g, ' ').trim().length;
+}
+
+(async () => {
+  const restoreMap = { ts: new Date().toISOString(), ticket: 'TK-10817', store: DOMAIN, api: API, desc: [], draft: [] };
+  const result = { written: [], skipped_guard: [], errored: [], drafted: [], draft_errored: [], not_found: [] };
+
+  // ---- PHASE 1: BACKUP-FIRST GET all 45 desc + all 12 draft, record current state ----
+  console.log(`\n=== PHASE 1: BACKUP (GET current live state for all 57) ===`);
+  const descPlan = [];
+  for (const r of descRows) {
+    const id = numId(r.shopify_id);
+    const g = await rest('GET', `products/${id}.json?fields=id,title,body_html,status`);
+    await sleep(520);
+    if (g.status === 404 || !g.json.product) {
+      result.not_found.push({ shopify_id: r.shopify_id, sku: r.sku, phase: 'desc-get', status: g.status });
+      console.log(`  NOT_FOUND desc ${r.sku} (${id}) status=${g.status}`);
+      continue;
+    }
+    const live = g.json.product;
+    const liveBody = live.body_html || '';
+    restoreMap.desc.push({ shopify_id: r.shopify_id, sku: r.sku, old_body_html: liveBody, old_status: live.status });
+    const len = stripLen(liveBody);
+    if (len > 5) {
+      // GUARD: live body already non-empty -> SKIP, do not overwrite
+      result.skipped_guard.push({ shopify_id: r.shopify_id, sku: r.sku, live_len: len });
+      console.log(`  GUARD-SKIP ${r.sku} (${id}) live body already ${len} chars`);
+    } else {
+      descPlan.push({ id, gid: r.shopify_id, sku: r.sku, new_body_html: r.new_body_html });
+    }
+  }
+  for (const r of draftRows) {
+    const id = numId(r.shopify_id);
+    const g = await rest('GET', `products/${id}.json?fields=id,title,body_html,status`);
+    await sleep(520);
+    if (g.status === 404 || !g.json.product) {
+      result.not_found.push({ shopify_id: r.shopify_id, sku: r.sku, phase: 'draft-get', status: g.status });
+      console.log(`  NOT_FOUND draft ${r.sku} (${id}) status=${g.status}`);
+      continue;
+    }
+    const live = g.json.product;
+    restoreMap.draft.push({ shopify_id: r.shopify_id, sku: r.sku, old_body_html: live.body_html || '', old_status: live.status });
+  }
+
+  // WRITE RESTORE-MAP BEFORE ANY MUTATION
+  fs.writeFileSync(RESTORE_PATH, JSON.stringify(restoreMap, null, 2));
+  console.log(`\nRESTORE-MAP written: ${RESTORE_PATH}`);
+  console.log(`  desc backed up: ${restoreMap.desc.length}, draft backed up: ${restoreMap.draft.length}`);
+  console.log(`  desc to WRITE (passed guard): ${descPlan.length}, skipped-by-guard: ${result.skipped_guard.length}`);
+
+  // ---- PHASE 2: WRITE 45 (only guard-passers) ----
+  console.log(`\n=== PHASE 2: WRITE body_html (${descPlan.length} products) ===`);
+  for (const p of descPlan) {
+    const u = await rest('PUT', `products/${p.id}.json`, { product: { id: Number(p.id), body_html: p.new_body_html } });
+    await sleep(520);
+    if (u.status === 200 && u.json.product) {
+      result.written.push({ shopify_id: p.gid, sku: p.sku });
+      console.log(`  WROTE ${p.sku} (${p.id}) [rate ${u.remain}]`);
+    } else {
+      result.errored.push({ shopify_id: p.gid, sku: p.sku, status: u.status, err: JSON.stringify(u.json).slice(0, 200) });
+      console.log(`  ERROR desc ${p.sku} (${p.id}) status=${u.status} ${JSON.stringify(u.json).slice(0,160)}`);
+    }
+  }
+
+  // ---- PHASE 3: DRAFT the 12 ----
+  console.log(`\n=== PHASE 3: set status=draft (${draftRows.length} finished-goods) ===`);
+  for (const r of draftRows) {
+    const id = numId(r.shopify_id);
+    if (result.not_found.some(n => n.shopify_id === r.shopify_id)) continue;
+    const u = await rest('PUT', `products/${id}.json`, { product: { id: Number(id), status: 'draft' } });
+    await sleep(520);
+    if (u.status === 200 && u.json.product && u.json.product.status === 'draft') {
+      result.drafted.push({ shopify_id: r.shopify_id, sku: r.sku });
+      console.log(`  DRAFTED ${r.sku} (${id}) [rate ${u.remain}]`);
+    } else {
+      result.draft_errored.push({ shopify_id: r.shopify_id, sku: r.sku, status: u.status, err: JSON.stringify(u.json).slice(0, 200) });
+      console.log(`  ERROR draft ${r.sku} (${id}) status=${u.status}`);
+    }
+  }
+
+  // ---- PHASE 4: VERIFY sample (5 of written + all drafted) ----
+  console.log(`\n=== PHASE 4: VERIFY ===`);
+  const verify = { desc_sample: [], draft_all: [] };
+  const sample = result.written.slice(0, 5);
+  for (const s of sample) {
+    const g = await rest('GET', `products/${numId(s.shopify_id)}.json?fields=id,body_html,status`);
+    await sleep(520);
+    const len = stripLen(g.json.product?.body_html);
+    verify.desc_sample.push({ sku: s.sku, body_len: len, ok: len > 20 });
+    console.log(`  VERIFY desc ${s.sku}: body_len=${len} ${len > 20 ? 'OK' : 'FAIL'}`);
+  }
+  for (const d of result.drafted) {
+    const g = await rest('GET', `products/${numId(d.shopify_id)}.json?fields=id,status`);
+    await sleep(520);
+    const st = g.json.product?.status;
+    verify.draft_all.push({ sku: d.sku, status: st, ok: st === 'draft' });
+    console.log(`  VERIFY draft ${d.sku}: status=${st} ${st === 'draft' ? 'OK' : 'FAIL'}`);
+  }
+
+  result.restore_map = RESTORE_PATH;
+  result.verify = verify;
+  const outPath = path.join(ROOT, `data/carnegie-backfill-RESULT-${ISO}.json`);
+  fs.writeFileSync(outPath, JSON.stringify(result, null, 2));
+
+  console.log(`\n=== SUMMARY ===`);
+  console.log(`written: ${result.written.length}/45`);
+  console.log(`skipped-by-guard: ${result.skipped_guard.length}`);
+  console.log(`desc errored: ${result.errored.length}`);
+  console.log(`drafted: ${result.drafted.length}/12`);
+  console.log(`draft errored: ${result.draft_errored.length}`);
+  console.log(`not_found: ${result.not_found.length}`);
+  console.log(`RESTORE: ${RESTORE_PATH}`);
+  console.log(`RESULT: ${outPath}`);
+})();

← 0ee7c950 fabricut: commit TK-10815 handle-exists idempotency guard on  ·  back to Dw Validator Debug TK11314  ·  fabricut: add concurrency lockfile to push (Cody hole #1 — a 0356a0e8 →