/crewforth:db-migrationfrom Crewforth
Applies schema migrations safely by detecting the migration tool, classifying changes by risk (additive/destructive/ambiguous), gating destructive operations behind user approval, backing up in production, and providing a preview-apply-verify-rollback workflow.
Ships in Crewforth. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
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.
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 |
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).
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:
UPDATE over the table).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, and deleting the code nobody calls any more): references/expand-contract.md.
Back up before any migration; it cannot be skipped in prod, and can be skipped in dev with approval. Then verify the backup was created and is not empty — otherwise abort:
[ -s "$BACKUP_FILE" ] || { echo "ERROR: Backup empty/not created — migration aborted."; exit 1; }
Backup + restore + post-apply verify commands per engine (PostgreSQL · MySQL · SQLite):
references/backup-restore.md — read the one for your database, not all three.
Once classification and backup are complete: Preview → (approval) → Apply → Verify.
Per-tool commands for those four steps and for rollback — Prisma, Knex, Sequelize, TypeORM, Drizzle, Alembic, Django, Rails, EF Core: references/tool-matrix.md. Look up the one the project uses.
Rules: Always show the preview before applying and get it approved (if the tool does not support a dry-run, treat the migration file itself as the preview). A destructive migration is not applied without passing the approval gate (§2). Show the full apply output; if there is an error, roll back.
Additional post-apply verification — compare against the expected schema using your engine's inspect command (references/backup-restore.md).
First the tool-specific rollback (last column of the matrix); if that fails, restore from the backup (per-engine
restore command in references/backup-restore.md); then re-verify. If neither works, warn the user with the full error detail.
If no tool is detected, manage numbered up/down files (every up has a down, each SQL inside BEGIN/COMMIT)
with a _migrations tracking table. Full pattern + example + the apply loop: references/raw-sql.md.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Prisma, Drizzle, SQLAlchemy, Django, Rails, TypeORM, PostgreSQL, MySQL
npx claudepluginhub crewforth/crewforth --plugin crewforth60 skills in this plugin
/a11yUse when building or changing UI, before shipping a user-facing screen, and when something cannot be
reached with a keyboard, read by a screen reader, or seen at low contrast.
/adrArchitecture Decision Record: context-decision-consequences, for decisions that are expensive to reverse.
Written under docs/adr/.
/api-designUse when an API contract is designed or changed: a new endpoint or resource, how its errors and pages
are returned, a field to add or remove, or a version to cut without breaking a consumer.
/automode-policyAuto-mode classifier config: inspect what the classifier that answers permission prompts is configured
with, and catch the silent case where a custom autoMode block drops the built-in block rules.
/backend-architectureDecide, record and apply the backend stack and architecture pattern.
Use when backend work starts with no recorded stack, or a framework/DB/pattern must be chosen.
/brainstormUse when the ask is still fuzzy and no direction is chosen yet: "not sure what we want", several ways to go,
or a scope to settle before any plan is written.
Other plugins' skills for the same job