-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest_db_migration.sh
More file actions
executable file
·41 lines (31 loc) · 1.14 KB
/
Copy pathtest_db_migration.sh
File metadata and controls
executable file
·41 lines (31 loc) · 1.14 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
#!/bin/bash
set -euo pipefail
cd "$(dirname "$0")/.."
# Test database config (hardcoded - no .env needed)
export DB_HOST=localhost
export DB_PORT=5433
export DB_USER=test_user
export DB_NAME=test_db
export PGPASSWORD=test_password
# Build connection URL
export DATABASE_URL="postgresql://$DB_USER:$PGPASSWORD@$DB_HOST:$DB_PORT/$DB_NAME"
echo "Migrating test database: $DATABASE_URL"
# Check if psql is available
if ! command -v psql &> /dev/null; then
echo "Error: psql not found. Use docker exec instead."
echo "Running: docker exec scripts-postgres-test-1 psql ..."
# Use docker exec if psql not installed
docker exec -i scripts-postgres-test-1 psql -U $DB_USER -d $DB_NAME <<EOF
DROP SCHEMA public CASCADE;
CREATE SCHEMA public;
EOF
# Apply migration via docker
docker exec -i scripts-postgres-test-1 psql -U $DB_USER -d $DB_NAME < backend/supabase/migration.sql
else
# Using local psql
# Clear existing schema
psql "$DATABASE_URL" -c "DROP SCHEMA public CASCADE; CREATE SCHEMA public;"
# Apply migration
psql "$DATABASE_URL" -f backend/supabase/migration.sql
fi
echo "✅ Test database migration complete"