[object Object]

← back to Wallco Ai

fix(db): psqlExecLocal multi-line SQL — JSON.stringify of newlines was producing literal \n that psql parsed as a meta-command ("invalid command \nINSERT"). Switch to stdin-feed like psqlQuery. Regression from REFACTOR-1a (3b6954e). Unblocks /admin/ghost-review Regenerate-Whole button.

7eb0a508a469e0cd3f324a7cb91586a3721bfc78 · 2026-05-23 23:29:03 -0700 · Steve Abrams

Files touched

Diff

commit 7eb0a508a469e0cd3f324a7cb91586a3721bfc78
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Sat May 23 23:29:03 2026 -0700

    fix(db): psqlExecLocal multi-line SQL — JSON.stringify of newlines was producing literal \n that psql parsed as a meta-command ("invalid command \nINSERT"). Switch to stdin-feed like psqlQuery. Regression from REFACTOR-1a (3b6954e). Unblocks /admin/ghost-review Regenerate-Whole button.
---
 lib/db.js | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/lib/db.js b/lib/db.js
index e9bc336..a781ce4 100644
--- a/lib/db.js
+++ b/lib/db.js
@@ -38,11 +38,13 @@ function pgEsc(v) {
   return "'" + String(v).replace(/'/g, "''") + "'";
 }
 
-// Variant that uses the -c argv form — kept for cases where stdin isn't
-// the right path. SQL goes through JSON.stringify so embedded quotes are
-// shell-safe (the value is double-quoted by the shell, not interpolated).
+// Behavior-identical to psqlQuery (stdin-fed). Previously used `-c ${JSON.stringify(sql)}`
+// argv form, which broke any multi-line SQL: JSON.stringify converts real newlines into the
+// literal two characters `\n`, and psql then interprets `\n` as a backslash meta-command
+// (like `\d`, `\l`) — yielding `invalid command \nINSERT`. Stdin-feed avoids all shell
+// escaping and supports INSERT...RETURNING + multi-statement batches identically.
 function psqlExecLocal(sql) {
-  return execSync(PSQL_CMD + ' -c ' + JSON.stringify(sql), { encoding: 'utf8' }).trim();
+  return execSync(PSQL_CMD, { input: sql, encoding: 'utf8' }).trim();
 }
 
 module.exports = {

← 725d763 ghost-review: Fix / Remove+Fill / Reverse-Regenerate action  ·  back to Wallco Ai  ·  scripts: oneshot trellis-upgrade regen for drunk-zoo-36 #266 9666be2 →