[object Object]

← back to Astek Landing

TK-11438: migrate build script postgres connections to unix socket

d25e0098a98949c9681c131c093e8b1697517774 · 2026-09-15 04:08:02 -0700 · steve@designerwallcoverings.com

Files touched

Diff

commit d25e0098a98949c9681c131c093e8b1697517774
Author: steve@designerwallcoverings.com <steve@designerwallcoverings.com>
Date:   Tue Sep 15 04:08:02 2026 -0700

    TK-11438: migrate build script postgres connections to unix socket
---
 scripts/build-products-json.js |  2 +-
 scripts/run-data-refresh.sh    | 10 ++++++++++
 scripts/scrape-astek.js        |  2 +-
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/scripts/build-products-json.js b/scripts/build-products-json.js
index faee80b..41fc01c 100644
--- a/scripts/build-products-json.js
+++ b/scripts/build-products-json.js
@@ -14,7 +14,7 @@ const PW = (() => {
   const m = env.match(/^DW_ADMIN_DB_PASSWORD=(.*)$/m);
   return m ? m[1].replace(/^["']|["']$/g, '').trim() : (process.env.PGPASSWORD || '');
 })();
-const pool = new Pool({ host: '127.0.0.1', port: 5432, user: 'dw_admin', database: 'dw_unified', password: PW });
+const pool = new Pool({ host: process.env.PGHOST || (process.platform === 'darwin' ? '/tmp' : '127.0.0.1'), port: 5432, user: 'dw_admin', database: 'dw_unified', password: PW });
 
 // Map Astek color_ tags -> our canonical color buckets (drives the color filter + color sort).
 const BUCKET = {
diff --git a/scripts/run-data-refresh.sh b/scripts/run-data-refresh.sh
new file mode 100755
index 0000000..bedfcbf
--- /dev/null
+++ b/scripts/run-data-refresh.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+# Dependency-guarded wrapper for the astek-data-refresh cron (TK-11162 fix).
+# The cron plist used to call `node build-products-json.js` directly with no
+# install step, so a missing/wiped node_modules crashed it silently every
+# time with no self-healing. This wraps it: npm ci (deterministic, matches
+# package-lock.json, ~1s when already installed) then the real script.
+set -euo pipefail
+cd "$(dirname "$0")/.."
+/opt/homebrew/bin/npm ci --omit=dev --no-audit --no-fund
+exec /opt/homebrew/bin/node scripts/build-products-json.js
diff --git a/scripts/scrape-astek.js b/scripts/scrape-astek.js
index 63b981f..9285989 100644
--- a/scripts/scrape-astek.js
+++ b/scripts/scrape-astek.js
@@ -26,7 +26,7 @@ const PW = (() => {
 })();
 
 const pool = new Pool({
-  host: '127.0.0.1', port: 5432, user: 'dw_admin', database: 'dw_unified', password: PW,
+  host: process.env.PGHOST || (process.platform === 'darwin' ? '/tmp' : '127.0.0.1'), port: 5432, user: 'dw_admin', database: 'dw_unified', password: PW,
 });
 
 const BANNED = s => (s || '')

← ef312d0 TK-11438: migrate postgres pool to unix socket (darwin fallb  ·  back to Astek Landing  ·  (newest)