Files
order_site/apps/backend/scripts/reconcile-migration-history.sql
T
yml2213 0de0fd7b58 chore(db): 将 108–115 补丁迁移收敛为 108–111
- 原 108/111/112/113/114 合并为 108_finance_cost_integrity:
  成本异常归档、人工成本完整性、影子总账、商品页/模板查询索引
- 原 115 注释迁移改为 111_work_order_share_cancel_reason_comment
- 新增 reconcile-migration-history.sql,用于已跑旧 112–115 的库
  重建 schema_migrations 顺序,不重复执行 DDL
- 已验证:001→111、101→111 两条升级路径;
  旧 115 与新 111 的 pg_dump schema 完全一致
- 测试/文档迁移编号同步到 103–111

验证:backend check 853(849 pass / 4 skip);frontend check 172 + build。
2026-10-27 12:37:21 +08:00

55 lines
2.3 KiB
PL/PgSQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- 旧 108–115 → 新 108–111 的迁移元数据校准(仅用于已经跑过旧 112–115 的本地/测试库)。
--
-- 背景:2026-10-27 把原 108/111/112/113/114 合并成 108_finance_cost_integrity,
-- 原 115 注释迁移改名为 111。新库从 001/101 直接跑新文件即可;
-- 已跑过旧 112–115 的库 schema 已等价,只需把 schema_migrations 的旧名字替换掉,
-- 否则 node-pg-migrate 会因 108 顺序冲突拒绝启动。
--
-- 用法(先备份):
-- docker exec -i order_site-postgres-1 psql -U "$POSTGRES_USER" -d "$POSTGRES_DB" \
-- -v ON_ERROR_STOP=1 < apps/backend/scripts/reconcile-migration-history.sql
--
-- 幂等:只在检测到旧 112_finance_ledger 时执行。
BEGIN;
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM schema_migrations WHERE name = '112_finance_ledger') THEN
RAISE NOTICE '未检测到旧 112_finance_ledger,跳过迁移历史校准';
RETURN;
END IF;
-- 108–111 整段重建,保证 node-pg-migrate 的 runNames 顺序与文件顺序一致。
-- 109/110 的 schema 已经存在,重新登记不会重复执行。
DELETE FROM schema_migrations
WHERE name IN (
'108_cost_exception_archive',
'108_finance_cost_integrity',
'109_work_order_share_participation',
'110_work_order_hall_and_shop_indexes',
'111_manual_cost_integrity',
'111_work_order_share_cancel_reason_comment',
'112_finance_ledger',
'113_cost_center_query_indexes',
'114_template_evidence_indexes',
'115_work_order_share_cancel_reason_comment'
);
INSERT INTO schema_migrations (name, filename, run_on)
VALUES
('108_finance_cost_integrity', '108_finance_cost_integrity.sql', NOW()),
('109_work_order_share_participation', '109_work_order_share_participation.sql', NOW()),
('110_work_order_hall_and_shop_indexes', '110_work_order_hall_and_shop_indexes.sql', NOW()),
('111_work_order_share_cancel_reason_comment', '111_work_order_share_cancel_reason_comment.sql', NOW())
ON CONFLICT (name) DO NOTHING;
-- 旧 115 的注释效果已经在 schema 里;这里保证新基线也带上同一注释。
COMMENT ON COLUMN work_order_shares.cancelled_reason IS
'取消来源:timeout/worker_request/admin/admin_partial/problem/settlement';
RAISE NOTICE '迁移历史已校准为 108–111';
END $$;
COMMIT;