@@ -19,28 +19,31 @@ STAT_EXTENSION_SQL=@STAT_EXTENSION_SQL@
19
19
cleanup () {
20
20
echo " Cleaning up..."
21
21
22
- # Kill overmind processes first
22
+ # Kill postgres processes first
23
+ if pgrep -f " postgres" > /dev/null; then
24
+ pkill -TERM postgres || true
25
+ sleep 2
26
+ fi
27
+
28
+ # Then kill overmind
23
29
if [ -S " ./.overmind.sock" ]; then
24
30
overmind kill || true
25
31
sleep 2
26
32
fi
27
33
28
- # Kill any remaining postgres processes
29
- echo " Killing any remaining postgres processes..."
30
- pkill -9 postgres || true
31
- pkill -9 -f " tmux.*overmind.*postgresql" || true
32
-
33
- # Extra cleanup for tmux sessions
34
+ # Kill tmux sessions explicitly
35
+ pkill -f " tmux.*overmind.*postgresql" || true
34
36
tmux ls 2> /dev/null | grep ' overmind' | cut -d: -f1 | xargs -I{} tmux kill-session -t {} || true
37
+
38
+ # Force kill any stragglers
39
+ pkill -9 -f " (postgres|tmux.*overmind.*postgresql)" || true
35
40
36
- # Remove socket and Procfile
37
41
rm -f .overmind.sock Procfile
38
-
39
- # Verify cleanup
40
- remaining=$( ps aux | grep -E " (postgres|overmind|tmux.*postgresql)" | grep -v grep || true)
41
- if [ ! -z " $remaining " ]; then
42
- echo " Warning: Some processes might still be running:"
43
- echo " $remaining "
42
+
43
+ # Final verification
44
+ if ps aux | grep -E " (postgres|overmind|tmux.*postgresql)" | grep -v grep > /dev/null; then
45
+ ps aux | grep -E " (postgres|overmind|tmux.*postgresql)" | grep -v grep
46
+ return 1
44
47
fi
45
48
}
46
49
@@ -143,6 +146,24 @@ wait_for_postgres() {
143
146
return 1
144
147
}
145
148
149
+ check_orioledb_ready () {
150
+ local max_attempts=30
151
+ local attempt=1
152
+
153
+ while [ $attempt -le $max_attempts ]; do
154
+ if " ${PSQLBIN} /psql" -v ON_ERROR_STOP=1 -U " $PGSQL_SUPERUSER " -p " $PORTNO " -h localhost -d postgres -c " SELECT * FROM pg_am WHERE amname = 'orioledb'" | grep -q orioledb; then
155
+ echo " Orioledb extension is ready!"
156
+ return 0
157
+ fi
158
+ echo " Waiting for orioledb to be ready (attempt $attempt /$max_attempts )..."
159
+ sleep 2
160
+ attempt=$(( attempt + 1 ))
161
+ done
162
+
163
+ echo " Orioledb failed to initialize after $max_attempts attempts"
164
+ return 1
165
+ }
166
+
146
167
trim_schema () {
147
168
case " $CURRENT_SYSTEM " in
148
169
" x86_64-darwin" |" aarch64-darwin" )
165
186
while [ $count -lt $max_wait ]; do
166
187
if [ -S " ./.overmind.sock" ]; then
167
188
# Found the socket, give it a moment to be ready
168
- sleep 2
189
+ sleep 5
169
190
echo " Socket file found and ready"
170
191
break
171
192
fi
174
195
count=$(( count + 1 ))
175
196
done
176
197
}
198
+ perform_dump () {
199
+ local max_attempts=3
200
+ local attempt=1
201
+
202
+ while [ $attempt -le $max_attempts ]; do
203
+ echo " Attempting dbmate dump (attempt $attempt /$max_attempts )"
204
+
205
+ if dbmate dump; then
206
+ return 0
207
+ fi
208
+
209
+ echo " Dump attempt $attempt failed, waiting before retry..."
210
+ sleep 5
211
+ attempt=$(( attempt + 1 ))
212
+ done
213
+
214
+ echo " All dump attempts failed"
215
+ return 1
216
+ }
177
217
migrate_version () {
178
218
echo " PSQL_VERSION: $PSQL_VERSION "
179
219
overmind kill || true
@@ -193,6 +233,13 @@ migrate_version() {
193
233
echo " Failed to connect to PostgreSQL server"
194
234
exit 1
195
235
fi
236
+
237
+ if [ " $PSQL_VERSION " = " orioledb-17" ]; then
238
+ if ! check_orioledb_ready; then
239
+ echo " Failed to initialize orioledb extension"
240
+ exit 1
241
+ fi
242
+ fi
196
243
197
244
echo " PostgreSQL server is ready"
198
245
@@ -233,7 +280,7 @@ EOSQL
233
280
fi
234
281
235
282
echo " Running dbmate dump with $PSQLBIN "
236
- dbmate dump
283
+ perform_dump
237
284
238
285
echo " CURRENT_SYSTEM: $CURRENT_SYSTEM "
239
286
if [ -f " ./db/schema.sql" ]; then
0 commit comments