@@ -524,7 +524,7 @@ sync_with_remote() {
524524
525525# Function to check migration status
526526check_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