feat: stage-isolated infrastructure — separate Postgres DBs, Redis DBs, and MinIO bucket prefixes per stage

This commit is contained in:
Celes Renata
2026-04-19 22:20:03 +00:00
parent 2621b3c5c5
commit 5c63264393
10 changed files with 96 additions and 30 deletions
+31
View File
@@ -299,6 +299,37 @@ for ns in stonks-beta stonks-paper stonks-oracle; do
done
echo ""
# -------------------------------------------------------
# 6d. Create isolated databases for beta and paper stages
# -------------------------------------------------------
echo "--- Step 6d: Creating stage-isolated databases ---"
PG_POD=$(kubectl get pods -n postgresql-service -l cnpg.io/cluster=postgresql,role=primary -o jsonpath='{.items[0].metadata.name}' 2>/dev/null || echo "postgresql-1")
# Create databases (idempotent)
for db in stonks_beta stonks_paper; do
kubectl exec -n postgresql-service "$PG_POD" -c postgres -- \
psql -U postgres -tc "SELECT 1 FROM pg_database WHERE datname='$db'" | grep -q 1 || \
kubectl exec -n postgresql-service "$PG_POD" -c postgres -- \
psql -U postgres -c "CREATE DATABASE $db OWNER stonks;"
echo " ✓ Database $db exists"
done
# Run migrations on beta and paper databases
REPO_ROOT="${SCRIPT_DIR}/../stonks-oracle"
if [ -d "$REPO_ROOT/infra/migrations" ]; then
for db in 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
done
echo " ✓ Migrations applied to $db"
done
else
echo " ⚠ Migrations directory not found at $REPO_ROOT/infra/migrations — skipping"
fi
echo ""
# -------------------------------------------------------
# 7. Install Kargo via Helm
# -------------------------------------------------------