---
name: step-seed
description: Populate database with test data
next_step: null
---

# Database Seed

## YOUR TASK:

Populate the database with test or initial data using EF Core conventions.

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

---

## COMPLIANCE:

| FORBIDDEN | REQUIRED |
|-----------|----------|
| SQL scripts in repo | `HasData()` in configurations |
| `sqlcmd` with INSERT | `IDataSeeder` classes |
| `migrationBuilder.Sql()` INSERT | EF Core typed migrations |

---

## EXECUTION SEQUENCE:

### 1. Environment Check

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

```bash
echo "Seed Configuration"
echo "=================="
echo ""
echo "DbContext:   $DBCONTEXT ($DBCONTEXT_TYPE)"
echo "Environment: $SELECTED_ENV"
echo "Database:    $DATABASE_NAME"

# Block production
block_production
```

### 2. Detect Available Seed Methods

Load: `references/seed-methods.md#detect-available-seed-methods`

### 3. Select Method

**If multiple methods available:**

```yaml
AskUserQuestion:
  header: "Seed"
  question: "Which seed method to use?"
  options:
    - label: "HasData (Recommended)"
      description: "Via EF Core migrations"
    - label: "Seeder Class"
      description: "Run DbSeeder/DataSeeder"
    - label: "CLI --seed"
      description: "Launch app with --seed"
  multiSelect: false
```

### 4. Execute Seed

Load execution methods from: `references/seed-methods.md#execute-seed-*`

- HasData: `references/seed-methods.md#execute-seed---hasdata`
- Seeder Class: `references/seed-methods.md#execute-seed---seeder-class`
- CLI Argument: `references/seed-methods.md#execute-seed---cli-argument`

### 5. Verify (Optional)

Load: `references/seed-methods.md#verify-seed-data`

### 6. Summary

```bash
echo ""
echo "==========================================="
echo "SEED COMPLETE"
echo "==========================================="
echo ""
echo "Database:    $DATABASE_NAME"
echo "Environment: $SELECTED_ENV"
echo "Method:      $SEED_METHOD"
echo ""
echo "Compliance:  EF Core native, No raw SQL"
echo ""
echo "==========================================="
echo ""
echo "Next steps:"
echo "  /efcore db-status    # Check status"
echo "  dotnet run           # Start application"
echo ""
```

---

## OUTPUT FORMAT:

```
SEED COMPLETE
=============
Database:    {database_name}
Environment: {env}
Method:      {hasdata | seeder-class | cli-argument}

Compliance:  EF Core native, No raw SQL

Next: /efcore db-status, dotnet run
```

---

## NO SEED METHODS FOUND:

Load: `references/troubleshooting.md#seed-setup-guide`

---

## MIGRATION FROM SQL:

Load: `references/troubleshooting.md#migration-from-sql`

---

## BOTH CONTEXTS:

If `RUN_BOTH=true` (auto-detected for client projects with SmartStack NuGet):

Run the seed sequence for both contexts, in order:

```bash
# 1. Seed CoreDbContext first (system data: Users, Roles, Permissions...)
echo "=== Seeding CoreDbContext (core schema) ==="
DBCONTEXT="CoreDbContext"
# Run steps 2-6 with CoreDbContext...

# 2. Then ExtensionsDbContext (client data)
echo ""
echo "=== Seeding ExtensionsDbContext (extensions schema) ==="
DBCONTEXT="ExtensionsDbContext"
# Run steps 2-6 with ExtensionsDbContext...
```

**Order matters:** Core MUST be seeded first (Extensions may reference Core data via foreign keys).

---

## OPTIONS:

| Option | Description |
|--------|-------------|
| `--env {name}` | Use appsettings.{name}.json |
| `--context {name}` | Specify DbContext |
| `--method {name}` | Force seed method (hasdata, seeder-class, cli-argument) |

---

## COMPLETION:

Seed data applied. Use `/efcore db-status` to verify.
