forked from kellymusk/Aframp-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix-migrations.sh
More file actions
executable file
·71 lines (56 loc) · 3.17 KB
/
fix-migrations.sh
File metadata and controls
executable file
·71 lines (56 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
# Fix Migration State Script
# This script fixes the migration state when tables exist but aren't tracked
set -e
echo "🔧 Fixing migration state..."
# Database name
DB_NAME="aframp"
# Check if database exists
if ! psql -lqt | cut -d \| -f 1 | grep -qw "$DB_NAME"; then
echo "❌ Database $DB_NAME does not exist"
exit 1
fi
echo "📊 Current migration state:"
psql -d "$DB_NAME" -c "SELECT version, description, success FROM _sqlx_migrations ORDER BY version;"
echo ""
echo "🔍 Checking which migrations need to be marked as applied..."
# Check if migration 20260123040000 tables exist
if psql -d "$DB_NAME" -tAc "SELECT EXISTS (SELECT FROM pg_tables WHERE schemaname = 'public' AND tablename = 'payment_provider_configs');" | grep -q 't'; then
echo "✅ Migration 20260123040000 tables exist"
# Mark as applied if not already
if ! psql -d "$DB_NAME" -tAc "SELECT EXISTS (SELECT FROM _sqlx_migrations WHERE version = 20260123040000);" | grep -q 't'; then
echo "📝 Marking migration 20260123040000 as applied..."
psql -d "$DB_NAME" -c "INSERT INTO _sqlx_migrations (version, description, success, checksum, execution_time, installed_on) VALUES (20260123040000, 'implement payments schema', true, E'\\x', 0, now());"
else
echo "ℹ️ Migration 20260123040000 already marked as applied"
fi
fi
# Check if migration 20260124000000 tables/indexes exist
if psql -d "$DB_NAME" -tAc "SELECT EXISTS (SELECT FROM pg_indexes WHERE schemaname = 'public' AND indexname = 'idx_transactions_wallet_address');" | grep -q 't'; then
echo "✅ Migration 20260124000000 indexes exist"
# Mark as applied if not already
if ! psql -d "$DB_NAME" -tAc "SELECT EXISTS (SELECT FROM _sqlx_migrations WHERE version = 20260124000000);" | grep -q 't'; then
echo "📝 Marking migration 20260124000000 as applied..."
psql -d "$DB_NAME" -c "INSERT INTO _sqlx_migrations (version, description, success, checksum, execution_time, installed_on) VALUES (20260124000000, 'indexes and constraints', true, E'\\x', 0, now());"
else
echo "ℹ️ Migration 20260124000000 already marked as applied"
fi
fi
# Check if migration 20260125000000 tables exist
if psql -d "$DB_NAME" -tAc "SELECT EXISTS (SELECT FROM pg_tables WHERE schemaname = 'public' AND tablename = 'exchange_rates');" | grep -q 't'; then
echo "✅ Migration 20260125000000 tables exist"
# Mark as applied if not already
if ! psql -d "$DB_NAME" -tAc "SELECT EXISTS (SELECT FROM _sqlx_migrations WHERE version = 20260125000000);" | grep -q 't'; then
echo "📝 Marking migration 20260125000000 as applied..."
psql -d "$DB_NAME" -c "INSERT INTO _sqlx_migrations (version, description, success, checksum, execution_time, installed_on) VALUES (20260125000000, 'add repository tables', true, E'\\x', 0, now());"
else
echo "ℹ️ Migration 20260125000000 already marked as applied"
fi
fi
echo ""
echo "📊 Updated migration state:"
psql -d "$DB_NAME" -c "SELECT version, description, success FROM _sqlx_migrations ORDER BY version;"
echo ""
echo "✅ Migration state fixed!"
echo ""
echo "You can now run ./setup.sh again without errors."