diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f343508a9..b6912b38f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,7 +26,7 @@ jobs: - name: Set PostgreSQL versions id: set-versions run: | - VERSIONS=$(nix run nixpkgs#yq -- '.postgres_major[] | select(. != "orioledb-17")' ansible/vars.yml | nix run nixpkgs#jq -- -R -s -c 'split("\n")[:-1]') + VERSIONS=$(nix run nixpkgs#yq -- '.postgres_major[]' ansible/vars.yml | nix run nixpkgs#jq -- -R -s -c "split(\"\n\")[:-1]") echo "postgres_versions=$VERSIONS" >> $GITHUB_OUTPUT build: needs: prepare diff --git a/nix/tools/dbmate-tool.sh.in b/nix/tools/dbmate-tool.sh.in index b41e83f0b..8c489839b 100644 --- a/nix/tools/dbmate-tool.sh.in +++ b/nix/tools/dbmate-tool.sh.in @@ -19,28 +19,31 @@ STAT_EXTENSION_SQL=@STAT_EXTENSION_SQL@ cleanup() { echo "Cleaning up..." - # Kill overmind processes first + # Kill postgres processes first + if pgrep -f "postgres" >/dev/null; then + pkill -TERM postgres || true + sleep 2 + fi + + # Then kill overmind if [ -S "./.overmind.sock" ]; then overmind kill || true sleep 2 fi - # Kill any remaining postgres processes - echo "Killing any remaining postgres processes..." - pkill -9 postgres || true - pkill -9 -f "tmux.*overmind.*postgresql" || true - - # Extra cleanup for tmux sessions + # Kill tmux sessions explicitly + pkill -f "tmux.*overmind.*postgresql" || true tmux ls 2>/dev/null | grep 'overmind' | cut -d: -f1 | xargs -I{} tmux kill-session -t {} || true + + # Force kill any stragglers + pkill -9 -f "(postgres|tmux.*overmind.*postgresql)" || true - # Remove socket and Procfile rm -f .overmind.sock Procfile - - # Verify cleanup - remaining=$(ps aux | grep -E "(postgres|overmind|tmux.*postgresql)" | grep -v grep || true) - if [ ! -z "$remaining" ]; then - echo "Warning: Some processes might still be running:" - echo "$remaining" + + # Final verification + if ps aux | grep -E "(postgres|overmind|tmux.*postgresql)" | grep -v grep >/dev/null; then + ps aux | grep -E "(postgres|overmind|tmux.*postgresql)" | grep -v grep + return 1 fi } @@ -143,6 +146,24 @@ wait_for_postgres() { return 1 } +check_orioledb_ready() { + local max_attempts=30 + local attempt=1 + + while [ $attempt -le $max_attempts ]; do + 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 + echo "Orioledb extension is ready!" + return 0 + fi + echo "Waiting for orioledb to be ready (attempt $attempt/$max_attempts)..." + sleep 2 + attempt=$((attempt + 1)) + done + + echo "Orioledb failed to initialize after $max_attempts attempts" + return 1 +} + trim_schema() { case "$CURRENT_SYSTEM" in "x86_64-darwin"|"aarch64-darwin") @@ -165,7 +186,7 @@ EOF while [ $count -lt $max_wait ]; do if [ -S "./.overmind.sock" ]; then # Found the socket, give it a moment to be ready - sleep 2 + sleep 5 echo "Socket file found and ready" break fi @@ -174,6 +195,25 @@ EOF count=$((count + 1)) done } +perform_dump() { + local max_attempts=3 + local attempt=1 + + while [ $attempt -le $max_attempts ]; do + echo "Attempting dbmate dump (attempt $attempt/$max_attempts)" + + if dbmate dump; then + return 0 + fi + + echo "Dump attempt $attempt failed, waiting before retry..." + sleep 5 + attempt=$((attempt + 1)) + done + + echo "All dump attempts failed" + return 1 +} migrate_version() { echo "PSQL_VERSION: $PSQL_VERSION" overmind kill || true @@ -193,6 +233,13 @@ migrate_version() { echo "Failed to connect to PostgreSQL server" exit 1 fi + + if [ "$PSQL_VERSION" = "orioledb-17" ]; then + if ! check_orioledb_ready; then + echo "Failed to initialize orioledb extension" + exit 1 + fi + fi echo "PostgreSQL server is ready" @@ -233,7 +280,7 @@ EOSQL fi echo "Running dbmate dump with $PSQLBIN" - dbmate dump + perform_dump echo "CURRENT_SYSTEM: $CURRENT_SYSTEM" if [ -f "./db/schema.sql" ]; then