[object Object]

← back to Designer Wallcoverings

schu-cost-ingest: add --dry (exercise UPDATEs in a txn then ROLLBACK; no write, file stays staged)

828450a00ca811589133c48d65840986c886104e · 2026-06-11 16:49:29 -0700 · SteveStudio2

Files touched

Diff

commit 828450a00ca811589133c48d65840986c886104e
Author: SteveStudio2 <stevestudio2@SteveStacStudio.lan>
Date:   Thu Jun 11 16:49:29 2026 -0700

    schu-cost-ingest: add --dry (exercise UPDATEs in a txn then ROLLBACK; no write, file stays staged)
---
 shopify/scripts/cost-handoff/schu-cost-ingest.js | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/shopify/scripts/cost-handoff/schu-cost-ingest.js b/shopify/scripts/cost-handoff/schu-cost-ingest.js
index f0cdf6b9..9d2f8f1c 100644
--- a/shopify/scripts/cost-handoff/schu-cost-ingest.js
+++ b/shopify/scripts/cost-handoff/schu-cost-ingest.js
@@ -29,6 +29,7 @@ const REJECT = path.join(ROOT, 'rejected');
 
 const DB_URL = process.env.DW_DB_URL || 'postgresql://dw_admin@127.0.0.1:5432/dw_unified';
 const MIN_ROWS = 50, MIN_COST = 1, MAX_COST = 100000, MAX_FRACTION = 0.95;
+const DRY = process.argv.includes('--dry');   // validate + exercise UPDATEs then ROLLBACK; no durable write, file stays staged
 
 function parseCsv(txt) {
   const lines = txt.split(/\r?\n/).filter(Boolean);
@@ -46,7 +47,7 @@ function parseCsv(txt) {
   const rows = parseCsv(fs.readFileSync(fp, 'utf8'));
 
   // ---- validate ----
-  const reject = (why) => { fs.renameSync(fp, path.join(REJECT, file)); console.error(new Date().toISOString(), 'REJECT', file, '-', why); process.exit(2); };
+  const reject = (why) => { if (!DRY) fs.renameSync(fp, path.join(REJECT, file)); console.error(new Date().toISOString(), DRY ? 'DRY-FAIL' : 'REJECT', file, '-', why); process.exit(2); };
   if (rows.length < MIN_ROWS) reject(`too few rows (${rows.length} < ${MIN_ROWS})`);
   const costRows = [];
   for (const r of rows) {
@@ -76,9 +77,14 @@ function parseCsv(txt) {
       } else applied += res.rowCount;
       if (r.disc) { const d = await client.query(`UPDATE schumacher_catalog SET excluded=true, price='DISCONTINUED' WHERE mfr_sku=$1`, [r.sku]); disc += d.rowCount; }
     }
-    await client.query('COMMIT');
-    fs.renameSync(fp, path.join(DONE, file));
-    console.log(new Date().toISOString(), `APPLIED ${file}: cost-updated ${applied}, disco ${disc}, unknown-sku ${unknown}, of ${costRows.length} cost rows`);
+    if (DRY) {
+      await client.query('ROLLBACK');
+      console.log(new Date().toISOString(), `DRY ${file}: WOULD cost-update ${applied}, disco ${disc}, unknown-sku ${unknown}, of ${costRows.length} cost rows (rolled back — no write; file left staged)`);
+    } else {
+      await client.query('COMMIT');
+      fs.renameSync(fp, path.join(DONE, file));
+      console.log(new Date().toISOString(), `APPLIED ${file}: cost-updated ${applied}, disco ${disc}, unknown-sku ${unknown}, of ${costRows.length} cost rows`);
+    }
   } catch (e) {
     await client.query('ROLLBACK').catch(() => {});
     fs.renameSync(fp, path.join(REJECT, file));

← 06a4f86b Part 2: Schumacher cost handoff (DTD-B decoupled) — Mac2 exp  ·  back to Designer Wallcoverings  ·  Read-only overnight Kravet price monitor: diff live vs autho e7a0a4b3 →