[object Object]

← back to Japan Enrich

japan: loader prefers dw_admin (owner) DSN so ALTER TABLE use_for_ai works; prints candidate users + table owner for diagnosis

e82b9031cde98aa5c8fa9e161ad061cd8c147000 · 2026-07-06 17:27:42 -0700 · Steve

Files touched

Diff

commit e82b9031cde98aa5c8fa9e161ad061cd8c147000
Author: Steve <steve@designerwallcoverings.com>
Date:   Mon Jul 6 17:27:42 2026 -0700

    japan: loader prefers dw_admin (owner) DSN so ALTER TABLE use_for_ai works; prints candidate users + table owner for diagnosis
---
 scripts/load-lines-remote.sh | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/scripts/load-lines-remote.sh b/scripts/load-lines-remote.sh
index 0b8f44d..e391e82 100644
--- a/scripts/load-lines-remote.sh
+++ b/scripts/load-lines-remote.sh
@@ -14,13 +14,16 @@ ssh root@45.61.58.125 bash -s <<'REMOTE'
 set -e
 cd /root/Projects/japan-staging-viewer
 npm i pg -s
-DATABASE_URL=""
-for f in $(grep -rl "^DATABASE_URL=.*dw_unified" /root/Projects/*/.env /root/Projects/*/*/.env /root/.env 2>/dev/null); do
-  v=$(grep -m1 "^DATABASE_URL=" "$f" | cut -d= -f2- | tr -d '"')
-  [ -n "$v" ] && { DATABASE_URL="$v"; echo "DSN resolved from $f"; break; }
-done
+# collect every dw_unified DSN across project .env files, then PREFER the dw_admin (owner) one,
+# because ALTER TABLE (use_for_ai column) requires table ownership.
+CANDS=$(grep -rhoE "^DATABASE_URL=[^ ]+" /root/Projects/*/.env /root/Projects/*/*/.env /root/.env 2>/dev/null | cut -d= -f2- | tr -d '"' | grep dw_unified | sort -u)
+echo "candidate DSN users:"; printf '%s\n' "$CANDS" | sed -E 's#://([^:]+):[^@]*@#://\1:***@#'
+DATABASE_URL=$(printf '%s\n' "$CANDS" | grep -m1 dw_admin || true)
+[ -z "$DATABASE_URL" ] && DATABASE_URL=$(printf '%s\n' "$CANDS" | grep -m1 -E "://postgres[:@]" || true)
+[ -z "$DATABASE_URL" ] && DATABASE_URL=$(printf '%s\n' "$CANDS" | head -1)
 [ -z "$DATABASE_URL" ] && DATABASE_URL="postgresql:///dw_unified"
 export DATABASE_URL
-echo "db check:"; psql "$DATABASE_URL" -Atc "select current_database()"
+echo "using user: $(printf '%s' "$DATABASE_URL" | sed -E 's#://([^:]+):.*#\1#')"
+echo "db + owner check:"; psql "$DATABASE_URL" -Atc "select current_user, (select tableowner from pg_tables where tablename='vendor_registry')"
 node db/load-distributor-lines.js
 REMOTE

← 329275d japan: loader wrapper uses quoted heredoc (fixes quote-strip  ·  back to Japan Enrich  ·  japan: rewrite nginx setup — separate conf via scp (server_n 32cb9e4 →