[object Object]

← back to Designerwallcoverings

TK-10484: fix yorkwall cost applier — key on recovered_mfr_code, no-price stays NULL, DB-verified count

df48217a0ca8674f01e5c7274ac7eb6fb0e22002 · 2026-09-24 13:05:42 -0700 · Steve Abrams

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

Files touched

Diff

commit df48217a0ca8674f01e5c7274ac7eb6fb0e22002
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Thu Sep 24 13:05:42 2026 -0700

    TK-10484: fix yorkwall cost applier — key on recovered_mfr_code, no-price stays NULL, DB-verified count
    
    Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
---
 scripts/tk10484-yorkwall-cost-apply.mjs | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/scripts/tk10484-yorkwall-cost-apply.mjs b/scripts/tk10484-yorkwall-cost-apply.mjs
index c417fc4..071b9d7 100644
--- a/scripts/tk10484-yorkwall-cost-apply.mjs
+++ b/scripts/tk10484-yorkwall-cost-apply.mjs
@@ -49,14 +49,17 @@ if (mode === 'rollback') {
 
 // apply
 psql(`ALTER TABLE jeffrey_stevens_catalog ADD COLUMN IF NOT EXISTS yorkwall_cost numeric(10,2);`);
-let sql = `BEGIN;`;
-for (const r of results.results) {
-  const sku = `DWAA-${r.orig}-Roll`; // e.g., DWAA-NU1930-Roll
-  const val = r.net && r.net > 0 ? r.net : 0;
-  sql += `UPDATE jeffrey_stevens_catalog SET yorkwall_cost=${val} WHERE sku='${sku.replace(/'/g, "''")}';\n`;
+// Key = recovered_mfr_code (e.g. NU1930) — verified 47/47 one-row matches. No-price codes stay NULL:
+// an unmeasured cost must never read as $0.
+const priced = results.results.filter((r) => r.net && r.net > 0 && /^NU[A-Z]?\d+$/.test(r.orig));
+let sql = `BEGIN;\n`;
+for (const r of priced) {
+  sql += `UPDATE jeffrey_stevens_catalog SET yorkwall_cost=${Number(r.net)} WHERE recovered_mfr_code='${r.orig}';\n`;
 }
 sql += `COMMIT;`;
-psql(sql);
-const n = psql(`SELECT count(*) FROM jeffrey_stevens_catalog WHERE vendor_code='nuwallpaper' AND yorkwall_cost > 0;`).trim().match(/^\s*(\d+)/)?.[1] || '0';
-console.log(`APPLIED — yorkwall_cost column added, ${n} NU rows priced (${results.found} expected), ${results.noprice} marked as no-price.`);
+execFileSync('psql', [...PG, '-v', 'ON_ERROR_STOP=1'], { input: sql, encoding: 'utf8' });
+const n = Number(execFileSync('psql', [...PG, '-tA', '-c',
+  `SELECT count(*) FROM jeffrey_stevens_catalog WHERE yorkwall_cost > 0;`], { encoding: 'utf8' }).trim());
+console.log(`APPLIED — ${n} rows now carry yorkwall_cost (expected ${priced.length}); ${results.noprice} no-price codes left NULL.`);
+if (n !== priced.length) { console.log('MISMATCH — investigate before using these costs.'); process.exit(3); }
 console.log('Undo: node scripts/tk10484-yorkwall-cost-apply.mjs --rollback');

← 78f2d63 TK-10484: reversible yorkwall cost applier for 47 NU codes (  ·  back to Designerwallcoverings  ·  TK-10484: reversible archiver for 33 yorkwall no-price NU co 41b4348 →