ci: validate alembic migration chain
Deploy / Deploy Production (push) Failing after 2095h41m1s
CI/CD Pipeline / Validate Code Quality And Tests (push) Failing after 2095h41m25s
Deploy / Deploy Staging (push) Has been cancelled

This commit is contained in:
Xiaoxia AI
2026-06-21 07:49:23 +08:00
parent 309906cb53
commit 4a8703b037
3 changed files with 23 additions and 9 deletions
+10 -3
View File
@@ -61,12 +61,19 @@ jobs:
- name: Run code quality checks
run: |
python -m compileall -q apps packages tests
python -m black --check apps packages tests
python -m isort --check-only apps packages tests
python -m compileall -q alembic apps packages tests
python -m black --check alembic apps packages tests
python -m isort --check-only alembic apps packages tests
python -m flake8 apps packages tests --count --statistics
bandit -r apps packages -q
- name: Validate Alembic migrations
run: |
DATABASE_URL=postgresql+psycopg://postgres:postgres@localhost:5432/xiaoxia_saas \
python -m alembic upgrade head --sql > /tmp/alembic-upgrade.sql
test -s /tmp/alembic-upgrade.sql
grep -q "Running upgrade" /tmp/alembic-upgrade.sql
- name: Run tests
run: |
python -m pytest tests -q
+10 -3
View File
@@ -61,12 +61,19 @@ jobs:
- name: Run code quality checks
run: |
python -m compileall -q apps packages tests
python -m black --check apps packages tests
python -m isort --check-only apps packages tests
python -m compileall -q alembic apps packages tests
python -m black --check alembic apps packages tests
python -m isort --check-only alembic apps packages tests
python -m flake8 apps packages tests --count --statistics
bandit -r apps packages -q
- name: Validate Alembic migrations
run: |
DATABASE_URL=postgresql+psycopg://postgres:postgres@localhost:5432/xiaoxia_saas \
python -m alembic upgrade head --sql > /tmp/alembic-upgrade.sql
test -s /tmp/alembic-upgrade.sql
grep -q "Running upgrade" /tmp/alembic-upgrade.sql
- name: Run tests
run: |
python -m pytest tests -q
+3 -3
View File
@@ -25,6 +25,7 @@ staging / production 不允许依赖 `Base.metadata.create_all()` 建表;表
- staging 数据库 `alembic_version` 已确认:`001`
- staging health endpoint 已确认 healthy
- `develop` 部署 job 已确认 succeeded
- CI 已增加 Alembic offline upgrade SQL 生成检查,验证 migration 链可加载并能生成 `upgrade head` SQL
## 已废弃入口
@@ -55,9 +56,8 @@ staging / production 不允许依赖 `Base.metadata.create_all()` 建表;表
后续 schema 工作应继续推进:
1. CI 增加迁移检查:`alembic upgrade head`。
2. 新增 revision drift 检查,防止 models 已改但未生成 migration。
3. 对 production 首次接入 Alembic 前,先执行只读 schema/数据备份检查。
1. 新增 revision drift 检查,防止 models 已改但未生成 migration。
2. 对 production 首次接入 Alembic 前,先执行只读 schema/数据备份检查。
## 禁止事项