add-migration
Generate a new EF Core migration for Skoleoverblikket. USE THIS SKILL when the user says 'add migration', 'create migration', 'generate migration', 'ef migration', or after model/entity changes that n
SKILL.md.claude/skills/add-migration/SKILL.md
GitHubAdd Migration Skill
Generates a new EF Core migration and verifies the result.
Project paths
- API project:
api/Skoleoverblikket.Api/Skoleoverblikket.Api.csproj - Migrations folder:
api/Skoleoverblikket.Api/Data/Migrations/ - DbContext:
AppDbContextinapi/Skoleoverblikket.Api/Data/
Steps
1. Confirm migration name
If the user did not provide a name, ask for one. Migration names must be PascalCase and describe the schema change — e.g. Add_Course_Category, Remove_Staff_Slug, Add_SchemaDateRange.
2. Run the migration script
Always use the repo script — it adds the migration AND regenerates migration_script.sql atomically:
.\scripts\add-migration.ps1 -MigrationName <MigrationName>
Never call dotnet ef directly for this task. The script handles both steps and exits non-zero on failure.
3. Verify output
After the script succeeds, check that:
- Two new files exist:
<timestamp>_<Name>.csand<timestamp>_<Name>.Designer.cs AppDbContextModelSnapshot.cswas updatedmigration_script.sqlcontains the new migration ID at the bottom- The migration
Up()method contains the expected SQL operations — read it and confirm with the user if the changes look unexpected
4. Build to confirm no compile errors
dotnet build api/Skoleoverblikket.Api/Skoleoverblikket.Api.csproj --configuration Release
Rules
- Never modify an existing migration file — if a migration needs changing, add a new one
- Never run
dotnet ef database updatein CI or production — migrations are applied viamigration_script.sqlin the CI pipeline - If the migration is empty (no
Up()body), the model change was not registered — check that the entity has a correspondingIEntityTypeConfiguration<T>and is picked up byApplyConfigurationsFromAssembly - If
dotnet efis not installed, run:dotnet tool install --global dotnet-ef