---
name: step-reset
description: Reset database - drop and recreate
next_step: null
---

# Database Reset

## YOUR TASK:

Completely reset the database: drop, recreate, and apply all migrations.

**WARNING:** This is DESTRUCTIVE. All data will be lost!

**Requires:** `steps/shared/step-00-init.md` completed

---

## COMPLIANCE:

| FORBIDDEN | REQUIRED |
|-----------|----------|
| `sqlcmd` for DDL/DML | `dotnet ef database drop` |
| SQL scripts in repo | `dotnet ef database update` |
| INSERT via scripts | `HasData()` for seeding |

**Exception:** `sqlcmd` allowed ONLY for `BACKUP DATABASE`.

---

## EXECUTION SEQUENCE:

### 1. Environment Check

Load validation: `references/database-operations.md#check-required-variables`

```bash
echo "Reset Configuration"
echo "==================="
echo ""
echo "DbContext:   $DBCONTEXT ($DBCONTEXT_TYPE)"
echo "Environment: $SELECTED_ENV"
echo "Database:    $DATABASE_NAME"
echo "Server:      $SERVER_NAME"
echo ""
echo "WARNING: ALL DATA WILL BE LOST!"

# Block production
block_production
```

### 2. Confirmation (MANDATORY)

```yaml
AskUserQuestion:
  header: "Reset DB"
  question: "DANGER: Permanently delete '{DATABASE_NAME}'?

ALL DATA WILL BE LOST!

This action is IRREVERSIBLE."
  options:
    - label: "Yes, delete {DATABASE_NAME}"
      description: "Drop + Recreate (IRREVERSIBLE)"
    - label: "No, cancel"
      description: "Keep database"
  multiSelect: false
```

### 3. Optional Backup

```yaml
AskUserQuestion:
  header: "Backup"
  question: "Backup database before deletion?"
  options:
    - label: "Yes, backup (Recommended)"
      description: "Create .bak via sqlcmd"
    - label: "No"
      description: "Dev data only - continue"
    - label: "Manual backup"
      description: "Via SSMS/Azure Portal (stops here)"
  multiSelect: false
```

**If backup requested:**

Load: `references/database-operations.md#backup-command`

### 4. Drop Database

Load: `references/reset-operations.md#drop-database`

### 5. Recreate + Apply Migrations

Load: `references/reset-operations.md#recreate--apply-migrations`

### 6. Optional Seed

```yaml
AskUserQuestion:
  header: "Seed"
  question: "Populate with test data (HasData)?"
  options:
    - label: "Yes (recommended)"
      description: "Apply HasData configurations"
    - label: "No"
      description: "Empty database"
  multiSelect: false
```

**If seed requested:**

```bash
echo ""
echo "Running seed..."

# HasData is already applied via migrations
# For custom seeding:
dotnet run --project "$STARTUP_PROJECT" -- --seed 2>/dev/null || echo "No --seed argument supported"
```

### 7. Summary

Load: `references/reset-operations.md#summary-after-reset`

---

## OUTPUT FORMAT:

```
RESET COMPLETE
==============
Database:    {database_name}
Environment: {env}
DbContext:   {dbcontext}

Operations:
  - Drop: OK
  - Create: OK
  - Migrations: {N} applied
  - Backup: {path | none}

Compliance:  EF Core CLI only

Next: /efcore db-status, /efcore db-seed
```

---

## PROTECTIONS:

Load: `references/troubleshooting.md#reset-protections`

---

## BOTH CONTEXTS:

If "Both" selected:

```bash
# Drop + Recreate CoreDbContext
DBCONTEXT="CoreDbContext"
# ... execute reset ...

# Then ExtensionsDbContext
DBCONTEXT="ExtensionsDbContext"
# ... execute reset ...
```

---

## OPTIONS:

| Option | Description |
|--------|-------------|
| `--env {name}` | Use appsettings.{name}.json |
| `--no-backup` | Skip backup step |
| `--context {name}` | Specify DbContext |
| `--seed` | Auto-seed after reset |

---

## COMPLETION:

Database reset complete. Fresh state with all migrations applied.
