From 894e6ec2c19f6592a9af8e79d4faf593c4bcd4e2 Mon Sep 17 00:00:00 2001 From: Codex Date: Wed, 17 Jun 2026 04:56:48 +0200 Subject: [PATCH] Retry database readiness in live smoke --- scripts/live_migration_smoke.sh | 38 +++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/scripts/live_migration_smoke.sh b/scripts/live_migration_smoke.sh index 6f4f8100..3bd16d83 100755 --- a/scripts/live_migration_smoke.sh +++ b/scripts/live_migration_smoke.sh @@ -20,13 +20,26 @@ cd /app echo "Database URL is read from backend container settings / DATABASE_URL." python - <<'PY' +import time + from sqlalchemy import text +from sqlalchemy.exc import OperationalError from app.db.session import get_engine -with get_engine().connect() as connection: - connection.execute(text("SELECT 1")) - print("Database connection: ok") +last_error = None +for attempt in range(1, 61): + try: + with get_engine().connect() as connection: + connection.execute(text("SELECT 1")) + print(f"Database connection: ok after attempt {attempt}") + break + except OperationalError as exc: + last_error = exc + print(f"Database not ready yet ({attempt}/60): {exc}") + time.sleep(2) +else: + raise SystemExit(f"Database did not become ready: {last_error}") PY python -m alembic upgrade head @@ -113,13 +126,26 @@ echo "Using Python: $PYTHON_BIN" echo "Database URL is read from backend settings / DATABASE_URL." "$PYTHON_BIN" - <<'PY' +import time + from sqlalchemy import text +from sqlalchemy.exc import OperationalError from app.db.session import get_engine -with get_engine().connect() as connection: - connection.execute(text("SELECT 1")) - print("Database connection: ok") +last_error = None +for attempt in range(1, 61): + try: + with get_engine().connect() as connection: + connection.execute(text("SELECT 1")) + print(f"Database connection: ok after attempt {attempt}") + break + except OperationalError as exc: + last_error = exc + print(f"Database not ready yet ({attempt}/60): {exc}") + time.sleep(2) +else: + raise SystemExit(f"Database did not become ready: {last_error}") PY "$PYTHON_BIN" -m alembic upgrade head