db-migration-reviewer
Skill1 starsChanged 3 months agoMITView on GitHub
数据库迁移评审。审查迁移脚本的安全性、可回滚性、锁表风险与数据一致性,输出带严重级别的评审报告。Use to review database migrations for safety, rollback, locking and data integrity before deployment.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- proflead/codex-skills-librarytheir own version, first seen Jun 18, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- proflead/codex-skills-library★ 153same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository28 other files it gives its agents.
- api-contract-designerSkill
- api-testerSkill
- bug-diagnoserSkill
- cache-governorSkill
- ci-cd-setupSkill
- code-migratorSkill
- code-reviewerSkill
- commit-message-writerSkill
- db-schema-designerSkill
- dev-env-troubleshooterSkill
- frontend-debugSkill
- git-workflowSkill
- log-analysisSkill
- meeting-minutesSkill
- natural-chinese-writerSkill
- performance-profilerSkill
- release-note-writerSkill
- requirement-clarifierSkill
- requirements-reviewerSkill
- security-reviewerSkill
- skill-creator-cnSkill
- skill-style-guideSkill
- sql-reviewerSkill
- task-decomposerSkill
- tdd-workflowSkill
- tech-design-writerSkill
- tech-doc-writerSkill
- weekly-reportSkill
The file
Files
数据库迁移评审
何时使用
- 合并前要评审迁移脚本(up/down、SQL 文件);
- 大表变更上线前,想确认会不会锁表、会不会丢数据;
- 迁移经常在生产环境出问题,想建立检查流程;
- 用户明确说"帮我看下这个迁移安不安全"。
使用步骤
第 1 步:定位迁移与数据库类型
先确认:
- 迁移文件位置与框架(Alembic、Flyway、golang-migrate、prisma migrate 等);
- 目标数据库(PostgreSQL、MySQL、SQLite…),规则有差异;
- 涉及的表和已有数据量(表大不大,线上有没有流量)。
第 2 步:逐项检查安全红线
以下问题按严重级别处理:
| 级别 | 问题 |
| P0 阻断 | 大表上普通 CREATE INDEX(阻塞写入,应改用 CONCURRENTLY 或在线变更) |
| P0 | 删除/更新语句没有 WHERE,或 WHERE 明显错误 |
| P0 | 新加列 NOT NULL 且无默认值(大表会重写并锁表) |
| P0 | 生产环境没有备份或回滚方案就执行破坏性操作 |
| P1 严重 | 同一次迁移里混了 DDL 和 DML(改结构 + 回填数据) |
| P1 | 加 volatile 默认值(如 DEFAULT now())导致整表重写 |
| P1 | 迁移不可回滚且没有标注原因 |
| P2 一般 | 缺少索引或索引冗余、约束缺失 |
| P3 建议 | 命名、格式、注释问题 |
第 3 步:检查可回滚性
- 有 down 迁移吗?down 是否真的能还原;
- 不可逆的迁移(如删列)是否显式标注,并确认数据已备份;
- 回滚顺序和 up 是否完全相反。
第 4 步:检查数据一致性
- 回填数据是否单独成步,不塞进结构变更里;
- 批量操作是否分批(避免长事务和日志膨胀);
- 约束(外键、唯一)加上前,线上存量数据是否已校验;
- 变更后 ORM 模型与 schema 是否对齐(有没有 drift)。
第 5 步:输出评审报告
PostgreSQL/MySQL 差异对照与锁阻塞速查见 references/DB_DIFFERENCES.md。
# 迁移评审报告:<文件名>
## 结论
通过 / 修改后通过 / 不通过
## 问题清单
| 级别 | 位置 | 问题 | 证据 | 建议 |
## 风险说明
涉及的表、预估数据量、上线窗口
## 回滚方案输入与输出
- 输入:迁移文件(或 diff)+ 数据库类型;
- 输出:评审报告 + 修改建议。
示例
迁移内容(节选):
ALTER TABLE orders ADD COLUMN discount DECIMAL NOT NULL;评审发现:
- P0:大表上新增
NOT NULL无默认值,会全表重写并锁表; - 建议:改为可空 + 默认值,回填单独成一步,再收紧约束:
ALTER TABLE orders ADD COLUMN discount DECIMAL NOT NULL DEFAULT 0;
-- 数据回填(单独迁移)
UPDATE orders SET discount = 0;
-- 收紧(确认存量数据后,单独迁移)辅助脚本
scripts/migration_template.py 生成 up/down 迁移骨架和评审清单:
python scripts/migration_template.py add_user_email --db postgres生成三个文件:up 脚本、down 脚本、评审清单。
注意事项
- 不同数据库规则不同:PostgreSQL 用
CREATE INDEX CONCURRENTLY,MySQL 用ALGORITHM=INPLACE, LOCK=NONE; - 不确定线上数据量就问用户或看监控,不要假设表很小;
- 只评审、不替用户执行生产迁移;
- 评审意见要带证据(哪一行、会有什么后果),不能只说"有风险"。
不适用场景
- 迁移还没写,需要的是生成迁移(那是另一件事);
- 用户没有提供迁移文件和数据库信息;
- 数据库未上线、无生产数据(重点应放在设计上)。
验证方式
- 触发:"帮我看下这个迁移安不安全";
- 检查:报告覆盖锁表、回滚、数据一致性,问题带级别和证据;
- 抽查:任选一条 P0/P1 意见,对照迁移文件确认问题真实存在。
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

