Creates, reviews and verifies an EF Core migration for Govern after model changes (entities or configurations). Use when the EF model changed, the user asks for a migration, or tests fail with pending model changes.
Installs into .claude/skills of the current project.
Are you the author of Add Migration?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/andy-dendy-repo-add-migration)
---
name: add-migration
description: >
Creates, reviews and verifies an EF Core migration for Govern after model changes (entities or configurations).
Use when the EF model changed, the user asks for a migration, or tests fail with pending model changes.
---
# Add a migration
## 1. Generate
Name the migration in PascalCase after what it does (`AddOrders`, `AddUserDisplayName`). No database connection is needed, but the host must build:
```bash
dotnet tool restore
ConnectionStrings__Govern="Host=localhost;Database=govern;Username=postgres;Password=unused" \
Jwt__SigningKey="design-time-only-key-not-a-secret-000000" \
dotnet ef migrations add <Name> --project src/Govern.Infrastructure --startup-project src/Govern.Api --output-dir Persistence/Migrations
```
If user-secrets are configured for `src/Govern.Api`, the environment variables are not needed.
## 2. Review the generated `Up`/`Down`
- **Data loss:** `DropColumn` or `DropTable` where you meant a rename. Fix the model (EF can't guess renames): remove the migration and hand the rename to EF with `RenameColumn` in a fresh migration only when necessary. Never edit the `*.Designer.cs` or the snapshot (a hook blocks it).
- **New non-nullable columns on existing tables:** need a default or a backfill.
- **Checks:**
- indexes for new foreign keys and unique business keys
- `Down` reverses `Up`
- snake_case names generated by convention, not hard-coded
- **Undo a wrong migration:** `dotnet ef migrations remove --project src/Govern.Infrastructure --startup-project src/Govern.Api`. This only works while it hasn't been applied anywhere shared.
## 3. Verify
- `dotnet build Govern.slnx`.
- `dotnet test Govern.slnx`. Integration tests apply all migrations to a fresh Postgres container at startup, so a broken migration fails there.
- Optionally apply to the local database: run the Api (it migrates on startup) and inspect with the `postgres` MCP, read-only.
- For non-trivial schema changes, run the `ef-core-specialist` agent.
## 4. Deploy note
Production applies migrations at startup (`DatabaseMigrationService`). For destructive or long-running changes, plan an expand/contract sequence across releases and document it in the PR.