@@ -19,28 +19,31 @@ STAT_EXTENSION_SQL=@STAT_EXTENSION_SQL@
1919cleanup () {
2020 echo " Cleaning up..."
2121
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
2329 if [ -S " ./.overmind.sock" ]; then
2430 overmind kill || true
2531 sleep 2
2632 fi
2733
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
3436 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
3540
36- # Remove socket and Procfile
3741 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
4447 fi
4548}
4649
@@ -143,6 +146,24 @@ wait_for_postgres() {
143146 return 1
144147}
145148
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+
146167trim_schema () {
147168 case " $CURRENT_SYSTEM " in
148169 " x86_64-darwin" |" aarch64-darwin" )
165186 while [ $count -lt $max_wait ]; do
166187 if [ -S " ./.overmind.sock" ]; then
167188 # Found the socket, give it a moment to be ready
168- sleep 2
189+ sleep 5
169190 echo " Socket file found and ready"
170191 break
171192 fi
174195 count=$(( count + 1 ))
175196 done
176197}
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+ }
177217migrate_version () {
178218 echo " PSQL_VERSION: $PSQL_VERSION "
179219 overmind kill || true
@@ -193,6 +233,13 @@ migrate_version() {
193233 echo " Failed to connect to PostgreSQL server"
194234 exit 1
195235 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
196243
197244 echo " PostgreSQL server is ready"
198245
@@ -233,7 +280,7 @@ EOSQL
233280 fi
234281
235282 echo " Running dbmate dump with $PSQLBIN "
236- dbmate dump
283+ perform_dump
237284
238285 echo " CURRENT_SYSTEM: $CURRENT_SYSTEM "
239286 if [ -f " ./db/schema.sql" ]; then
0 commit comments