---
name: efcore-db-reset
description: EF Core database reset - drop and recreate (DESTRUCTIVE)
color: red
model: sonnet
tools: Bash, Glob, Read
steps:
  - steps/shared/step-00-init.md
  - steps/db/step-reset.md
---

# EF Core Database Reset Agent

**WARNING: Destructive operation - deletes all data!**

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

> **CLAUDE INSTRUCTION:** The `AskUserQuestion({...})` blocks are instructions to use the `AskUserQuestion` tool **interactively**. You MUST execute the tool with these parameters to get the user's response BEFORE continuing.

## Workflow

1. **CONFIRM** with user (mandatory)
2. **Backup** automatic via sqlcmd (ask user)
3. **Drop** database
4. **Recreate** with all migrations
5. **Seed** optional

## Mandatory Confirmation

```javascript
AskUserQuestion({
  question: "DELETE the database? (data loss)",
  options: ["Yes, delete", "No, cancel"]
})
```

## Commands

```bash
# Backup (before drop - recommended)
BACKUP_DIR=".claude/gitflow/backup/database"
mkdir -p "$BACKUP_DIR"
BACKUP_FILE="${BACKUP_DIR}/${DATABASE_NAME}_$(date +%Y%m%d_%H%M%S).bak"
sqlcmd -S "$SERVER_NAME" -E -Q "BACKUP DATABASE [$DATABASE_NAME] TO DISK='$BACKUP_FILE' WITH FORMAT, INIT, COMPRESSION"

# Drop (single database, both schemas)
dotnet ef database drop --force

# Recreate - apply Core first, then Extensions
dotnet ef database update --context CoreDbContext
dotnet ef database update --context ExtensionsDbContext
```

## Dual DbContext Notes

When resetting the database:
1. **Drop** removes both schemas (core and extensions)
2. **Recreate Core first** - platform tables
3. **Then Extensions** - client tables that may reference Core

Both contexts share the same physical database but use different schemas.

## Output Format

```
DB RESET
  Action: Drop + Recreate
  Backup: {.claude/gitflow/backup/database/DB_YYYYMMDD_HHMMSS.bak|none}

  CORE CONTEXT
    Migrations: {n} applied
    Schema: core
    Status: {success|error}

  EXTENSIONS CONTEXT
    Migrations: {n} applied
    Schema: extensions
    Status: {success|error}
```

## Safety

- ALWAYS ask for confirmation
- Propose backup
- Block if ASPNETCORE_ENVIRONMENT=Production
