migration-safety-checker

Database migration safety reviewer — detect locks, data loss risks, missing rollback plans, and performance issues in SQL and ORM migrations before they hit production.

Safety Notice

This listing is from the official public ClawHub registry. Review SKILL.md and referenced scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "migration-safety-checker" with this command: npx skills add charlie-morrison/migration-safety-checker

Migration Safety Checker

Review database migrations for safety issues before they run in production. Catches table locks, data loss, missing rollbacks, and performance problems that would otherwise cause outages.

Use when: "review this migration", "is this migration safe", "check before we deploy", or when reviewing a PR that contains migration files.

Step 1 — Find Migrations

# Common migration locations
find . -type f \( \
  -path "*/migrations/*.sql" -o \
  -path "*/migrations/*.py" -o \
  -path "*/migrate/*.sql" -o \
  -path "*/db/migrate/*.rb" -o \
  -path "*/alembic/versions/*.py" -o \
  -path "*/prisma/migrations/*" -o \
  -path "*/drizzle/*.sql" -o \
  -path "*/knex/migrations/*" -o \
  -path "*/flyway/*.sql" -o \
  -path "*/liquibase/*.xml" -o \
  -path "*/sequelize/migrations/*" \
\) -not -path '*/node_modules/*' 2>/dev/null | sort | tail -10

# Latest migration (the one being reviewed)
git diff --name-only HEAD~1 | grep -i migrat

Step 2 — Check for Dangerous Operations

Read the migration file and check for each of these issues:

Locking Risks (HIGH)

OperationRiskFix
ALTER TABLE ... ADD COLUMN ... NOT NULLFull table lock on large tables (PostgreSQL <11, MySQL)Add column as nullable first, backfill, then add constraint
ALTER TABLE ... ADD COLUMN ... DEFAULTRewrites entire table (PostgreSQL <11)Add without default, backfill in batches, then set default
CREATE INDEXBlocks writes for duration of index buildUse CREATE INDEX CONCURRENTLY (Postgres) or ALGORITHM=INPLACE (MySQL)
ALTER TABLE ... ALTER COLUMN TYPEFull table rewrite + exclusive lockCreate new column, backfill, swap — never alter type on large tables
ALTER TABLE ... ADD CONSTRAINTValidates all rows (lock)Use NOT VALID then VALIDATE CONSTRAINT separately (Postgres)
LOCK TABLEExplicit lock — why?Almost never needed; remove or justify

Data Loss Risks (CRITICAL)

OperationRiskCheck
DROP TABLEPermanent data deletionIs there a backup? Is the table truly unused?
DROP COLUMNColumn data lostIs the column read anywhere? Check app code
TRUNCATEAll data deletedShould this be in a migration at all?
DELETE FROM without WHEREDeletes everythingMissing WHERE clause?
ALTER COLUMN ... TYPE with castPossible data truncationDo current values fit the new type?
DROP INDEXQuery performance regressionWas this index used? Check query plans

Rollback Issues (MEDIUM)

IssueCheck
No down/rollback migrationEvery up must have a down
Irreversible downDROP TABLE can't be rolled back with data
Data migration without reverseIf you transformed data, can you reverse it?
Schema + data in one migrationSplit them — data migrations should be separately rollbackable

Performance Issues (MEDIUM)

PatternIssueFix
Backfill in migrationBlocks deployment, holds transactionUse background jobs for large backfills
No batchingOne giant UPDATE/INSERTBatch in chunks of 1000-5000
Multiple ALTERs on same tableEach one locks separatelyCombine into one ALTER when possible
Large DEFAULT valuesRewrites tableAdd column, then set default separately

Step 3 — ORM-Specific Checks

Django / Alembic (Python)

# Watch for these in migration files:
# - RunPython without reverse_code → no rollback
# - AddField with default on large table → lock
# - AlterField changing type → rewrite
# - RemoveField → data loss
# - RunSQL without reverse_sql → no rollback

Rails (Ruby)

# Watch for:
# - add_column with null: false without default → fails on existing rows
# - add_index without algorithm: :concurrently → table lock
# - change_column → type change, possible lock
# - remove_column → data loss
# - No reversible block or no down method

Prisma / Drizzle / Knex (Node.js)

# Watch for:
# - Column made required (@required/NOT NULL) without default
# - Type changes on existing columns
# - Dropped columns or tables
# - No migration squashing on 50+ migration files

Step 4 — Production Readiness

Check these before approving:

  • Migration runs in a transaction (or explicitly opted out with reason)
  • Estimated row count for affected tables (< 1M rows = usually safe, > 10M = needs careful planning)
  • Tested on staging with production-size data
  • Rollback tested (run down migration, verify data intact)
  • Application code is backward-compatible with both old and new schema
  • Deploy order: schema first (additive), then code, then cleanup migration

Output Template

# Migration Review: [filename]

## Safety Rating: 🟢 Safe / 🟡 Caution / 🔴 Dangerous

## Operations
| # | Operation | Table | Risk | Issue |
|---|-----------|-------|------|-------|
| 1 | ADD COLUMN | users | 🟡 | NOT NULL without default — will lock on 2M rows |
| 2 | CREATE INDEX | orders | 🔴 | Not CONCURRENTLY — will block writes on 5M rows |

## Recommendations
1. [specific fix for each issue]

## Rollback Plan
- [does a rollback migration exist?]
- [is it tested?]
- [any data loss on rollback?]

## Estimated Impact
- Tables affected: X
- Estimated lock time: ~Xs on [table] ([row count] rows)
- Downtime required: yes/no

Notes

  • PostgreSQL 11+ handles ADD COLUMN ... DEFAULT without a table rewrite (but NOT NULL still needs NOT VALID trick)
  • MySQL 8.0+ supports instant ADD COLUMN at the end of the table
  • Always check the actual row count: SELECT reltuples FROM pg_class WHERE relname = 'table_name'
  • For zero-downtime deploys, follow the expand/contract pattern: add new → backfill → migrate code → drop old

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

Multi Edge-TTS CN

Edge-TTS 在线语音合成 skill。基于微软 Edge TTS 引擎,生成速度快(1-2秒),支持多种音色和输出格式。同时支持飞书(OGG/Opus)和企业微信(AMR)。默认音色 xiaoxiao_lively。需联网。

Registry SourceRecently Updated
General

vedic-destiny

吠陀命盘分析中文入口。用于完整命盘研判、命主盘 Rashi chart 与九分盘 Navamsha chart 联读、既往事件回看、出生时间稳定度判断、事业主题、婚姻主题、时空盘专题,以及基于 Jagannatha Hora PDF、星盘截图或文本命盘数据的系统拆盘。当用户提到完整星盘、事业方向、婚姻问题、关系窗...

Registry SourceRecently Updated
General

One Person Company OS

Build a visual operating cockpit for an AI-native one-person company across promise, buyer, product, delivery, cash, learning, and assets. / 为 AI 一人公司建立可视化经营...

Registry SourceRecently Updated
General

健康追踪

健康追踪技能 - 追踪饮水、睡眠、步数等健康数据,JSON存储。

Registry SourceRecently Updated