← back to Designerwallcoverings
TK-10484: reversible cost fix for 4 NU rows (25 -> Yorkwall 30), Steve-approved, not fired
1fc203fbea6549a1689d184411b3639ba96dc288 · 2026-09-24 13:10:34 -0700 · Steve Abrams
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Files touched
A scripts/tk10484-nu-cost-fix.mjs
Diff
commit 1fc203fbea6549a1689d184411b3639ba96dc288
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Thu Sep 24 13:10:34 2026 -0700
TK-10484: reversible cost fix for 4 NU rows (25 -> Yorkwall 30), Steve-approved, not fired
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
---
scripts/tk10484-nu-cost-fix.mjs | 49 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
diff --git a/scripts/tk10484-nu-cost-fix.mjs b/scripts/tk10484-nu-cost-fix.mjs
new file mode 100644
index 0000000..99b0567
--- /dev/null
+++ b/scripts/tk10484-nu-cost-fix.mjs
@@ -0,0 +1,49 @@
+#!/usr/bin/env node
+// TK-10484 — set cost := yorkwall_cost on the 4 NU rows where our cost (25) is below Yorkwall NET (30).
+// Steve approved 2026-09-24. Scope is only rows where yorkwall_cost > 0 AND cost <> yorkwall_cost.
+// Old values are saved to data/ before the write; --rollback restores them.
+//
+// node scripts/tk10484-nu-cost-fix.mjs # dry-run
+// node scripts/tk10484-nu-cost-fix.mjs --apply
+// node scripts/tk10484-nu-cost-fix.mjs --rollback # restore from the newest restore file
+
+import { execFileSync } from 'node:child_process';
+import { readFileSync, writeFileSync, readdirSync } from 'node:fs';
+import { fileURLToPath } from 'node:url';
+import { dirname, join } from 'node:path';
+
+const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
+const DATA = join(ROOT, 'data');
+const PG = ['-h', '/tmp', '-d', 'dw_unified', '-v', 'ON_ERROR_STOP=1'];
+const mode = process.argv.includes('--apply') ? 'apply'
+ : process.argv.includes('--rollback') ? 'rollback' : 'dry';
+const q = (sql) => execFileSync('psql', [...PG, '-tA', '-F', '|', '-c', sql], { encoding: 'utf8' }).trim();
+const run = (sql) => execFileSync('psql', PG, { input: sql, encoding: 'utf8' });
+
+console.log(`TK-10484 nu-cost-fix — mode: ${mode}`);
+
+if (mode === 'rollback') {
+ const f = readdirSync(DATA).filter((n) => n.startsWith('tk10484-nu-cost-fix-restore-')).sort().pop();
+ if (!f) { console.log('No restore file found.'); process.exit(1); }
+ const rows = JSON.parse(readFileSync(join(DATA, f), 'utf8')).rows;
+ run('BEGIN;\n' + rows.map((r) => `UPDATE jeffrey_stevens_catalog SET cost=${Number(r.cost)} WHERE sku='${r.sku}';`).join('\n') + '\nCOMMIT;');
+ console.log(`ROLLBACK done — restored ${rows.length} rows from ${f}.`);
+ process.exit(0);
+}
+
+const rows = q(`SELECT sku, recovered_mfr_code, cost, yorkwall_cost FROM jeffrey_stevens_catalog
+ WHERE yorkwall_cost > 0 AND cost IS DISTINCT FROM yorkwall_cost ORDER BY recovered_mfr_code;`)
+ .split('\n').filter(Boolean).map((l) => { const [sku, code, cost, yw] = l.split('|'); return { sku, code, cost, yw }; });
+rows.forEach((r) => console.log(` ${r.code} ${r.sku} cost ${r.cost} -> ${r.yw}`));
+if (rows.length !== 4) { console.log(`Expected 4 rows, found ${rows.length} — stopping.`); process.exit(3); }
+
+if (mode === 'dry') { console.log('\nDRY-RUN. Apply: node scripts/tk10484-nu-cost-fix.mjs --apply'); process.exit(0); }
+
+const ts = new Date().toISOString().replace(/[:.]/g, '-');
+const restore = join(DATA, `tk10484-nu-cost-fix-restore-${ts}.json`);
+writeFileSync(restore, JSON.stringify({ ts, rows: rows.map((r) => ({ sku: r.sku, cost: r.cost })) }, null, 2));
+run('BEGIN;\n' + rows.map((r) => `UPDATE jeffrey_stevens_catalog SET cost=yorkwall_cost WHERE sku='${r.sku}';`).join('\n') + '\nCOMMIT;');
+const left = q(`SELECT count(*) FROM jeffrey_stevens_catalog WHERE yorkwall_cost > 0 AND cost IS DISTINCT FROM yorkwall_cost;`);
+console.log(`APPLIED — ${rows.length} rows set to Yorkwall cost; mismatches remaining: ${left}. Restore file: ${restore}`);
+if (left !== '0') process.exit(3);
+console.log('Undo: node scripts/tk10484-nu-cost-fix.mjs --rollback');
← 6d77d92 TK-10484: archived 33 yorkwall no-price NU rows; fix count p
·
back to Designerwallcoverings
·
TK-10484: restore file for NU cost fix (4 rows 25->30) 8e87211 →