db-migration
Apply schema migrations safely: detect the tool, classify the change by risk, gate destructive ones behind approval, back up in prod, preview-apply-verify…
от crewforth★ 26 звёзд на GitHub
Установить db-migration в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Database Migration
Trigger phrases: "migration", "schema change", "update database", "add column", "create table", "alter table", "add a column to", "adding a column to", "drop a column", "rename the table", "change the column type", "backfill"
A migration is very often a one-way gate: once applied, going back is expensive or impossible unless it was planned for. That is why the heart of the flow is not running a command, but classifying the change by risk class before it passes through the gate — let the safe one flow through, stop and get approval for the destructive one, and keep a rollback path ready in every case. The skill works with all common ORM/migration tools.
Crewforth adaptation (local, .claude/): Engine and tool come from
CLAUDE.md ## Stackor repo detection (backend-architecture).crew-database-expertapplies it; a destructive migration requires explicit approval (§4.5), commit/push with explicit approval (§4.4). Authorization/IDOR impact → crew-security-expert; personal-data retention → crew-privacy-agent. §4 Prohibitions apply.
Checklist
- Tool detected, pending migrations listed
- Every change classified (additive / destructive / ambiguous)
- Destructive/ambiguous changes approved by the user
- Backup taken (mandatory in prod, verified)
- Preview (dry-run) shown and approved
- Applied, schema verified post-apply
- Rollback path (tool or backup) ready
- Every migration has its down step, or says why it has none
- A new foreign key or unique constraint: the existing rows that break it were counted first
- The SQL an ORM generated was read: a rename it wrote as drop + add is destructive, never implicit
1. Detect the tool
Determine the tool from the file trace; if none is found, fall back to raw SQL mode (below); if several are found, ask the user.
| Trace | Tool |
|---|---|
prisma/schema.prisma |
Prisma |
knexfile.{js,ts} |
Knex |
.sequelizerc / config/config.json + models/ |
Sequelize |
data-source.ts (typeorm) / ormconfig.ts |
TypeORM |
drizzle.config.ts |
Drizzle |
alembic.ini / alembic/ |
Alembic |
manage.py + django dependency |
Django |
db/migrate/ + rails in Gemfile |
Rails |
Microsoft.EntityFrameworkCore in *.csproj + Migrations/ |
EF Core |
2. Classify the change — the heart of the flow
Extract the SQL to be applied (the "Preview" column in the matrix below) and place it into one of three classes:
| Class | Example operations | How it is handled |
|---|---|---|
| Additive (safe) | CREATE TABLE, nullable/defaulted ADD COLUMN, CREATE INDEX, non-destructive ADD CONSTRAINT, seed INSERT |
Proceed in the normal flow |
| Destructive (dangerous) | DROP TABLE/COLUMN/INDEX/CONSTRAINT, ALTER COLUMN … TYPE, TRUNCATE, DELETE without WHERE, RENAME (breaks references) |
Always the approval gate (below) |
| Ambiguous (human judgment) | ALTER COLUMN, ADD COLUMN NOT NULL without a default (blows up on a populated table), UPDATE, mixed migration |
Treat as destructive, warn and ask |
Approval gate (destructive/ambiguous): list the operations one by one, show the environment and the target, wait for explicit approval. Even if "run" was said in the general flow, this gate requires separate approval.
WARNING — this migration contains a destructive operation:
· DROP COLUMN "legacy_email" (table: users)
· ALTER COLUMN "status" TYPE integer (table: orders)
CANNOT BE UNDONE without a backup. Target: production (myapp_db @ db.example.com)
Continue? (yes / no)
If rejected, stop immediately and propose a safer path (e.g. a new column + background copy instead of changing the type).
Breaking change across deploys — expand/contract
A rolling deploy runs the old and the new code against ONE schema at the same time, and a rollback runs the old
code against the new schema. So a rename, a type change or a new NOT NULL on a live table is never one
migration. It is a sequence, each step its own release:
- Expand — additive only: the new column/table, nullable or defaulted. The old artefact must still run.
- Dual-write — the code writes both shapes; reads stay on the old one.
- Backfill in batches, outside the deploy, idempotent and resumable (never one
UPDATEover the table). - Switch reads to the new shape; keep writing both until the rollback window has passed.
- Contract — drop or rename the old shape in a LATER release, as its own migration through the approval gate above, approved separately: approving the expand does not approve the contract.
Build an index on a live table online (CREATE INDEX CONCURRENTLY on PostgreSQL, or the engine's equivalent); a
plain build locks writes. Each step with an example, and deprecating an API or a feature (warn → adapter →
removal, an
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- references/backup-restore.md
- references/expand-contract.md
- references/raw-sql.md
- references/tool-matrix.md
FAQ
Что делает скилл db-migration?
Apply schema migrations safely: detect the tool, classify the change by risk, gate destructive ones behind approval, back up in prod, preview-apply-verify, roll back on failure. Use when a schema change is about to be applied to any environment.
Как установить скилл db-migration?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл db-migration запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
AnthropicToolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
access
AnthropicManage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
configure
AnthropicSet up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
access
AnthropicManage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…