---
name: step-status
description: Display migrations and database status
next_step: null
---

# Database Status

## YOUR TASK:

Display comprehensive status of EF Core migrations and database connection.

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

**Type:** Read-only, no modifications

---

## EXECUTION SEQUENCE:

### 0. Validate Required Variables

```bash
# Validate required variables from step-00-init
for VAR_NAME in DBCONTEXT DBCONTEXT_TYPE INFRA_PROJECT STARTUP_PROJECT SELECTED_ENV; do
  eval VAR_VALUE=\$$VAR_NAME
  if [ -z "$VAR_VALUE" ]; then
    echo "ERROR: Required variable $VAR_NAME is not set"
    echo "Run step-00-init first"
    exit 1
  fi
done
```

### 1. Display Configuration

```bash
echo ""
echo "EF CORE STATUS"
echo "=============="
echo ""
echo "Project:     $PROJECT_NAME"
echo "DbContext:   $DBCONTEXT ($DBCONTEXT_TYPE)"
echo "Schema:      $SCHEMA"
echo "Environment: $SELECTED_ENV"
echo "Config:      $CONFIG_FILE"
```

### 2. Test Database Connection

```bash
echo ""
echo "Testing connection..."

CONNECTION_TEST=$(dotnet ef database list \
  --context "$DBCONTEXT" \
  --project "$INFRA_PROJECT" \
  --startup-project "$STARTUP_PROJECT" 2>&1)

if [ $? -eq 0 ]; then
  echo "Connection:  OK"
else
  echo "Connection:  FAILED"
  echo ""
  echo "$CONNECTION_TEST"
fi
```

### 3. List Migrations

```bash
echo ""
echo "Migrations:"

dotnet ef migrations list \
  --context "$DBCONTEXT" \
  --project "$INFRA_PROJECT" \
  --startup-project "$STARTUP_PROJECT"
```

### 4. Count Applied vs Pending

```bash
MIGRATION_OUTPUT=$(dotnet ef migrations list \
  --context "$DBCONTEXT" \
  --project "$INFRA_PROJECT" \
  --startup-project "$STARTUP_PROJECT" 2>/dev/null)

APPLIED=$(echo "$MIGRATION_OUTPUT" | grep -v "(Pending)" | grep -c "^[0-9]" || echo "0")
PENDING=$(echo "$MIGRATION_OUTPUT" | grep -c "(Pending)" || echo "0")
TOTAL=$((APPLIED + PENDING))

echo ""
echo "Summary:"
echo "  Total:    $TOTAL migrations"
echo "  Applied:  $APPLIED"
echo "  Pending:  $PENDING"
```

### 5. Check MCP for Conflicts (Optional)

```javascript
// Call MCP for additional analysis
const result = await mcp__smartstack__check_migrations({
  branch: CURRENT_BRANCH
});

if (result.conflicts && result.conflicts.length > 0) {
  console.log("");
  console.log("Conflicts detected:");
  result.conflicts.forEach(c => console.log("  - " + c));
}
```

### 6. Check Naming Compliance

```bash
echo ""
echo "Naming compliance:"

# Check migration naming pattern
PATTERN="^(core|extensions)_v[0-9]+\.[0-9]+\.[0-9]+_[0-9]+_"
NON_COMPLIANT=$(find "$MIGRATIONS_DIR" -name "*.cs" 2>/dev/null | \
  grep -v "Designer\|Snapshot" | \
  xargs -I{} basename {} .cs | \
  grep -v -E "$PATTERN" | \
  wc -l)

if [ "$NON_COMPLIANT" -eq 0 ]; then
  echo "  All migrations follow naming convention"
else
  echo "  WARNING: $NON_COMPLIANT migrations have non-standard names"
fi
```

### 7. Check 1-Migration-Per-Feature Rule

```bash
# Count migrations for current branch
BRANCH_MIGS=$(find "$MIGRATIONS_DIR" -name "*.cs" 2>/dev/null | \
  grep -v "Designer\|Snapshot" | \
  xargs -I{} basename {} | \
  grep -i "$(echo "$CURRENT_BRANCH" | sed 's|.*/||' | tr '-' '_')" | \
  wc -l)

echo ""
if [ "$BRANCH_MIGS" -le 1 ]; then
  echo "1-migration-per-feature: OK"
else
  echo "1-migration-per-feature: WARNING ($BRANCH_MIGS migrations for this branch)"
  echo "  Consider: /efcore squash"
fi
```

---

## OUTPUT FORMAT:

```
EF CORE STATUS
==============
Project:     {project_name}
DbContext:   {dbcontext} ({dbcontext_type})
Schema:      {schema}
Environment: {env}
Config:      {config_file}

Connection:  {OK | FAILED}

Migrations:
  {list of migrations}

Summary:
  Total:    {N} migrations
  Applied:  {N}
  Pending:  {N}

Naming compliance: {OK | WARNING}
1-migration-per-feature: {OK | WARNING}

{if pending}
Next: /efcore db-deploy
{endif}
```

---

## TROUBLESHOOTING (if connection fails):

```
TROUBLESHOOTING
├── SQL Server running?
├── appsettings.Local.json configured?
├── Database exists?
└── Commands: /efcore db-reset, /efcore db-deploy
```

---

## OPTIONS:

| Option | Description |
|--------|-------------|
| `--verbose` | Show all migrations with details |
| `--json` | Output as JSON |
| `--context` | Specify DbContext |

---

## COMPLETION:

Status displayed. No modifications made.
