From 4c89d6b440eb147706445919cf4f2c1578b3bb2f Mon Sep 17 00:00:00 2001 From: Xiaoxia AI Date: Sun, 21 Jun 2026 06:55:56 +0800 Subject: [PATCH] fix(deploy): handle alembic baseline stamping --- infra/docker/deploy-staging.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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