fix(db): 禁止修改已发布迁移并分批兼容旧库

This commit is contained in:
yml2213
2026-11-07 17:51:34 +08:00
parent 7b68d9b60a
commit 8ef8c61862
12 changed files with 253 additions and 123 deletions
+16
View File
@@ -666,6 +666,21 @@ start_postgres() {
fail "PostgreSQL 启动失败,请根据上面的日志排查。"
}
prepare_database_migrations() {
local preflight_sql="${PROJECT_ROOT}/deploy/sql/prepare-113-finance-cutover.sql"
[[ -f "${preflight_sql}" ]] || fail "缺少迁移前置兼容脚本:${preflight_sql}"
log "检查旧库的迁移前置兼容数据"
if docker compose exec -T postgres sh -lc \
'psql -v ON_ERROR_STOP=1 -U "${POSTGRES_USER:-postgres}" -d "${POSTGRES_DB:-order_site}"' \
< "${preflight_sql}"; then
return
fi
print_diagnostics
fail "迁移前置兼容检查失败,已停止部署"
}
run_database_migrations() {
log "执行数据库迁移"
if docker compose run --rm --no-deps backend node dist/db/migrate.js; then
@@ -810,6 +825,7 @@ deploy_stack() {
reset_database
time_step "启动 PostgreSQL" start_postgres
time_step "迁移前备份" backup_before_migrate
time_step "检查迁移前置兼容数据" prepare_database_migrations
time_step "执行数据库迁移" run_database_migrations
time_step "启动后端" restart_backend
time_step "启动 Web 入口" restart_web