Skip to content

Commit 0ea4e55

Browse files
committed
feat: enhance migration status reporting with detailed file listing and table verification
1 parent 2c30f77 commit 0ea4e55

File tree

2 files changed

+53
-37
lines changed

2 files changed

+53
-37
lines changed

bin/deploy-with-migrations.sh

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,31 @@ if [ $? -ne 0 ]; then
6969
fi
7070

7171
# Check migration status before applying
72-
echo -e "${YELLOW}Checking migration status on remote server...${NC}"
72+
echo -e "${YELLOW}=== MIGRATION STATUS BEFORE APPLYING ===${NC}"
73+
echo -e "${YELLOW}Checking which migration files exist and their current status...${NC}"
74+
75+
# List all migration files and their status
76+
ssh $SSH_OPTS $REMOTE_USER@$REMOTE_HOST "cd $REMOTE_DIR && echo -e '${YELLOW}Migration files found:${NC}' && ls -la supabase/migrations/*.sql 2>/dev/null | while read -r line; do echo -e '${GREEN}📄 \$line${NC}'; done || echo -e '${RED}No migration files found${NC}'"
77+
78+
# Check detailed migration status
7379
ssh $SSH_OPTS $REMOTE_USER@$REMOTE_HOST "cd $REMOTE_DIR && ./bin/supabase-db.sh status"
7480

81+
echo -e "${YELLOW}=== APPLYING MIGRATIONS ===${NC}"
7582
# Run the Supabase migrations
7683
echo -e "${YELLOW}Running Supabase migrations on remote server...${NC}"
7784
ssh $SSH_OPTS $REMOTE_USER@$REMOTE_HOST "cd $REMOTE_DIR && ./bin/supabase-db.sh migrate"
7885

86+
echo -e "${YELLOW}=== MIGRATION STATUS AFTER APPLYING ===${NC}"
87+
echo -e "${YELLOW}Verifying migration status after application...${NC}"
88+
89+
# Check migration status after applying
90+
ssh $SSH_OPTS $REMOTE_USER@$REMOTE_HOST "cd $REMOTE_DIR && ./bin/supabase-db.sh status"
91+
92+
# Also check for specific tables that should exist
93+
echo -e "${YELLOW}=== VERIFYING SPECIFIC TABLES ===${NC}"
94+
echo -e "${YELLOW}Checking if campaigns table exists in database...${NC}"
95+
ssh $SSH_OPTS $REMOTE_USER@$REMOTE_HOST "cd $REMOTE_DIR && echo 'Checking for campaigns table...' && supabase db pull --schema public 2>/dev/null | grep -i 'campaigns' || echo -e '${RED}❌ campaigns table not found${NC}'"
96+
7997
if [ $? -eq 0 ]; then
8098
echo -e "${GREEN}Migrations successful!${NC}"
8199
else

bin/supabase-db.sh

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ sync_with_remote() {
524524

525525
# Function to check migration status
526526
check_migration_status() {
527-
echo -e "${YELLOW}Checking migration status...${NC}"
527+
echo -e "${YELLOW}=== MIGRATION STATUS CHECK ===${NC}"
528528

529529
# Check if Supabase CLI is installed
530530
if ! command -v supabase &> /dev/null; then
@@ -550,32 +550,32 @@ check_migration_status() {
550550
export SUPABASE_DB_PASSWORD="$SUPABASE_DB_PASSWORD"
551551
export SUPABASE_ACCESS_TOKEN="$SUPABASE_ACCESS_TOKEN"
552552

553-
echo -e "${YELLOW}=== Migration Status Report ===${NC}"
554-
echo ""
555-
556-
# List all local migration files
553+
# Count and list migration files
557554
if [ -d "supabase/migrations" ]; then
558-
echo -e "${YELLOW}Local migration files:${NC}"
555+
MIGRATION_COUNT=$(ls supabase/migrations/*.sql 2>/dev/null | wc -l)
556+
echo -e "${GREEN}Found $MIGRATION_COUNT migration files:${NC}"
557+
558+
# List each migration file with a brief description
559559
for migration_file in supabase/migrations/*.sql; do
560560
if [ -f "$migration_file" ]; then
561561
filename=$(basename "$migration_file")
562562
echo -e "${GREEN}📄 $filename${NC}"
563563

564-
# Extract the first few lines to show what the migration does
565-
echo -e "${YELLOW} Content preview:${NC}"
566-
head -10 "$migration_file" | grep -E "^--" | head -3 | sed 's/^/ /'
567-
echo ""
564+
# Show first comment line that describes what the migration does
565+
first_comment=$(head -5 "$migration_file" | grep -E "^--" | head -1 | sed 's/^-- *//')
566+
if [ -n "$first_comment" ]; then
567+
echo -e "${YELLOW}$first_comment${NC}"
568+
fi
568569
fi
569570
done
571+
echo ""
570572
else
571-
echo -e "${RED}No migrations directory found.${NC}"
573+
echo -e "${RED}No migrations directory found.${NC}"
572574
return 1
573575
fi
574576

575-
echo -e "${YELLOW}=== Checking Applied Migrations ===${NC}"
576-
577-
# Get migration history from remote database
578-
echo -e "${YELLOW}Fetching migration history from remote database...${NC}"
577+
# Get migration status from database
578+
echo -e "${YELLOW}Checking which migrations have been applied to database...${NC}"
579579

580580
# Create a temporary file to capture the migration list output
581581
MIGRATION_LIST_OUTPUT=$(mktemp)
@@ -584,35 +584,43 @@ check_migration_status() {
584584
supabase migration list 2>&1 | tee "$MIGRATION_LIST_OUTPUT"
585585
LIST_EXIT_CODE=$?
586586

587+
echo ""
588+
echo -e "${YELLOW}=== MIGRATION APPLICATION STATUS ===${NC}"
589+
587590
if [ $LIST_EXIT_CODE -eq 0 ]; then
588-
echo -e "${GREEN}Migration list retrieved successfully!${NC}"
589-
echo ""
590-
echo -e "${YELLOW}=== Migration Status Summary ===${NC}"
591-
592591
# Parse the output and show status for each local migration
592+
APPLIED_COUNT=0
593+
NOT_APPLIED_COUNT=0
594+
593595
for migration_file in supabase/migrations/*.sql; do
594596
if [ -f "$migration_file" ]; then
595597
filename=$(basename "$migration_file" .sql)
596598

597599
# Check if this migration appears in the applied list
598600
if grep -q "$filename" "$MIGRATION_LIST_OUTPUT"; then
599601
echo -e "${GREEN}$filename - APPLIED${NC}"
602+
APPLIED_COUNT=$((APPLIED_COUNT + 1))
600603
else
601604
echo -e "${RED}$filename - NOT APPLIED${NC}"
605+
NOT_APPLIED_COUNT=$((NOT_APPLIED_COUNT + 1))
602606
fi
603607
fi
604608
done
609+
610+
echo ""
611+
echo -e "${YELLOW}Summary: ${GREEN}$APPLIED_COUNT applied${NC}, ${RED}$NOT_APPLIED_COUNT not applied${NC}"
612+
613+
if [ $NOT_APPLIED_COUNT -gt 0 ]; then
614+
echo -e "${YELLOW}⚠️ Some migrations have not been applied to the database!${NC}"
615+
fi
605616
else
606-
echo -e "${YELLOW}Could not retrieve migration list. Trying alternative method...${NC}"
617+
echo -e "${RED}❌ Could not retrieve migration status from database${NC}"
618+
echo -e "${YELLOW}This might indicate a connection or authentication issue${NC}"
607619

608-
# Alternative: Check each migration individually
609-
echo -e "${YELLOW}Checking migrations individually...${NC}"
620+
# Still list the files but mark status as unknown
610621
for migration_file in supabase/migrations/*.sql; do
611622
if [ -f "$migration_file" ]; then
612623
filename=$(basename "$migration_file" .sql)
613-
echo -e "${YELLOW}🔍 Checking $filename...${NC}"
614-
615-
# For now, just mark as unknown since we can't check individual status easily
616624
echo -e "${YELLOW}$filename - STATUS UNKNOWN${NC}"
617625
fi
618626
done
@@ -621,17 +629,7 @@ check_migration_status() {
621629
# Clean up temporary file
622630
rm -f "$MIGRATION_LIST_OUTPUT"
623631

624-
echo ""
625-
echo -e "${YELLOW}=== Troubleshooting Tips ===${NC}"
626-
echo -e "${YELLOW}If migrations show as NOT APPLIED:${NC}"
627-
echo -e "${YELLOW}1. Run: ./bin/supabase-db.sh migrate${NC}"
628-
echo -e "${YELLOW}2. Check your database connection and permissions${NC}"
629-
echo -e "${YELLOW}3. Verify SUPABASE_DB_PASSWORD and SUPABASE_ACCESS_TOKEN${NC}"
630-
echo ""
631-
echo -e "${YELLOW}If you're missing the campaigns table specifically:${NC}"
632-
echo -e "${YELLOW}1. Check if there's a migration that creates the campaigns table${NC}"
633-
echo -e "${YELLOW}2. Look for any migration that might have failed to apply${NC}"
634-
echo -e "${YELLOW}3. Consider creating a new migration for the campaigns table if missing${NC}"
632+
echo -e "${YELLOW}=== END MIGRATION STATUS CHECK ===${NC}"
635633
}
636634

637635
# Function to check for updates and upgrade if needed

0 commit comments

Comments
 (0)