build(migration): pre-commit拦截migration 多head问题

This commit is contained in:
sophie committed 2026-06-09 11:08:16 +08:00
1 parent 4fa5ab4929
commit ac67b07107
5 files changed
+263 -3

No files matched your search

+9
View File
@@ -32,6 +32,15 @@ if [[ "${MODELS_CHANGED}" -eq 1 && "${MIGRATION_CHANGED}" -eq 0 ]]; then
exit 1
fi
# migration 链校验:防止多人并行 migration 合并后出现多 head,部署时 db upgrade 失败
# 实现见 scripts/check_migration_heads.py(离线读文件,无需数据库)
if [[ "${MIGRATION_CHANGED}" -eq 1 ]]; then
STAGED_NEW_MIGRATIONS="$(git diff --cached --name-only --diff-filter=A -- 'backend/migrations/versions/*.py' || true)"
if ! run_migration_heads_check "${ROOT_DIR}" "${STAGED_NEW_MIGRATIONS}"; then
exit 1
fi
fi
if hook_should_skip; then
exit 0
fi