agentleFS
joaoguimaraesprojoaoguimaraespro/personal-finance/.agents/skills/dotnet-ef-migration/SKILL.md

dotnet-ef-migration

Skill1 starsChanged todayMITView on GitHub

Create, review, list, remove or script an EF Core migration for one module of a .NET modular monolith (one DbContext per module). Use after changing an entity or its configuration, or when asked to add a migration.

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 3 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Never write or edit migration files by hand.

    line 12
  2. Very specific:

    If the context name is ambiguous across modules, pass the fully qualified name (<Module>.Infrastructure.Database.<Module>DbContext).

    line 25
  3. Distinctive:

    only this module's schema is touched.

    line 28
  4. Very specific:

    no unintended drops or renames (EF turns a rename into drop + add unless told: use RenameColumn/RenameTable).

    line 29
  5. Distinctive:

    Commit the model change and the migration together.

    line 34

≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

EF Core migration for a module

Inputs: the migration name (PascalCase, says what changed) and the module. Find the paths from the repo first: <Module>.Infrastructure project, the startup (host) project, and the <Module>DbContext class. Read the repo's AGENTS.md/CLAUDE.md: if it names another output folder or command, use that.

Never write or edit migration files by hand; the tool generates them.

Steps

  1. Model change complete (entity, IEntityTypeConfiguration<T>, DbSet if new). dotnet build passes.
  2. Generate:
    dotnet ef migrations add <Name> \
      --project src/Modules/<Module>/<Module>.Infrastructure/<Module>.Infrastructure.csproj \
      --startup-project src/<Host>/<Host>.csproj \
      --context <Module>DbContext \
      --output-dir Database/Migrations
    If the context name is ambiguous across modules, pass the fully qualified name (<Module>.Infrastructure.Database.<Module>DbContext).
  3. Review the generated Up() and Down():
    • only this module's schema is touched;
    • no unintended drops or renames (EF turns a rename into drop + add unless told: use RenameColumn/RenameTable);
    • indexes and unique constraints include the tenant column when the table is tenant-scoped;
    • data backfills (migrationBuilder.Sql(...)) are idempotent and parameter-free.
  4. Apply locally: dotnet ef database update --project ... --startup-project ... --context <Module>DbContext (or the repo's own startup migration step). Run the tests.
  5. Commit the model change and the migration together.

Other commands (same --project/--startup-project/--context)

NeedCommand
Undo the last, unapplied migrationdotnet ef migrations remove ...
Listdotnet ef migrations list ...
Deployment scriptdotnet ef migrations script --idempotent --output <Name>.sql ...

Naming

Add<X>Table, Add<Column>To<Table>, Add<X>Index, Add<X>Relation, Remove<X>, Rename<X>To<Y>, Backfill<X>.

Troubleshooting

  • "No DbContext was found": the context is not registered by the module's DependencyInjection, or the startup project does not reference the module.
  • "More than one DbContext": pass --context.
  • Pending model changes after generating: something else changed the model; build and diff again.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.