Fix null bu_teams in postgres migration, add retry logic to deploy script
This commit is contained in:
@@ -190,8 +190,8 @@ function getTableMigrations() {
|
||||
{ src: 'is_active', dest: 'is_active', transform: v => v === 1 || v === true },
|
||||
{ src: 'created_at', dest: 'created_at' },
|
||||
{ src: 'last_login', dest: 'last_login' },
|
||||
{ src: 'user_group', dest: 'user_group' },
|
||||
{ src: 'bu_teams', dest: 'bu_teams' },
|
||||
{ src: 'user_group', dest: 'user_group', transform: v => v || 'Read_Only' },
|
||||
{ src: 'bu_teams', dest: 'bu_teams', transform: v => v || '' },
|
||||
],
|
||||
conflict: '(id) DO NOTHING',
|
||||
},
|
||||
@@ -584,7 +584,7 @@ async function migrate() {
|
||||
return migration.columns.map(col => {
|
||||
let value = row[col.src];
|
||||
if (value === undefined) value = null;
|
||||
if (col.transform && value !== null) {
|
||||
if (col.transform) {
|
||||
value = col.transform(value);
|
||||
}
|
||||
return value;
|
||||
|
||||
@@ -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
37
scripts/reset-and-migrate.sh
Executable 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."
|
||||
Reference in New Issue
Block a user