Files
momentum-system/deploy/docker/bootstrap_live_db.sh
T
momentum devandClaude Fable 5 148e300af4 docs: live-money cutover runbook + one-command DB seed script
docs/LIVE-CUTOVER.md: full flip-day procedure — staged pieces, discovered
dependencies (second paper key pair, DB seeding, learned_params copy,
telegram token, ports/dirs), 15-min cutover with the paper stack running
throughout, verification list, rollback. bootstrap_live_db.sh seeds the
live stack's Postgres from the paper nightly dump and truncates the
money-record tables so research history carries over while live P&L
starts at zero.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-22 17:29:06 -05:00

42 lines
2.0 KiB
Bash

#!/bin/bash
# Seed the LIVE stack's fresh Postgres from the paper stack's nightly dump,
# then wipe the money-record tables so live P&L starts at zero while every
# research baseline (minute/daily bars, rvol + regime history, learned
# setups) carries over. Run ON CUBE after the live stack's postgres is up.
#
# ./bootstrap_live_db.sh <backup.sql.gz> <live-postgres-container>
# e.g. ./bootstrap_live_db.sh \
# /mnt/Volume/Storage/Apps/momentum/data/backups/momentum-2026-07-28.sql.gz \
# ix-momentum-live-postgres-1
#
# Idempotent-ish: restoring over a non-empty DB will error on existing objects;
# for a re-run, recreate the live stack's pgdata volume first (it is DISPOSABLE
# until the flip — that's the point of staging).
set -euo pipefail
BACKUP="${1:?usage: bootstrap_live_db.sh <backup.sql.gz> <live-pg-container>}"
CONTAINER="${2:?usage: bootstrap_live_db.sh <backup.sql.gz> <live-pg-container>}"
PSQL=(docker exec -i "$CONTAINER" psql -U momentum -d momentum -v ON_ERROR_STOP=0 -q)
echo "[1/3] restoring $BACKUP into $CONTAINER ..."
gunzip -c "$BACKUP" | "${PSQL[@]}" >/dev/null
echo "[2/3] zeroing money-record tables (all trades/P&L derive from events) ..."
docker exec -i "$CONTAINER" psql -U momentum -d momentum -v ON_ERROR_STOP=1 <<'SQL'
TRUNCATE events, telemetry_events;
-- paper-only artifacts that must not leak into the live stack's views
TRUNCATE simulated_orders, simulated_fills, paper_missed_trades, paper_sessions;
SQL
echo "[3/3] sanity ..."
docker exec -i "$CONTAINER" psql -U momentum -d momentum -t <<'SQL'
SELECT 'minute_bars ' || count(*) || ' (want millions)' FROM minute_bars
UNION ALL SELECT 'daily_bars ' || count(*) FROM daily_bars
UNION ALL SELECT 'setup_events ' || count(*) FROM setup_events
UNION ALL SELECT 'regime_scores ' || count(*) FROM regime_scores
UNION ALL SELECT 'events (MUST be 0) ' || count(*) FROM events;
SQL
echo "done. Copy the paper stack's data/learned_params.json into the live"
echo "stack's data volume, then start the loop."