create-migration

Create and apply EF Core migrations for module-specific DbContexts.

6.7k|2.0k|Updated Aug 20, 2021
One-click install
npx skills add https://github.com/fullstackhero/dotnet-starter-kit --skill create-migration-fullstackhero
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: create-migration
Source: https://github.com/fullstackhero/dotnet-starter-kit/tree/main/.agents/skills/create-migration
Command: npx skills add https://github.com/fullstackhero/dotnet-starter-kit --skill create-migration-fullstackhero

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It prevents broken or missing database changes when you modify EF Core entities by ensuring migrations are generated from the correct, freshly-built model snapshot and applied through the project’s dedicated migration pipeline.

Core Features & Use Cases

  • Centralized, per-module migrations: Writes migrations into a single migrations project, organized by module/context folders (e.g., Catalog/, Identity/).
  • Correct migration context targeting: Uses the right --context {X}DbContext and outputs to the matching module folder with --output-dir {X}.
  • Safety-first workflow: Encourages building before migrations add, generating idempotent SQL for review, and applying via the DbMigrator (not API startup).
  • Typical use case: You change an entity or EF configuration in a module and need a new migration that updates only the relevant module’s schema in a multi-tenant setup.

Quick Start

Run the migration creation command for your module’s DbContext, ensuring you use the Migrations project, the API host as startup project, the correct --context {X}DbContext, and --output-dir {X} to place the migration in the right folder.

Frequently Asked Questions about create-migration

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I generate EF Core migrations for a specific module DbContext without creating stale model snapshots?

To generate EF Core migrations safely, first build the solution, then run the migration command targeting the specific module DbContext using the correct --context parameter and --output-dir to place files in the matching module folder.

Why does my EF Core migration update the wrong schema in a multi-tenant PostgreSQL setup?

Multi-tenant schema corruption occurs when migrations are generated from a stale model snapshot. You must build the solution first, explicitly specify the correct module DbContext, and output the migration to the proper module directory.

What is the safest workflow for applying EF Core migrations in a vertical slice architecture?

The safest EF Core migration workflow involves building the project, adding the migration to the correct module folder, generating idempotent SQL for review, and applying changes via the DbMigrator rather than the API startup project.

Can I apply EF Core database migrations directly through the API startup project?

Applying migrations through the API startup project is not recommended. You should use the dedicated DbMigrator pipeline to apply module-specific migrations, ensuring safe updates across multi-tenant schemas without startup conflicts.

How do I organize EF Core migrations when working with multiple module-specific DbContexts?

Organize EF Core migrations by writing them into a single centralized migrations project using module-specific folders. Use the --context parameter to target the correct DbContext and --output-dir to place the migration in the matching module directory.

Does the FSH EF Core migration approach support generating SQL scripts for review?

Yes, the FSH migration approach supports generating idempotent SQL scripts for review. After adding the migration to the correct module folder, you can script the SQL to verify database changes before applying them through the DbMigrator.