diff --git a/infra/docker/deploy-staging.sh b/infra/docker/deploy-staging.sh index ea2dbb939..f6fca86bd 100644 --- a/infra/docker/deploy-staging.sh +++ b/infra/docker/deploy-staging.sh @@ -37,23 +37,28 @@ export COMPOSE_DOCKER_CLI_BUILD=0 docker compose build --pull=false api docker compose build --pull=false worker docker compose run --rm --no-deps api sh -c ' - cd /app && + cd /app + set +e python - <<"PY" import os from sqlalchemy import create_engine, text + url = os.environ["DATABASE_URL"] engine = create_engine(url) with engine.begin() as conn: has_version = conn.execute(text("SELECT to_regclass('public.alembic_version')")).scalar() is not None has_tables = conn.execute(text("SELECT COUNT(*) FROM pg_tables WHERE schemaname = 'public' AND tablename != 'alembic_version'")).scalar() if has_tables and not has_version: - raise SystemExit("STAMP_REQUIRED") + raise SystemExit(42) PY status=$? + set -e if [ "$status" -eq 0 ]; then alembic upgrade head - else + elif [ "$status" -eq 42 ]; then alembic stamp head && alembic upgrade head + else + exit "$status" fi ' docker compose up -d api worker web