← 返回
未分类 Key 中文

migratesafe

Database migration safety checker — catches destructive migrations before they reach production
数据库迁移安全检查器 — 在破坏性迁移到达生产环境前将其捕获
suhteevah
未分类 clawhub v1.0.2 1 版本 100000 Key: 需要
★ 0
Stars
📥 365
下载
💾 0
安装
1
版本
#latest

概述

MigrateSafe — Database Migration Safety Checker

MigrateSafe analyzes database migration files for destructive operations before they reach production. It detects DROP TABLE, column removals, risky type changes, missing rollbacks, lock hazards, and unsafe ALTER operations across raw SQL, Rails, Django, Knex.js, Prisma, Flyway, and Liquibase migrations. It uses regex-based pattern matching with risk scoring and produces compliance reports.

Commands

Free Tier (No license required)

migratesafe scan [file|directory]

One-shot scan of migration files for destructive operations.

How to execute:

bash "<SKILL_DIR>/scripts/migratesafe.sh" scan [target]

What it does:

  1. Accepts a file path or directory (defaults to current directory)
  2. Auto-detects migration framework (SQL, Rails, Django, Knex, Prisma, Flyway, Liquibase)
  3. Finds all migration files in standard locations (db/migrate, migrations/, prisma/migrations, sql/)
  4. Runs 15+ destructive operation patterns against each file
  5. Calculates a risk score (0-100) per file and overall
  6. Outputs findings with: file, line number, severity, operation, recommendation
  7. Exit code 0 if safe, exit code 1 if critical/high risk operations detected
  8. Free tier limited to 3 migration files per scan

Example usage scenarios:

  • "Check my migrations for destructive operations" -> runs migratesafe scan .
  • "Is this migration safe to deploy?" -> runs migratesafe scan db/migrate/20240115_add_users.sql
  • "Scan my SQL files for DROP statements" -> runs migratesafe scan migrations/

migratesafe help

Show available commands and usage information.

bash "<SKILL_DIR>/scripts/migratesafe.sh" help

migratesafe version

Show version information.

bash "<SKILL_DIR>/scripts/migratesafe.sh" version

Pro Tier ($19/user/month -- requires MIGRATESAFE_LICENSE_KEY)

migratesafe hooks install

Install git pre-commit hooks that scan staged migration files before every commit.

How to execute:

bash "<SKILL_DIR>/scripts/migratesafe.sh" hooks install

What it does:

  1. Validates Pro+ license
  2. Copies lefthook config to project root
  3. Installs lefthook pre-commit hook
  4. On every commit: scans all staged migration files, blocks commit if critical/high risk, shows remediation advice

migratesafe hooks uninstall

Remove MigrateSafe git hooks.

bash "<SKILL_DIR>/scripts/migratesafe.sh" hooks uninstall

migratesafe rollback-check [directory]

Verify that every UP migration has a corresponding DOWN/rollback migration.

bash "<SKILL_DIR>/scripts/migratesafe.sh" rollback-check [directory]

What it does:

  1. Validates Pro+ license
  2. Scans migration directories for UP migrations
  3. Checks for corresponding rollback/down files or reversible blocks
  4. Reports missing rollbacks with severity assessment

migratesafe diff

Compare two schema versions and highlight dangerous changes.

bash "<SKILL_DIR>/scripts/migratesafe.sh" diff schema_v1.sql schema_v2.sql

What it does:

  1. Validates Pro+ license
  2. Compares two SQL schema files
  3. Identifies dropped tables, removed columns, type changes
  4. Shows side-by-side diff with risk annotations

Team Tier ($39/user/month -- requires MIGRATESAFE_LICENSE_KEY with team tier)

migratesafe history [directory]

Show migration risk history across all migrations in the project.

bash "<SKILL_DIR>/scripts/migratesafe.sh" history [directory]

What it does:

  1. Validates Team+ license
  2. Scans all migration files chronologically
  3. Builds a risk timeline showing when dangerous migrations were introduced
  4. Reports cumulative risk score and trends

migratesafe report [directory]

Generate a full compliance report in markdown format.

bash "<SKILL_DIR>/scripts/migratesafe.sh" report [directory]

What it does:

  1. Validates Team+ license
  2. Runs full scan of all migration files
  3. Generates a formatted markdown report from template
  4. Includes per-file breakdowns, risk scores, recommendations, rollback status
  5. Output suitable for compliance audits and change advisory boards

Detected Destructive Operations

MigrateSafe detects 15+ destructive patterns across 7 migration frameworks:

| Category | Examples | Severity |

|----------|----------|----------|

| Table Drops | DROP TABLE, drop_table, DeleteModel, dropTable | Critical |

| Truncation | TRUNCATE TABLE, unconditional DELETE FROM | Critical |

| Column Drops | DROP COLUMN, remove_column, RemoveField, dropColumn | High |

| Type Changes | ALTER COLUMN...TYPE, change_column, AlterField | High |

| Constraint Removal | DROP CONSTRAINT, DROP INDEX, RemoveConstraint, remove_index | High |

| NOT NULL Additions | SET NOT NULL (without DEFAULT), add non-null column | Medium |

| Missing Transactions | Migrations not wrapped in BEGIN/COMMIT | Medium |

| Lock Hazards | CREATE INDEX (without CONCURRENTLY), ALTER TABLE on large tables | Medium |

| Cascade Deletes | ON DELETE CASCADE, CASCADE changes | Medium |

| Column Renames | RENAME COLUMN, rename_column, RenameField | Low |

| Data Loss Risk | REPLACE operations, ON DELETE SET NULL changes | Low |

Supported Migration Frameworks

| Framework | File Pattern | Detection |

|-----------|-------------|-----------|

| Raw SQL | *.sql | Full SQL pattern matching |

| Rails | db/migrate/*.rb | remove_column, drop_table, change_column, etc. |

| Django | migrations/*.py | RemoveField, DeleteModel, AlterField, etc. |

| Knex.js | migrations/.js/.ts | dropTable, dropColumn, raw.*DROP, etc. |

| Prisma | prisma/migrations/*.sql | Full SQL pattern matching |

| Flyway | sql/V*.sql | Full SQL pattern matching |

| Liquibase | *.xml changesets | dropTable, dropColumn, modifyDataType, etc. |

Configuration

Add to ~/.openclaw/openclaw.json:

{
  "skills": {
    "entries": {
      "migratesafe": {
        "enabled": true,
        "apiKey": "YOUR_LICENSE_KEY",
        "config": {
          "severityThreshold": "high",
          "migrationDirs": ["db/migrate", "migrations", "prisma/migrations", "sql"],
          "ignorePatterns": ["**/test/**", "**/seed/**"],
          "requireRollbacks": true,
          "blockOnCritical": true
        }
      }
    }
  }
}

Important Notes

  • Free tier works immediately -- no configuration needed
  • All scanning happens locally -- no code or schema data sent to external servers
  • License validation is offline -- no phone-home or network calls
  • Supports multiple migration frameworks in the same project
  • Risk scores are cumulative -- a file with multiple issues scores higher
  • Git hooks use lefthook which must be installed (see install metadata above)
  • Exit codes: 0 = safe, 1 = dangerous operations detected (for CI/CD integration)

Error Handling

  • If lefthook is not installed and user tries hooks install, prompt to install it
  • If license key is invalid or expired, show clear message with link to https://migratesafe.pages.dev/renew
  • If no migration files found in target, report clean scan with info message
  • If a file is binary, skip it automatically with no warning
  • If migration framework cannot be determined, fall back to raw SQL pattern matching

When to Use MigrateSafe

The user might say things like:

  • "Check my migrations for destructive operations"
  • "Is this migration safe to run?"
  • "Scan for DROP TABLE statements"
  • "Verify my rollback migrations exist"
  • "Generate a migration safety report"
  • "Set up pre-commit hooks for migrations"
  • "Check if this schema change is dangerous"
  • "Block destructive migrations from being committed"
  • "Compare two schema versions"
  • "Show migration risk history"

版本历史

共 1 个版本

  • v1.0.2 当前
    2026-05-07 13:31 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

security-compliance

DepGuard

suhteevah
使用原生包管理器审计扫描项目依赖的漏洞和许可证合规性,并生成安全或合规报告。
★ 0 📥 1,181
developer-tools

DocSync

suhteevah
通过 git hooks 自动生成并同步文档;使用 tree‑sitter 解析和语义 diff 在本地检测并修复文档漂移。
★ 0 📥 1,304
security-compliance

Claude Local Bridge

suhteevah
安全的MCP桥接,让手机上的Claude能够浏览和编辑本地仓库,具备实时、人工审批的文件访问和审计日志功能。
★ 0 📥 1,099