@@ -69,7 +69,36 @@ MIGRATIONS_DIR="${SCRIPT_DIR}/../supabase/migrations"
6969
7070print_header " pgflow Temporary Migration Regenerator" 
7171
72- #  Step 1: Find the newest migration containing "pgflow_temp_"
72+ #  Step 1: Check if schemas are already synced
73+ print_info " Checking if schemas are in sync..." 
74+ 
75+ #  Run atlas-verify-schemas-synced and capture its exit code
76+ set  +e  #  Temporarily disable exit on error
77+ " ${SCRIPT_DIR} /atlas-verify-schemas-synced"   >  /dev/null 2>&1 
78+ SYNC_STATUS=$? 
79+ set  -e  #  Re-enable exit on error
80+ 
81+ if  [ $SYNC_STATUS  -eq  0 ];  then 
82+     print_success " Schemas are already in sync!" 
83+     echo 
84+     print_info " No migration regeneration needed. The schemas in the database" 
85+     print_info " already match what's defined in the schema files." 
86+     echo 
87+     print_info " This typically means:" 
88+     print_info "   • The temporary migration was already applied successfully" 
89+     print_info "   • All schema changes are captured in existing migrations" 
90+     print_info "   • No new changes have been made to schema files" 
91+     echo 
92+     print_info " If you've made changes to schema files, they should appear" 
93+     print_info " after running 'pnpm nx verify-schemas-synced core'." 
94+     echo 
95+     exit  0
96+ fi 
97+ 
98+ print_warning " Schemas are not in sync, proceeding with regeneration..." 
99+ echo 
100+ 
101+ #  Step 2: Find the newest migration containing "pgflow_temp_"
73102print_info " Searching for newest temporary migration..." 
74103
75104#  Find all migrations with pgflow_temp_ and get the newest one
@@ -99,10 +128,11 @@ print_info "Extracted migration name: ${BOLD}${TEMP_NAME}${NC}"
99128#  Show what will be done
100129echo 
101130print_header " This script will perform the following actions:" 
102- echo  -e "   1. ${RED} Remove${NC}  migration: ${MIGRATION_BASENAME} " 
103- echo  -e "   2. ${BLUE} Rehash${NC}  migrations using atlas-migrate-hash" 
104- echo  -e "   3. ${GREEN} Generate${NC}  new migration: ${TEMP_NAME} " 
105- echo  -e "   4. ${CYAN} Verify${NC}  the migration by running:" 
131+ echo  -e "   1. ${YELLOW} Check${NC}  if schemas are already in sync" 
132+ echo  -e "   2. ${RED} Remove${NC}  migration: ${MIGRATION_BASENAME} " 
133+ echo  -e "   3. ${BLUE} Rehash${NC}  migrations using atlas-migrate-hash" 
134+ echo  -e "   4. ${GREEN} Generate${NC}  new migration: ${TEMP_NAME} " 
135+ echo  -e "   5. ${CYAN} Verify${NC}  the migration by running:" 
106136echo  -e "      • pnpm nx verify-migrations core" 
107137echo  -e "      • pnpm nx gen-types core" 
108138echo  -e "      • pnpm nx test:pgtap core" 
@@ -117,27 +147,27 @@ else
117147    print_info " Skipping confirmation (--yes flag provided)" 
118148fi 
119149
120- #  Step 2 : Remove the migration
121- print_header " Step 1 : Removing temporary migration" 
150+ #  Step 3 : Remove the migration
151+ print_header " Step 2 : Removing temporary migration" 
122152print_info " Removing: ${MIGRATION_BASENAME} " 
123153rm " $NEWEST_MIGRATION " 
124154print_success " Migration removed" 
125155
126- #  Step 3 : Rehash migrations
127- print_header " Step 2 : Rehashing migrations" 
156+ #  Step 4 : Rehash migrations
157+ print_header " Step 3 : Rehashing migrations" 
128158print_info " Running atlas-migrate-hash..." 
129159cd  " ${SCRIPT_DIR} /.." 
130160./scripts/atlas-migrate-hash --yes
131161print_success " Migrations rehashed" 
132162
133- #  Step 4 : Generate new migration
134- print_header " Step 3 : Generating new migration" 
163+ #  Step 5 : Generate new migration
164+ print_header " Step 4 : Generating new migration" 
135165print_info " Running atlas-migrate-diff with name: ${BOLD}${TEMP_NAME}${NC} " 
136166./scripts/atlas-migrate-diff " $TEMP_NAME " 
137167print_success " New migration generated" 
138168
139- #  Step 5 : Verify the migration
140- print_header " Step 4 : Verifying migration" 
169+ #  Step 6 : Verify the migration
170+ print_header " Step 5 : Verifying migration" 
141171
142172#  5a: Verify migrations
143173echo 
0 commit comments