fix(db): 禁止修改已发布迁移并分批兼容旧库
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user