← back to Dw Validator Debug TK11314
TK-10649: targeted 3-row Shopify->PG reconcile for cross-vendor dw_sku collision fix
48cbba4bbadf4ed412ef4486a2149d39754ba32e · 2026-08-18 09:33:36 -0700 · Steve
Files touched
A scripts/reconcile-tk10649.js
Diff
commit 48cbba4bbadf4ed412ef4486a2149d39754ba32e
Author: Steve <steve@designerwallcoverings.com>
Date: Tue Aug 18 09:33:36 2026 -0700
TK-10649: targeted 3-row Shopify->PG reconcile for cross-vendor dw_sku collision fix
---
scripts/reconcile-tk10649.js | 46 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
diff --git a/scripts/reconcile-tk10649.js b/scripts/reconcile-tk10649.js
new file mode 100644
index 00000000..f1cc777c
--- /dev/null
+++ b/scripts/reconcile-tk10649.js
@@ -0,0 +1,46 @@
+const { Pool } = require('pg');
+const https = require('https');
+const pool = new Pool({ connectionString: (process.env.DATABASE_URL || 'postgresql://dw_admin@127.0.0.1:5432/dw_unified') });
+const TOK = process.env.SHOPIFY_ADMIN_TOKEN;
+const IDS = ['7430015418419','7432702033971','7632434397235'];
+
+function gql(query){
+ return new Promise((res,rej)=>{
+ const body=JSON.stringify({query});
+ const req=https.request({host:'designer-laboratory-sandbox.myshopify.com',
+ path:'/admin/api/2024-10/graphql.json',method:'POST',
+ headers:{'X-Shopify-Access-Token':TOK,'Content-Type':'application/json','Content-Length':Buffer.byteLength(body)}},
+ r=>{let d='';r.on('data',c=>d+=c);r.on('end',()=>{try{res(JSON.parse(d))}catch(e){rej(e)}})});
+ req.on('error',rej);req.write(body);req.end();
+ });
+}
+
+(async()=>{
+ for(const id of IDS){
+ const q=`query{ p:product(id:"gid://shopify/Product/${id}"){ id handle title vendor productType status createdAt updatedAt tags
+ variants(first:1){edges{node{ id sku }}}
+ metafields(first:100){edges{node{ namespace key value type }}} } }`;
+ const r=await gql(q);
+ const p=r.data.p;
+ const mf={};
+ for(const e of (p.metafields?.edges||[])){const {namespace,key,value,type}=e.node; (mf[namespace]=mf[namespace]||{})[key]={value,type};}
+ const variant=p.variants?.edges?.[0]?.node;
+ const vsku=variant?.sku||null;
+ const mfrSku=mf?.custom?.mfr_sku?.value||mf?.custom?.manufacturer_sku?.value||mf?.dwc?.manufacturer_sku?.value||mf?.global?.mfr_sku?.value||null;
+ let dwSku = mf?.global?.Handle?.value || null;
+ if(!dwSku && vsku){ dwSku = vsku.replace(/-sample$/i,''); }
+ const vp = dwSku ? ((dwSku.match(/^([A-Z]+-?[A-Za-z]*)-?\d/)||[])[1]||'').replace(/-$/,'')||null : null;
+ await pool.query(`UPDATE shopify_products SET
+ handle=$2,title=$3,vendor=$4,product_type=$5,status=$6,dw_sku=$7,mfr_sku=$8,vendor_prefix=$9,
+ variant_id=$10,variant_sku=$11,tags=$12,updated_at_shopify=$13,synced_at=NOW(),metafields=$14
+ WHERE shopify_id=$1`,
+ [p.id,p.handle,p.title,p.vendor,p.productType,p.status,dwSku,mfrSku,vp,
+ variant?.id||null,vsku,(p.tags||[]).join(',')||null,p.updatedAt,JSON.stringify(mf)]);
+ console.log(`RECONCILED ${id}: status=${p.status} dw_sku=${dwSku} variant_sku=${vsku} mfr=${mfrSku}`);
+ }
+ const coll=await pool.query("SELECT dw_sku,count(DISTINCT vendor) v FROM shopify_products WHERE status='ACTIVE' AND dw_sku IN ('DWK-32014','DWWD-70508') GROUP BY dw_sku");
+ console.log("COLLISIONS_POST:",JSON.stringify(coll.rows));
+ const wp=await pool.query("SELECT count(*) c FROM shopify_products WHERE dw_sku = 'DWWD-70508' AND status='ACTIVE'");
+ console.log("DWWD-70508_ACTIVE_ROWS:",wp.rows[0].c);
+ await pool.end();
+})().catch(e=>{console.error('ERR',e.message);process.exit(1)});
← 7d4c6206 TK-10661: use unless idiom (not ==blank) for offer_variant f
·
back to Dw Validator Debug TK11314
·
TK-10661: normalize Sample match (downcase|strip) per codex c692cedc →