migrate-validate
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMigrate Validate
Migrate Validate
Validate all pending database migrations for correctness, safety, and adherence to best practices.
验证所有待执行数据库迁移的正确性、安全性及对最佳实践的遵循情况。
When to use
使用场景
Before applying migrations to catch issues early -- foreign key references to non-existent tables, missing rollback SQL, destructive operations without safeguards, and naming convention violations.
在应用迁移之前提前发现问题——比如外键引用了不存在的表、缺少回滚SQL、无保护的破坏性操作,以及违反命名规范的情况。
Steps
步骤
- Find pending migrations -- use to list all migration files, cross-reference with applied history via
Globto identify pending onesmcp__claude-flow__agentdb_hierarchical-recall - Parse SQL -- use to load each pending
Readand.up.sqlfile and parse the SQL statements.down.sql - Check foreign keys -- verify that all REFERENCES targets exist in the current schema or in prior migrations (both applied and pending)
- Check NOT NULL defaults -- verify that any ADD COLUMN with NOT NULL has a DEFAULT value
- Check rollback completeness -- verify every CREATE/ALTER in the UP file has a corresponding DROP/ALTER in the DOWN file
- Flag destructive ops -- warn on DROP TABLE, DROP COLUMN, TRUNCATE without explicit confirmation
- Check idempotency -- verify IF EXISTS / IF NOT EXISTS is used for safety
- Check naming -- verify table names are plural, column names are snake_case, index names follow convention
idx_table_column - Store results -- call to record validation patterns for future reference
mcp__claude-flow__agentdb_pattern-store - Report -- display: errors (must fix), warnings (should fix), info (suggestions), with file path and line number for each issue
- 查找待执行迁移——使用列出所有迁移文件,通过
Glob与已应用的历史记录交叉比对,识别出待执行的迁移文件mcp__claude-flow__agentdb_hierarchical-recall - 解析SQL——使用加载每个待执行的
Read和.up.sql文件并解析SQL语句.down.sql - 检查外键——验证所有REFERENCES目标在当前 schema 或之前的迁移(已应用和待执行的)中存在
- 检查NOT NULL默认值——验证任何带NOT NULL的ADD COLUMN语句都有DEFAULT值
- 检查回滚完整性——验证UP文件中的每个CREATE/ALTER操作在DOWN文件中都有对应的DROP/ALTER操作
- 标记破坏性操作——对无明确确认的DROP TABLE、DROP COLUMN、TRUNCATE操作发出警告
- 检查幂等性——验证是否使用了IF EXISTS / IF NOT EXISTS以确保安全
- 检查命名——验证表名为复数形式、列名为蛇形命名(snake_case)、索引名称遵循规范
idx_table_column - 存储结果——调用记录验证模式,以备未来参考
mcp__claude-flow__agentdb_pattern-store - 生成报告——显示:错误(必须修复)、警告(建议修复)、信息(建议),并标注每个问题的文件路径和行号
CLI alternative
CLI替代方案
bash
npx @claude-flow/cli@latest memory search --query "migration validation results" --namespace migrationsbash
npx @claude-flow/cli@latest memory search --query "migration validation results" --namespace migrations