migrate-validate

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Migrate 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

步骤

  1. Find pending migrations -- use
    Glob
    to list all migration files, cross-reference with applied history via
    mcp__claude-flow__agentdb_hierarchical-recall
    to identify pending ones
  2. Parse SQL -- use
    Read
    to load each pending
    .up.sql
    and
    .down.sql
    file and parse the SQL statements
  3. Check foreign keys -- verify that all REFERENCES targets exist in the current schema or in prior migrations (both applied and pending)
  4. Check NOT NULL defaults -- verify that any ADD COLUMN with NOT NULL has a DEFAULT value
  5. Check rollback completeness -- verify every CREATE/ALTER in the UP file has a corresponding DROP/ALTER in the DOWN file
  6. Flag destructive ops -- warn on DROP TABLE, DROP COLUMN, TRUNCATE without explicit confirmation
  7. Check idempotency -- verify IF EXISTS / IF NOT EXISTS is used for safety
  8. Check naming -- verify table names are plural, column names are snake_case, index names follow
    idx_table_column
    convention
  9. Store results -- call
    mcp__claude-flow__agentdb_pattern-store
    to record validation patterns for future reference
  10. Report -- display: errors (must fix), warnings (should fix), info (suggestions), with file path and line number for each issue
  1. 查找待执行迁移——使用
    Glob
    列出所有迁移文件,通过
    mcp__claude-flow__agentdb_hierarchical-recall
    与已应用的历史记录交叉比对,识别出待执行的迁移文件
  2. 解析SQL——使用
    Read
    加载每个待执行的
    .up.sql
    .down.sql
    文件并解析SQL语句
  3. 检查外键——验证所有REFERENCES目标在当前 schema 或之前的迁移(已应用和待执行的)中存在
  4. 检查NOT NULL默认值——验证任何带NOT NULL的ADD COLUMN语句都有DEFAULT值
  5. 检查回滚完整性——验证UP文件中的每个CREATE/ALTER操作在DOWN文件中都有对应的DROP/ALTER操作
  6. 标记破坏性操作——对无明确确认的DROP TABLE、DROP COLUMN、TRUNCATE操作发出警告
  7. 检查幂等性——验证是否使用了IF EXISTS / IF NOT EXISTS以确保安全
  8. 检查命名——验证表名为复数形式、列名为蛇形命名(snake_case)、索引名称遵循
    idx_table_column
    规范
  9. 存储结果——调用
    mcp__claude-flow__agentdb_pattern-store
    记录验证模式,以备未来参考
  10. 生成报告——显示:错误(必须修复)、警告(建议修复)、信息(建议),并标注每个问题的文件路径和行号

CLI alternative

CLI替代方案

bash
npx @claude-flow/cli@latest memory search --query "migration validation results" --namespace migrations
bash
npx @claude-flow/cli@latest memory search --query "migration validation results" --namespace migrations