---
name: efcore
description: EF Core Commands - Migration and database management
argument-hint: "<command> [options]"
disable-model-invocation: true
---

## Current state (auto-injected)
- Preflight: !`if [ -f .git ] && grep -q '^gitdir: [A-Za-z]:' .git 2>/dev/null && grep -qi microsoft /proc/version 2>/dev/null; then p=$(sed 's/^gitdir: //' .git | tr -d '\r\n'); d=$(echo "${p:0:1}" | tr A-Z a-z); r="${p:2}"; r="${r//\\//}"; printf 'gitdir: %s\n' "$(realpath -m --relative-to="$(pwd)" "/mnt/$d$r")" > .git && echo "repaired"; else echo "ok"; fi`
- Branch: !`git branch --show-current 2>/dev/null || echo "UNAVAILABLE"`

<objective>
Manage EF Core migrations and database operations. **ALWAYS delegate to Task agents** for fast execution.
</objective>

<quick_start>
**Database operations:**
```bash
/efcore db-status          # Check migration status
/efcore db-deploy          # Apply pending migrations
/efcore db-reset           # Drop + recreate database
/efcore db-seed            # Populate with test data
```

**Migration operations:**
```bash
/efcore migration          # Create migration for current branch
/efcore squash             # Consolidate branch migrations
/efcore rebase-snapshot    # Sync snapshot with parent branch
/efcore scan               # Scan for cross-branch conflicts
/efcore conflicts          # Analyze migration conflicts
```
</quick_start>

<flags>
| Flag | Description |
|------|-------------|
| `--context <name>` | Specify DbContext (CoreDbContext/ExtensionsDbContext) |
| `--force` | Skip confirmations |
</flags>

<entry_point>

**ROUTING: ALWAYS delegate to Task agent. Never execute inline.**

Parse the command from `$ARGUMENTS` and delegate to the matching agent:

| Command | Task Agent (`subagent_type`) | Model | Description |
|---------|----------------------------|-------|-------------|
| `db-status` | `efcore-db-status` | haiku | Fast migration state check |
| `db-deploy` | `efcore-db-deploy` | haiku | Apply pending migrations |
| `db-reset` | `efcore-db-reset` | haiku | Drop + recreate database |
| `db-seed` | `efcore-db-seed` | haiku | Populate with test data |
| `migration` | `efcore-migration` | sonnet | Create/recreate migration (MCP) |
| `squash` | `efcore-squash` | sonnet | Consolidate migrations (MCP) |
| `rebase-snapshot` | `efcore-rebase-snapshot` | sonnet | Sync snapshot with parent (MCP) |
| `scan` | `efcore-scan` | haiku | Cross-branch conflict scan |
| `conflicts` | `efcore-conflicts` | haiku | Conflict analysis |

**Delegation template:**

```
Task(
  subagent_type: "{agent_name}",
  prompt: "Execute /efcore {command} in {cwd}. Branch: {branch}. Flags: {flags}",
  mode: "bypassPermissions"
)
```

**Pass to agent prompt:**
- Current working directory (absolute path)
- Current branch name
- Any flags (--context, --force)
- User's description (for migration command)

</entry_point>

<dual_dbcontext>
SmartStack uses **two separate DbContexts**:

| Context | DbContext | Schema | History Table |
|---------|-----------|--------|---------------|
| `core` | `CoreDbContext` | `core` | `core.__EFMigrationsHistory` |
| `extensions` | `ExtensionsDbContext` | `extensions` | `extensions.__EFMigrationsHistory` |
</dual_dbcontext>

<naming_convention>
**Migration naming (MCP MANDATORY):**

Pattern: `{context}_v{version}_{sequence}_{Description}`

**FORBIDDEN:** Manual name calculation. Always use `mcp__smartstack__suggest_migration`.
</naming_convention>

<safety_rules>
1. **Backup MANDATORY** for destructive operations (db-reset, squash)
2. **Production BLOCKED** - Never run on production
3. **1 migration per feature** - Recreate, don't accumulate
4. **MCP for naming** - Never hardcode migration names
</safety_rules>
