---
description: Plan and apply a safe database migration.
argument-hint: <migration-name>
---

# /db-migrate

## Purpose

Create a reviewable, reversible schema change across Prisma + EF + SQL Server mirror.

## Required context

- `docs/runbooks/db-migrations.md`, `prisma/schema.prisma`, `dotnet/src/Infrastructure/Persistence/`

## Inputs

- `$1` — migration name (kebab-case)

## Execution steps

1. Edit `prisma/schema.prisma`. Run `pnpm db:migrate` (asks first — it's an `ask` permission).
2. Mirror EF entities + configs in `dotnet/`; `dotnet build`.
3. Mirror SQL in `database/migrations/000N_<name>.sql`.
4. For destructive changes, follow expand→contract over two deploys.

## Validation checklist

- [ ] Migration committed under `prisma/migrations/`
- [ ] EF + SQL Server mirror updated
- [ ] Breaking changes use the two-deploy path
- [ ] `dotnet build` + `pnpm validate` pass

## Expected output

A committed, reversible migration in all three places.

## Failure handling

Never edit an applied migration. Roll forward with a new one.
