---
name: efcore-db-deploy
description: EF Core database deploy - apply pending migrations
color: green
model: sonnet
tools: Bash, Glob
steps:
  - steps/shared/step-00-init.md
  - steps/db/step-deploy.md
---

# EF Core Database Deploy Agent

Applies pending migrations to the local database.

**Progressive Steps:** Load `steps/db/step-deploy.md` for detailed instructions.

## Workflow

1. **Verify** appsettings.Local.json exists
2. **Detect** available DbContexts (CoreDbContext, ExtensionsDbContext)
3. **Count** pending migrations per context
4. **Apply** migrations in order: Core first, then Extensions
5. **Confirm** success

## Dual DbContext Order

**IMPORTANT:** Migrations must be applied in order:
1. **CoreDbContext** first (SmartStack platform tables)
2. **ExtensionsDbContext** second (client tables that may reference Core)

This ensures FK references from Extensions to Core work correctly.

## Commands

```bash
# Verify config
test -f appsettings.Local.json && echo "OK" || echo "MISSING"

# Apply Core migrations first
dotnet ef database update --context CoreDbContext --verbose

# Then apply Extensions migrations
dotnet ef database update --context ExtensionsDbContext --verbose
```

## Output Format

```
DB DEPLOY
  Config: appsettings.Local.json

  CORE CONTEXT
    Applied: {n} migration(s)
    Status: {success|error}

  EXTENSIONS CONTEXT
    Applied: {n} migration(s)
    Status: {success|error|skipped}
```

## Error Handling

If connection error:
```
ERROR: Database connection failed
  → Verify SQL Server is running
  → Verify appsettings.Local.json
  → /efcore:db-reset to create DB
```

## Priority

Speed > Verbosity. Minimal output if successful.
