feat: auto-run migrations via psql init container on scheduler startup
This commit is contained in:
+15
-4
@@ -314,20 +314,31 @@ for db in stonks_beta stonks_paper; do
|
||||
echo " ✓ Database $db exists"
|
||||
done
|
||||
|
||||
# Run migrations on beta and paper databases
|
||||
# Run migrations on all three databases (idempotent — IF NOT EXISTS in DDL)
|
||||
REPO_ROOT="${SCRIPT_DIR}/../stonks-oracle"
|
||||
if [ -d "$REPO_ROOT/infra/migrations" ]; then
|
||||
for db in stonks_beta stonks_paper; do
|
||||
for db in stonks stonks_beta stonks_paper; do
|
||||
echo " Running migrations on $db..."
|
||||
for migration in $(ls "$REPO_ROOT/infra/migrations/"*.sql 2>/dev/null | sort); do
|
||||
kubectl exec -n postgresql-service "$PG_POD" -c postgres -- \
|
||||
psql -U stonks -d "$db" -f - < "$migration" > /dev/null 2>&1 || true
|
||||
kubectl exec -i -n postgresql-service "$PG_POD" -c postgres -- \
|
||||
psql -U postgres -d "$db" < "$migration" > /dev/null 2>&1 || true
|
||||
done
|
||||
echo " ✓ Migrations applied to $db"
|
||||
done
|
||||
else
|
||||
echo " ⚠ Migrations directory not found at $REPO_ROOT/infra/migrations — skipping"
|
||||
fi
|
||||
|
||||
# Seed symbol registry data on all three databases
|
||||
if [ -d "$REPO_ROOT/services/symbol_registry" ]; then
|
||||
for db in stonks stonks_beta stonks_paper; do
|
||||
echo " Seeding $db..."
|
||||
POSTGRES_HOST=postgresql-rw.postgresql-service.svc.cluster.local \
|
||||
POSTGRES_PASSWORD='St0nks0racl3!' POSTGRES_USER=stonks POSTGRES_DB="$db" \
|
||||
python3 -m services.symbol_registry.seed 2>/dev/null || true
|
||||
echo " ✓ Seed data applied to $db"
|
||||
done
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# -------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user