← back to Ventura Corridor
scripts/push-news-snapshot.sh
27 lines
#!/usr/bin/env bash
# Nightly news_items sync: mac3 local DB (where the 2am crawl + summarizer write)
# → prod ventura_corridor on Kamatera (which has no crawl and no local Ollama).
# Full-table replace in one transaction; 229-row scale, sub-second.
# Scheduled 06:00 via com.steve.ventura-news-push (after the summarize cycles).
set -euo pipefail
export PATH="/opt/homebrew/bin:/usr/local/bin:$PATH"
export PGHOST=/tmp
LOG="$HOME/.claude/run-notes/ventura-news-push.log"
ts() { date '+%Y-%m-%d %H:%M:%S'; }
LOCAL_N=$(psql -d ventura_corridor -Atc "SELECT count(*) FROM news_items")
if [ -z "$LOCAL_N" ] || [ "$LOCAL_N" -eq 0 ]; then
echo "[$(ts)] ABORT — local news_items empty/unreadable (refusing to wipe prod)" >> "$LOG"; exit 1
fi
pg_dump -d ventura_corridor --no-owner --no-privileges --clean --if-exists -t news_items \
| ssh -o ConnectTimeout=15 my-server 'sudo -u postgres psql -d ventura_corridor -v ON_ERROR_STOP=1 -q
sudo -u postgres psql -d ventura_corridor -q -c "GRANT SELECT ON news_items TO PUBLIC"'
PROD_N=$(ssh -o ConnectTimeout=15 my-server 'sudo -u postgres psql -d ventura_corridor -Atc "SELECT count(*) FROM news_items"')
if [ "$PROD_N" = "$LOCAL_N" ]; then
echo "[$(ts)] OK — pushed $LOCAL_N news_items to prod" >> "$LOG"
else
echo "[$(ts)] MISMATCH — local=$LOCAL_N prod=$PROD_N" >> "$LOG"; exit 1
fi