Skip to content

Commit 28326ac

Browse files
committed
chore: fixing tool used to run dbmate migration checks
1 parent 9b2ba9a commit 28326ac

File tree

1 file changed

+37
-15
lines changed

1 file changed

+37
-15
lines changed

nix/tools/dbmate-tool.sh.in

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,31 @@ STAT_EXTENSION_SQL=@STAT_EXTENSION_SQL@
1919
cleanup() {
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

@@ -174,6 +177,25 @@ EOF
174177
count=$((count + 1))
175178
done
176179
}
180+
perform_dump() {
181+
local max_attempts=3
182+
local attempt=1
183+
184+
while [ $attempt -le $max_attempts ]; do
185+
echo "Attempting dbmate dump (attempt $attempt/$max_attempts)"
186+
187+
if dbmate dump; then
188+
return 0
189+
fi
190+
191+
echo "Dump attempt $attempt failed, waiting before retry..."
192+
sleep 5
193+
attempt=$((attempt + 1))
194+
done
195+
196+
echo "All dump attempts failed"
197+
return 1
198+
}
177199
migrate_version() {
178200
echo "PSQL_VERSION: $PSQL_VERSION"
179201
overmind kill || true
@@ -233,7 +255,7 @@ EOSQL
233255
fi
234256

235257
echo "Running dbmate dump with $PSQLBIN"
236-
dbmate dump
258+
perform_dump
237259

238260
echo "CURRENT_SYSTEM: $CURRENT_SYSTEM"
239261
if [ -f "./db/schema.sql" ]; then

0 commit comments

Comments
 (0)