Drop install.sh; pf.sh db-setup builds the calendar too

install.sh duplicated pf.sh config, db-setup and add-user, defaulted to one
person's DB host and account, never built the UI, and pointed at
`npm run dev` as the way to start. Neither script ran gen_dim_period.sql,
so a fresh install had no pf.dim_period at all. db-setup now runs it
between the schema and the auth tables; it only inserts missing months,
so re-running leaves an existing calendar untouched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Paul Trowbridge 2026-09-28 23:20:54 -04:00
parent 1b1452b625
commit f8b935d03f
3 changed files with 9 additions and 88 deletions

View File

@ -23,8 +23,9 @@ Data transport architecture options: `docs/pf_perspective_options.md`
```
server.js Express entry point; pg pool; session; type parsers for bigint/numeric
pf.sh Account and territory admin (add-user, passwd, set-territory, …)
install.sh Fresh install
pf.sh Install, deploy and admin: config, db-setup, deploy, install-service,
add-user, passwd, set-territory, … (fresh install: config → db-setup
→ add-user → deploy → install-service)
routes/
auth.js POST /api/login, /api/logout, GET /api/me; login throttle
tables.js GET /api/tables, /api/tables/:schema/:tname/preview

View File

@ -1,82 +0,0 @@
#!/usr/bin/env bash
set -e
echo ""
echo "========================================"
echo " Pivot Forecast — Install"
echo "========================================"
echo ""
# ── DB connection ─────────────────────────────────────────────
read -p "DB host [192.168.1.110]: " DB_HOST
DB_HOST=${DB_HOST:-192.168.1.110}
read -p "DB port [5432]: " DB_PORT
DB_PORT=${DB_PORT:-5432}
read -p "DB name [ubm]: " DB_NAME
DB_NAME=${DB_NAME:-ubm}
read -p "DB user [ptrowbridge]: " DB_USER
DB_USER=${DB_USER:-ptrowbridge}
read -s -p "DB password: " DB_PASSWORD
echo ""
read -p "App port [3030]: " PORT
PORT=${PORT:-3030}
# Session cookies are signed with this; the server refuses to start without it.
SESSION_SECRET=$(node -e 'console.log(require("crypto").randomBytes(32).toString("hex"))')
read -p "Send session cookie over HTTPS only? [Y/n]: " SECURE_ANS
case "${SECURE_ANS:-y}" in [Nn]*) COOKIE_SECURE=false ;; *) COOKIE_SECURE=true ;; esac
# ── Write .env ────────────────────────────────────────────────
cat > .env <<EOF
DB_HOST=${DB_HOST}
DB_PORT=${DB_PORT}
DB_NAME=${DB_NAME}
DB_USER=${DB_USER}
DB_PASSWORD=${DB_PASSWORD}
PORT=${PORT}
SESSION_SECRET=${SESSION_SECRET}
COOKIE_SECURE=${COOKIE_SECURE}
EOF
chmod 600 .env
echo "✓ .env written"
# ── npm install ───────────────────────────────────────────────
echo ""
echo "Installing node dependencies..."
npm install --silent
echo "✓ dependencies installed"
# ── schema install ────────────────────────────────────────────
echo ""
echo "Installing pf schema into ${DB_NAME}..."
PGPASSWORD=${DB_PASSWORD} psql \
-h "${DB_HOST}" \
-p "${DB_PORT}" \
-U "${DB_USER}" \
-d "${DB_NAME}" \
-v ON_ERROR_STOP=1 \
-f setup_sql/01_schema.sql \
-f setup_sql/02_auth.sql
echo "✓ schema installed"
# ── first account ─────────────────────────────────────────────
echo ""
echo "The app is behind a login. Create the first account now:"
./pf.sh add-user
# ── done ─────────────────────────────────────────────────────
echo ""
echo "========================================"
echo " Install complete"
echo " Start with: npm run dev
More accounts: ./pf.sh add-user"
echo " Open: http://$(hostname -I | awk '{print $1}'):${PORT}"
echo "========================================"
echo ""

10
pf.sh
View File

@ -194,13 +194,15 @@ cmd_db_setup() {
command -v psql &>/dev/null || die "psql not found — install postgresql-client"
echo
bold "DB Setup — will run: setup_sql/01_schema.sql, setup_sql/02_auth.sql"
warn "This creates the pf schema, tables, and the account/session tables."
warn "Safe to re-run (CREATE IF NOT EXISTS)."
bold "DB Setup — will run: setup_sql/01_schema.sql, setup_sql/gen_dim_period.sql, setup_sql/02_auth.sql"
warn "This creates the pf schema and tables, the pf.dim_period calendar, and the account/session tables."
warn "The calendar's fiscal year starts in the month set in gen_dim_period.sql (fiscal_start_month) — check it before a first install."
warn "Safe to re-run (CREATE IF NOT EXISTS; existing calendar rows are never overwritten)."
read -rp " Continue? [y/N] " confirm
[[ "$confirm" =~ ^[Yy]$ ]] || { echo "Aborted."; return; }
run_psql -v ON_ERROR_STOP=1 -f "${APP_DIR}/setup_sql/01_schema.sql"
run_psql -v ON_ERROR_STOP=1 -f "${APP_DIR}/setup_sql/gen_dim_period.sql"
run_psql -v ON_ERROR_STOP=1 -f "${APP_DIR}/setup_sql/02_auth.sql"
success "Schema applied."
@ -574,7 +576,7 @@ interactive_menu() {
echo " 4) restart restart server"
echo " 5) status service + DB + git info"
echo " 6) logs tail journald logs"
echo " 7) db-setup apply setup_sql/01_schema.sql"
echo " 7) db-setup apply the pf schema, calendar and auth tables"
echo " 8) config set DB connection + app PORT"
echo " 9) install-service create systemd unit file"
echo " 10) uninstall-service remove systemd unit file"