#!/bin/bash # Zero-rebuild-downtime update of the control plane on the node (run ON M3U96b from ~/apps/autoscholar): # git pull → install → build packages/services → migrate → build web into .next-new → swap → pm2 restart (≈5 s gap) set -euo pipefail export CI=true PATH=/opt/homebrew/opt/postgresql@17/bin:/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin cd "$(dirname "$0")/.." git pull -q origin main && git log --oneline -1 pnpm install --frozen-lockfile 2>&1 | tail -1 pnpm -r --filter "./packages/**" --filter "./services/**" build 2>&1 | grep -E "error|Failed" && exit 1 || true DBURL="${DATABASE_URL:-postgresql://autoscholar:$(cat ~/apps/autoscholar-data/.pgpass-autoscholar)@127.0.0.1:5432/autoscholar}" (cd packages/db && DATABASE_URL="$DBURL" pnpm migrate 2>&1 | tail -1) (cd apps/web && rm -rf .next-new && NEXT_DIST_DIR=.next-new APP_BASE_URL=https://autoscholar.ai pnpm build 2>&1 | grep -E "error|✓ Compiled|Failed") (cd apps/web && rm -rf .next-old && { [ -d .next ] && mv .next .next-old || true; } && mv .next-new .next && rm -rf .next-old) pm2 restart autoscholar autoscholar-scheduler >/dev/null sleep 4; curl -s -o /dev/null -w "local health %{http_code}\n" http://127.0.0.1:8470/api/public/topics