[object Object]

← back to Wallco Ai

night-builder: take FIRST line of psql RETURNING output, not last whitespace token

1e6e13a4e4f5d6f5bbf7515bbd27ce14d708a977 · 2026-05-20 07:56:37 -0700 · Steve Abrams

Bug from prior patch: psql -At emits RETURNING id on line 1 then INSERT 0 1 tag on line 2. The .split(/\s+/).pop() was grabbing '1' from the tag, breaking every UPDATE. Fix: insertRaw.trim().split('\n')[0].

Files touched

Diff

commit 1e6e13a4e4f5d6f5bbf7515bbd27ce14d708a977
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Wed May 20 07:56:37 2026 -0700

    night-builder: take FIRST line of psql RETURNING output, not last whitespace token
    
    Bug from prior patch: psql -At emits RETURNING id on line 1 then INSERT 0 1 tag on line 2. The .split(/\s+/).pop() was grabbing '1' from the tag, breaking every UPDATE. Fix: insertRaw.trim().split('\n')[0].
---
 scripts/night-builder.js | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/scripts/night-builder.js b/scripts/night-builder.js
index 533e877..5a136a9 100755
--- a/scripts/night-builder.js
+++ b/scripts/night-builder.js
@@ -820,7 +820,11 @@ function generateOne(track, cw) {
                       RETURNING id;`;
                     try {
                       const insertRaw = execSync(`/opt/homebrew/opt/postgresql@14/bin/psql dw_unified -At -c "${insertSql.replace(/"/g, '\\"').replace(/\n/g, ' ')}"`, { encoding: 'utf8' });
-                      const cwId = insertRaw.trim().split(/\s+/).pop();  // psql -At with RETURNING + INSERT 0 1 → take LAST token
+                      // psql -At emits the RETURNING value on line 1, then the
+                      // command tag (e.g. "INSERT 0 1") on line 2. Earlier
+                      // version used `.split(/\s+/).pop()` which grabbed "1"
+                      // from the command tag. Take the FIRST line instead.
+                      const cwId = (insertRaw.trim().split('\n')[0] || '').trim();
                       if (cwId && /^\d+$/.test(cwId)) {
                         try {
                           const updOut = execSync(`/opt/homebrew/opt/postgresql@14/bin/psql dw_unified -At -c "UPDATE spoon_all_designs SET image_url='/designs/img/by-id/${cwId}' WHERE id=${cwId};"`, { encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] }).trim();

← 2ea2f75 night-builder: debug-log url-patch step + ship self-healing  ·  back to Wallco Ai  ·  Login modal (3-role scroll-trigger) + comprehensive PNG sync f9750ac →