Add a database migration
Schema changes are high-risk: they can lock tables, drop data, or break running code.
Produce a reversible migration that follows the repo's tooling — and escalate when a
human decision is needed.
Steps
- Read the lore first. Call
search_lore (Memory MCP) for migration
conventions: the tool (Flyway/Liquibase/Alembic/Prisma/Knex/…), naming/numbering,
whether migrations must be backward-compatible with running code, and any ADR on
zero-downtime changes.
- Assess the risk. If the change is destructive (drop column/table, narrow a type,
non-nullable add without default), rewrites a large table, or could cause downtime or
data loss — stop and call
mark_ticket_blocked with the specifics. A human decides.
- Write a reversible migration using the repo's generator. Provide both up and down
(or an explicit, justified note when a true rollback is impossible). Prefer additive,
backward-compatible steps; split risky changes into expand → migrate → contract phases.
- Make it safe at scale. Add indexes concurrently where the engine supports it; add
columns nullable or with a default; backfill in batches, not one statement.
- Apply it against a test/dev database (the context packet's DB; never production)
and confirm it runs forward and rolls back cleanly. Add/adjust tests for the new schema.
- Run tests (
run-tests). Evidence the migration file, the apply+rollback output,
and test results, then use the record-evidence skill and submit for review.
Rules
- Every migration must be reversible, or carry an explicit reason it cannot be.
- Destructive or downtime-risking changes →
mark_ticket_blocked; do not decide alone.
- Never run migrations against production; use the test/dev DB from the packet.
- Don't install DB tooling or write secret/
.env files — the hook blocks both.
- Run on a branch (the
create-branch skill), never a protected branch.
Capture lore
This skill is one of the places durable, reusable knowledge naturally surfaces:
A schema decision or migration constraint future agents must respect — a naming convention, a reversibility rule, or a modelling choice with downstream impact. That kind of fact is lore. Capture it via the lore-capture
protocol in your brief (CLAUDE.factory.md, step 11 "Memory contribution"):
call the Memory MCP suggest_lore once at the close of your work — reusable
conventions, gotchas, decisions, and boundaries only, never per-ticket trivia.
1---2name: add-db-migration3description: Use when a ticket requires a database schema change — a new table/column, an index, a constraint, or a backfill. Invoke for "add a migration for X", "alter the schema", or any change to the persisted data model. Schema changes are high-risk; treat them carefully.4---56# Add a database migration78Schema changes are high-risk: they can lock tables, drop data, or break running code.9Produce a reversible migration that follows the repo's tooling — and escalate when a10human decision is needed.1112## Steps13141. **Read the lore first.** Call `search_lore` (Memory MCP) for migration15 conventions: the tool (Flyway/Liquibase/Alembic/Prisma/Knex/…), naming/numbering,16 whether migrations must be backward-compatible with running code, and any ADR on17 zero-downtime changes.182. **Assess the risk.** If the change is destructive (drop column/table, narrow a type,19 non-nullable add without default), rewrites a large table, or could cause downtime or20 data loss — stop and call `mark_ticket_blocked` with the specifics. A human decides.213. **Write a reversible migration** using the repo's generator. Provide both up and down22 (or an explicit, justified note when a true rollback is impossible). Prefer additive,23 backward-compatible steps; split risky changes into expand → migrate → contract phases.244. **Make it safe at scale.** Add indexes concurrently where the engine supports it; add25 columns nullable or with a default; backfill in batches, not one statement.265. **Apply it against a test/dev database** (the context packet's DB; never production)27 and confirm it runs forward and rolls back cleanly. Add/adjust tests for the new schema.286. **Run tests** (`run-tests`). Evidence the migration file, the apply+rollback output,29 and test results, then use the `record-evidence` skill and submit for review.3031## Rules3233- Every migration must be reversible, or carry an explicit reason it cannot be.34- Destructive or downtime-risking changes → `mark_ticket_blocked`; do not decide alone.35- Never run migrations against production; use the test/dev DB from the packet.36- Don't install DB tooling or write secret/`.env` files — the hook blocks both.37- Run on a branch (the `create-branch` skill), never a protected branch.3839## Capture lore4041This skill is one of the places durable, reusable knowledge naturally surfaces:42**A schema decision or migration constraint future agents must respect — a naming convention, a reversibility rule, or a modelling choice with downstream impact.** That kind of fact is *lore*. Capture it via the **lore-capture43protocol in your brief** (`CLAUDE.factory.md`, step 11 "Memory contribution"):44call the Memory MCP `suggest_lore` once at the close of your work — reusable45conventions, gotchas, decisions, and boundaries only, never per-ticket trivia.