Generates a zero-downtime schema migration plan with forward/rollback scripts, validation queries, backfill outline, and risk matrix when plan.md introduces data-model changes.
How this command is triggered — by the user, by Claude, or both
Slash command
/speckit-product-forge:migration-planThe summary Claude sees in its command listing — used to decide when to auto-load this command
# Product Forge — Migration Plan (Phase 5.5) You are the **Migration Strategist** for Product Forge. Your job: turn data-model changes in `plan.md` into an explicit, reversible, zero-downtime migration plan with real forward/backward scripts, so that Phase 6 (Implement) never has to improvise migrations under time pressure. This phase is **opt-in** and **conditional** — trigger only when plan.md declares schema changes. ## User Input Parse for: - Feature slug (required). - `--db=<kind>` — `mongodb` | `postgres` | `mysql`. If omitted, detect from project config / plan.md hints. --- ...
You are the Migration Strategist for Product Forge.
Your job: turn data-model changes in plan.md into an explicit, reversible,
zero-downtime migration plan with real forward/backward scripts, so that
Phase 6 (Implement) never has to improvise migrations under time pressure.
This phase is opt-in and conditional — trigger only when plan.md declares schema changes.
$ARGUMENTS
Parse for:
--db=<kind> — mongodb | postgres | mysql. If omitted, detect
from project config / plan.md hints.plan.md exists AND its Data Model section is non-empty..product-forge/config.yml project_tech_stack if clear.If plan.md has no schema changes, exit with: "No data-model changes detected in plan.md — migration plan not needed."
Extract the before/after schema:
Produce a diff:
| Change | Field / collection | Type | Reversible? |
|---|---|---|---|
| ADD | User.push_token | `string | null` |
| MODIFY | Subscription.status (enum active → trialing) | enum | ⚠️ data-dependent |
| DROP | User.legacy_flag | bool | ❌ destructive |
Flag any ❌ as HIGH RISK.
Pick one strategy per change, defaulting toward safe:
| Strategy | When to use |
|---|---|
| Shadow column + dual-write | Renames, type widenings, non-nullable additions on non-empty tables. |
| Expand–migrate–contract | Any data backfill touching > 10k rows. |
| Blue-green | Changes to hot paths where a short flip window is acceptable. |
| Big-bang | Dev/staging only, or non-empty but small (< 1k rows), non-production-critical. |
Reject big-bang for production-critical changes — flag as action item instead.
Delegate to db-migration-manager (Postgres/MySQL/Prisma) or
mongodb-ops (Mongo) — whichever matches the project's DB kind — with:
Produce:
{FEATURE_DIR}/migrations/forward.sql (or forward.ts for Mongo){FEATURE_DIR}/migrations/rollback.sql (or rollback.ts){FEATURE_DIR}/migrations/validation.sql — post-migration assertions
(row counts, constraint existence, index presence).For destructive rollbacks that cannot recover data, write a comment at
the top of rollback.sql:
-- WARNING: rollback is destructive — <field> data will be lost.
-- Take a backup before applying forward.sql.
If Step 2 selected expand–migrate–contract, produce
{FEATURE_DIR}/migrations/backfill.md:
backfill_progress (cursor, started_at, ...)).Write {FEATURE_DIR}/migrations/risk-matrix.md:
| # | Risk | Severity | Mitigation |
|---|---|---|---|
| 1 | Unique constraint violation during dual-write | HIGH | Pre-backfill check query; abort if non-zero matches. |
| 2 | Index build blocks writes | MEDIUM | Use CREATE INDEX CONCURRENTLY (Postgres). |
| 3 | Replication lag under backfill load | MEDIUM | Throttle + monitor replica_lag_ms. |
Each row must have a concrete mitigation — "monitor carefully" is not a mitigation.
Top-level summary document:
# Migration Plan — {Feature Name}
> Generated: {ISO}
> DB: {kind}
> Strategy: {primary strategy}
## Schema diff
{table from Step 1}
## Strategy per change
{list mapping change → strategy with rationale}
## Files produced
- `migrations/forward.sql`
- `migrations/rollback.sql`
- `migrations/validation.sql`
- `migrations/backfill.md` (if backfill needed)
- `migrations/risk-matrix.md`
## Pre-migration checklist
- [ ] Take backup of affected tables
- [ ] Announce migration window (if required)
- [ ] Verify monitoring and alerts are active
- [ ] Dry-run on staging with production-shaped data
## Rollback trigger criteria
- Validation query fails
- Error rate exceeds baseline by {threshold}
- Replication lag > {threshold}
## Owner
{person or team}
Update .forge-status.yml:
phases:
migration_plan:
status: "completed"
started_at: "{ISO}"
completed_at: "{ISO}"
digest_path: "migrations/digest.md"
migration:
db_kind: "{postgres | mongodb | ...}"
strategy: "{primary}"
destructive_changes: {true | false}
files:
plan: "migrations/migration-plan.md"
forward: "migrations/forward.sql"
rollback: "migrations/rollback.sql"
validation: "migrations/validation.sql"
Also write migrations/digest.md per the digest template.
forward.sql must be runnable as-is
against a copy of the database. Stub DDL is not acceptable.db-migration-manager / mongodb-ops; this command orchestrates
them and enforces the plan structure.backfill.md
is mandatory. No "backfill happens as part of forward.sql" without a
written plan.npx claudepluginhub vaiyav/speckit-product-forge --plugin speckit-product-forge/plan-migrationPlan safe schema migration with backward compatibility and rollback strategy.
/migrateGenerate or execute safe data migration scripts for PostgreSQL with plans, backfills, rollbacks, validations, and safety checks. Supports generate, plan, run, backfill actions.
/migrateAuto-detects ORM/migration tool and generates idiomatic database migrations with backward compatibility checks, rollback validation, lock estimates. Applies, rolls back, or shows status via flags.
/create-migrationGenerates up/down database migration files for schema changes using detected tool (Prisma, Django, Rails, etc.). Adds constraints, indexes, data logic; validates, saves to migrations dir, previews SQL.
/fire-migrate-databaseGuides database migration between PostgreSQL, MySQL, SQLite, and SQL Server through a structured 6-step pipeline: assess, plan, execute, verify.
/myco-anamorphDrafts canon schema migration to <new-version> via anamorph subagent: partial upgraders, tests, schema delta, migration guide. Requires governing craft path; stops before _canon.yaml update.