fix(deploy): handle alembic baseline stamping

This commit is contained in:
Xiaoxia AI
2026-06-21 06:55:56 +08:00
parent bfbaddbd9a
commit 4c89d6b440
+8 -3
View File
@@ -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