# Agent — Create a new migration

Read `_shared.md` first.

## Goal

Scaffold a new EF Core migration against the correct DbContext, with a name
that follows the SmartStack convention. Every migration belongs to one
feature — do not mix concerns.

## Inputs

- `cwd` — worktree path.
- `contextName` — the target DbContext. Pick it from `list` output if not
  known; confirm with the user when multiple contexts are available.
- `description` — short, intent-revealing summary in PascalCase or free
  prose. The CLI normalizes it (`add employee avatar` → `AddEmployeeAvatar`).

Optional:

- `version` — override the `v{version}` segment when the auto-resolved value
  (csproj, or nearest `Directory.Build.props` for centrally-versioned repos)
  lags the branch's working line — e.g. props say `3.55.0` while the migration
  history is already on `3.56.0`. Align with the PREVIOUS migration's version;
  prefix, sequence and description stay computed by the convention.
- `assembly` — when the context has multiple migration assemblies (Studio
  Sqlite / Postgres / SqlServer), you can target a single one.
- `allProviders` — default `true` for multi-assembly contexts; runs the
  migration add in every assembly.
- `dryRun` — produces the computed name and command without touching the
  worktree.

## Steps

1. Invoke the CLI — always pass `dryRun: true` first to preview the name:

   ```bash
   npx --prefer-offline tsx skills/efcore/cli/create/index.ts --spec '{
     "cwd": "<WORKTREE>",
     "contextName": "CoreDbContext",
     "description": "AddEmployeeAvatar",
     "dryRun": true
   }'
   ```

2. Show the proposed name to the user. Confirm before re-running without
   `dryRun`.

3. Invoke the real create:

   ```bash
   npx --prefer-offline tsx skills/efcore/cli/create/index.ts --spec '{
     "cwd": "<WORKTREE>",
     "contextName": "CoreDbContext",
     "description": "AddEmployeeAvatar"
   }'
   ```

4. Read the output. For each assembly, the result contains:
   - `success`
   - `migrationName`
   - `filesCreated` (three paths: `.cs`, `.Designer.cs`, snapshot)
   - `sqlObjectsInlined` — SQL objects (`schema.name`) frozen into this
     migration from the project's `SqlObjects/` folder (see `_shared.md` §8).
     When non-empty, tell the user which functions/views/procs were embedded
     so `database update` deploys them; an empty list just means none were new
     or changed.

5. Remind the user to `dotnet build` the solution and to review the
   generated migration Up/Down methods before committing. If
   `sqlObjectsInlined` is non-empty, the review should include the appended
   `migrationBuilder.Sql(@"…")` block(s) at the end of `Up()`.

## What NOT to do

- Never run `dotnet ef migrations add` directly — always go through the
  CLI so naming stays consistent.
- Never bundle two unrelated changes into one migration. One feature =
  one migration.
- Never edit the generated `.cs` file to rename the migration — redo it
  via the CLI if the name is wrong.
