@@ -69,7 +69,36 @@ MIGRATIONS_DIR="${SCRIPT_DIR}/../supabase/migrations"
69
69
70
70
print_header " pgflow Temporary Migration Regenerator"
71
71
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_"
73
102
print_info " Searching for newest temporary migration..."
74
103
75
104
# Find all migrations with pgflow_temp_ and get the newest one
@@ -99,10 +128,11 @@ print_info "Extracted migration name: ${BOLD}${TEMP_NAME}${NC}"
99
128
# Show what will be done
100
129
echo
101
130
print_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:"
106
136
echo -e " • pnpm nx verify-migrations core"
107
137
echo -e " • pnpm nx gen-types core"
108
138
echo -e " • pnpm nx test:pgtap core"
@@ -117,27 +147,27 @@ else
117
147
print_info " Skipping confirmation (--yes flag provided)"
118
148
fi
119
149
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"
122
152
print_info " Removing: ${MIGRATION_BASENAME} "
123
153
rm " $NEWEST_MIGRATION "
124
154
print_success " Migration removed"
125
155
126
- # Step 3 : Rehash migrations
127
- print_header " Step 2 : Rehashing migrations"
156
+ # Step 4 : Rehash migrations
157
+ print_header " Step 3 : Rehashing migrations"
128
158
print_info " Running atlas-migrate-hash..."
129
159
cd " ${SCRIPT_DIR} /.."
130
160
./scripts/atlas-migrate-hash --yes
131
161
print_success " Migrations rehashed"
132
162
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"
135
165
print_info " Running atlas-migrate-diff with name: ${BOLD}${TEMP_NAME}${NC} "
136
166
./scripts/atlas-migrate-diff " $TEMP_NAME "
137
167
print_success " New migration generated"
138
168
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"
141
171
142
172
# 5a: Verify migrations
143
173
echo
0 commit comments