Fix null bu_teams in postgres migration, add retry logic to deploy script

This commit is contained in:
Jordan Ramos
2026-05-07 13:28:19 -06:00
parent 1b8790ff16
commit 3db84a377b
3 changed files with 50 additions and 4 deletions

View File

@@ -88,7 +88,16 @@ echo "✓ Dependencies installed"
echo ""
echo "── Step 5: Running data migration (SQLite → Postgres) ──"
if [ -f backend/cve_database.db ]; then
node backend/scripts/migrate-to-postgres.js
if ! node backend/scripts/migrate-to-postgres.js; then
echo ""
echo "⚠ Migration failed — resetting database and retrying..."
PGPASSWORD=sV4xmC9xAUCFop0ypxMVS056QgPqGrX psql -h localhost -p 5433 -U steam -d cve_dashboard -c "
DROP SCHEMA public CASCADE;
CREATE SCHEMA public;
" >/dev/null 2>&1
echo "✓ Schema reset"
node backend/scripts/migrate-to-postgres.js
fi
else
echo "⚠ No SQLite database found — skipping migration (fresh install)"
fi

37
scripts/reset-and-migrate.sh Executable file
View File

@@ -0,0 +1,37 @@
#!/bin/bash
# =============================================================================
# reset-and-migrate.sh — Drop all Postgres data and re-run the migration
# =============================================================================
# Use this when the migration partially failed and you need a clean slate.
# Safe to run multiple times — it always starts fresh.
#
# What this does:
# 1. Drops and recreates the public schema (wipes all tables)
# 2. Runs the migration script (recreates schema + copies SQLite data)
#
# Usage:
# chmod +x scripts/reset-and-migrate.sh
# ./scripts/reset-and-migrate.sh
# =============================================================================
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
cd "$PROJECT_DIR"
echo ""
echo "── Resetting Postgres database ──"
PGPASSWORD=sV4xmC9xAUCFop0ypxMVS056QgPqGrX psql -h localhost -p 5433 -U steam -d cve_dashboard -c "
DROP SCHEMA public CASCADE;
CREATE SCHEMA public;
"
echo "✓ Schema dropped and recreated"
echo ""
echo "── Running migration ──"
node backend/scripts/migrate-to-postgres.js
echo ""
echo "✓ Done. Postgres is ready."