WMS_MAIN/temp/docs/rollback_plan.md

50 lines
1.6 KiB
Markdown
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.

# rollback_plan
更新时间: 2026-03-22
## 1. 通用回滚规则
- 所有新增 migration 必须提供 down。
- 对现网已有表,down 不应默认直接 drop 整表。
- 优先回滚新增字段、索引、约束,避免误删存量数据。
- 涉及数据回填的 migration,必须保留影响范围快照或备份。
## 2. 分类型回滚策略
### 建表 migration
- 新环境可使用 dropTable 回滚。
- 现网已有表不建议通过 down 删除,应改为“标记基线 + 停止继续执行”。
### 加字段 migration
- down 使用 dropColumn。
- 执行前需确认字段不被线上代码强依赖。
### 索引 migration
- down 使用 removeIndex。
- 若为性能补丁索引,回滚前需评估查询退化风险。
### 视图 migration
- down 使用 drop view。
- 回滚前确认是否有查询依赖视图。
### 动态分表策略 migration
- 只回滚策略与模板,不批量 drop 已创建的仓库动态表。
- 已存在分表应通过单独治理,不纳入统一 down 删除范围。
## 3. 当前优先风险
- 未进入 SequelizeMeta 的 migration 不能按常规 down 处理,必须先确认其是否已在数据库中手工生效。
- order_delivery/order_items 主表与动态表结构存在差异,回滚时必须区分主表与动态表。
- 日志类表通常已有存量数据,回滚需要避免整表删除。
## 4. 建议执行前准备
- 每批 migration 执行前导出目标表结构快照。
- 若涉及数据变更,先做行数统计与影响范围确认。
- 为每批次准备单独回滚脚本,不依赖临场拼写 SQL。