[object Object]

← back to Dw Photo Capture

TK-12162: await + retry the dw_unified new_items_staging write on every item create and report its result (dw_unified field) instead of fire-and-forget

360da780984ee410e1753b557cc68a0c54b232b4 · 2026-09-24 14:42:55 -0700 · Steve Abrams

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

Files touched

Diff

commit 360da780984ee410e1753b557cc68a0c54b232b4
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Thu Sep 24 14:42:55 2026 -0700

    TK-12162: await + retry the dw_unified new_items_staging write on every item create and report its result (dw_unified field) instead of fire-and-forget
    
    Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
---
 server.js | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/server.js b/server.js
index 1290a93..59cdc9d 100644
--- a/server.js
+++ b/server.js
@@ -2775,7 +2775,11 @@ async function createNewItem(p, b64, dryRun) {
     const pidLit = /^\d{1,19}$/.test(pidStr) ? pidStr : 'NULL';
     const stageSQL = `insert into new_items_staging (dw_sku, mfr_sku, vendor, vid, pattern_name, color, price, specs, shopify_product_id, created_via)
       values (${pgLit(dwsku)},${pgLit(mfr)},${pgLit(vreg.vendor)},${pgLit(vreg.vid || '')},${pgLit(name)},${pgLit(color)},${priceLit},${pgLit(specsJson)}::jsonb,${pidLit},'scan') on conflict do nothing`;
-    execFile(PSQL, ['-d', DW_DB, '-c', 'create table if not exists new_items_staging (id bigserial primary key, dw_sku text, mfr_sku text, vendor text, vid text, pattern_name text, color text, price numeric, shopify_product_id bigint, created_via text, created_at timestamptz default now()); alter table new_items_staging add column if not exists specs jsonb; ' + stageSQL], { timeout: 8000 }, () => {});
+    const stageRun = () => new Promise(resolve => execFile(PSQL, ['-v', 'ON_ERROR_STOP=1', '-d', DW_DB, '-c', 'create table if not exists new_items_staging (id bigserial primary key, dw_sku text, mfr_sku text, vendor text, vid text, pattern_name text, color text, price numeric, shopify_product_id bigint, created_via text, created_at timestamptz default now()); alter table new_items_staging add column if not exists specs jsonb; ' + stageSQL], { timeout: 8000 },
+      (err, _out, stderr) => resolve(err ? { committed: false, err: (String(stderr || '').trim() || err.message).slice(0, 200) } : { committed: true, table: 'new_items_staging' })));
+    let dwResult = await stageRun();
+    if (!dwResult.committed) dwResult = await stageRun();
+    if (!dwResult.committed) console.error(`[dw_unified] staging write FAILED for ${dwsku}: ${dwResult.err}`);
     // FileMaker WALLPAPER master — real create (dedupe on Series + Mfr Pattern so a re-run never dupes).
     let fmResult = { committed: false, skipped: 'FileMaker disabled or not configured' };
     if (FM_ENABLED() && FM.fmCreate) {
@@ -2783,7 +2787,7 @@ async function createNewItem(p, b64, dryRun) {
       fmResult = await FM.fmCreate(FM_DB, FM_WP_CREATE_LAYOUT, fm.fieldData, { dryRun: false, dedupe }).catch(e => ({ committed: false, err: e.message }));
     }
     if (pid) CATALOG.push({ product_id: pid, title, status: 'DRAFT', dw_sku: dwsku, mfr, price, image: null, done: false });
-    return { ok: true, product_id: pid, dw_sku: dwsku, title, status: 'draft', filemaker: fmResult, flags, preview };
+    return { ok: true, product_id: pid, dw_sku: dwsku, title, status: 'draft', filemaker: fmResult, dw_unified: dwResult, flags, preview };
   } catch (e) { return { ok: false, err: e.message }; }
 }
 

← 7e1353c TK-12090: verify script resolves dwphoto by name, not stale  ·  back to Dw Photo Capture  ·  TK-12162: auto-save only for registry vendors; case-insensit e7a5066 →