# Database Reset Operations

## Drop Database

```bash
echo ""
echo "Dropping database..."

dotnet ef database drop \
  --context "$DBCONTEXT" \
  --project "$INFRA_PROJECT" \
  --startup-project "$STARTUP_PROJECT" \
  --force
EXIT_CODE=$?

if [ $EXIT_CODE -ne 0 ]; then
  echo "ERROR: Drop failed (exit code: $EXIT_CODE)"
  echo "Database may be in use. Close connections and retry."
  exit 1
fi

echo "Database dropped."
```

## Recreate + Apply Migrations

```bash
echo ""
echo "Recreating database with migrations..."

dotnet ef database update \
  --context "$DBCONTEXT" \
  --project "$INFRA_PROJECT" \
  --startup-project "$STARTUP_PROJECT" \
  --verbose
EXIT_CODE=$?

if [ $EXIT_CODE -ne 0 ]; then
  echo ""
  echo "ERROR: Recreation failed (exit code: $EXIT_CODE)"
  exit 1
fi

echo "Database recreated."
```

## Summary After Reset

```bash
MIGRATION_COUNT=$(dotnet ef migrations list \
  --context "$DBCONTEXT" \
  --project "$INFRA_PROJECT" \
  --startup-project "$STARTUP_PROJECT" 2>/dev/null | \
  grep -c "^[0-9]" || echo "0")

echo ""
echo "==========================================="
echo "RESET COMPLETE"
echo "==========================================="
echo ""
echo "Database:    $DATABASE_NAME"
echo "Environment: $SELECTED_ENV"
echo "DbContext:   $DBCONTEXT"
echo ""
echo "Operations:"
echo "  - Drop: OK"
echo "  - Create: OK"
echo "  - Migrations: $MIGRATION_COUNT applied"
if [ -n "$BACKUP_FILE" ]; then
echo "  - Backup: $BACKUP_FILE"
fi
echo ""
echo "Compliance:  EF Core CLI only"
echo ""
echo "==========================================="
echo ""
echo "Next steps:"
echo "  /efcore db-status    # Verify status"
echo "  /efcore db-seed      # Add test data"
echo ""
```
