Skip to content
Back to skills

Add Migration

ASecurity

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.

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added October 19, 2026
developmentgobashapidatabase

Works with

  • api
  • mcp

Security analysis

A100/100

Scanned October 19, 2026

npx -y skills add andy-dendy-repo/govern --skill add-migration --agent claude-code

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.

Security grade badge for Add Migration
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/andy-dendy-repo-add-migration/badge)](https://www.skillsdirectory.com/skills/andy-dendy-repo-add-migration)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
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.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.