---
description: Scan all branches for migrations with risk analysis
agent: efcore-scan
model: sonnet
---

# EF Core Scan - Cross-Branch Migration Scanner

Scans all active branches to detect migrations and analyze conflict risks using **SmartStack MCP**.

**USAGE:** Before creating a migration or before a merge to check the status of other branches.

**SECURITY:** Read-only - no modifications.

**INTEGRATION:** Uses `mcp__smartstack__check_migrations` for each branch comparison.

---

## STEP 1: Detect Active Worktrees

```bash
# List all git worktrees
WORKTREES=$(git worktree list --porcelain | grep "^worktree" | cut -d' ' -f2)

echo "DETECTED WORKTREES"
echo "=================="
git worktree list
echo ""
```

---

## STEP 2: Invoke MCP for Each Branch

> **MCP INTEGRATION:** For each active branch, call the MCP to get structured analysis.

For each worktree/branch, call:

```json
{
  "tool": "mcp__smartstack__check_migrations",
  "parameters": {
    "branch": "<branch_name>",
    "compareBranch": "develop"
  }
}
```

**Claude instruction:** Loop through detected branches and invoke MCP:

```
FOR each branch in [feature/*, hotfix/*, release/*]:
  CALL mcp__smartstack__check_migrations WITH:
    - branch: {branch}
    - compareBranch: "develop"
  STORE result in BRANCH_RESULTS[branch]
```

---

## STEP 3: Aggregate Results

Parse MCP responses to build summary:

```typescript
interface ScanSummary {
  branches: BranchScan[];
  totalMigrations: number;
  conflictCount: number;
  recommendedMergeOrder: string[];
}

interface BranchScan {
  name: string;
  migrationCount: number;
  riskLevel: 'NONE' | 'LOW' | 'MEDIUM' | 'HIGH';
  conflicts: MigrationConflict[];
}
```

**Risk Level Calculation:**

| Condition | Risk Level |
|-----------|------------|
| Snapshot identical to develop | NONE |
| Different tables modified | LOW |
| FK to same tables | MEDIUM |
| Same tables/columns modified | HIGH |

---

## STEP 4: Calculate Merge Order

Based on conflict analysis, recommend merge order:

```
1. Branches with RISK=NONE (can merge immediately)
2. Branches with RISK=LOW (minor modifications, safe to merge)
3. Branches with RISK=MEDIUM (order matters, merge carefully)
4. Branches with RISK=HIGH (rebase required before merge)
```

---

## STEP 5: Display Report

```
================================================================================
                    EF CORE CROSS-BRANCH SCAN (via MCP)
================================================================================

DETECTED WORKTREES ({count})
  main/                    [main]
  develop/                 [develop]         <- REFERENCE
  features/user-auth/      [feature/user-auth]
  features/add-products/   [feature/add-products]
  hotfixes/login-fix/      [hotfix/login-fix]

MIGRATIONS PER BRANCH
--------------------------------------------------------------------------------
  Branch                  | Migrations | Snapshot   | vs Develop
--------------------------------------------------------------------------------
  develop                 | 12         | a1b2c3d4   | REFERENCE
  feature/user-auth       | 13         | e5f6g7h8   | +1 migration
  feature/add-products    | 13         | i9j0k1l2   | +1 migration
  hotfix/login-fix        | 12         | a1b2c3d4   | identical
--------------------------------------------------------------------------------

RISK ANALYSIS
--------------------------------------------------------------------------------
  feature/user-auth       : LOW      (different tables)
  feature/add-products    : MEDIUM   (FK to same table)
  hotfix/login-fix        : NONE     (snapshot = develop)
--------------------------------------------------------------------------------

RECOMMENDED MERGE ORDER
--------------------------------------------------------------------------------
  1. hotfix/login-fix      -> NONE   (direct merge OK)
  2. feature/user-auth     -> LOW    (merge OK)
  3. feature/add-products  -> MEDIUM (after user-auth, then rebase)
--------------------------------------------------------------------------------

================================================================================
```

---

## Options

| Option | Description |
|--------|-------------|
| `--json` | Output raw JSON for CI/CD |
| `--branch <name>` | Scan specific branch only |
| `--verbose` | Show detailed MCP responses |
| `--no-recommend` | Skip merge order recommendations |

---

## CI/CD Usage

```yaml
# GitHub Actions
- name: Scan EF Core migrations
  run: |
    # Claude Code will use MCP internally
    OUTPUT=$(claude-code "/efcore:scan --json")
    HIGH_RISK=$(echo $OUTPUT | jq '[.branches[] | select(.riskLevel == "HIGH")] | length')
    if [ "$HIGH_RISK" -gt 0 ]; then
      echo "::warning::$HIGH_RISK branches have HIGH risk migration conflicts"
    fi
```

---

## MCP Tool Reference

**Tool:** `mcp__smartstack__check_migrations`

**Description:** Analyze EF Core migrations for conflicts, ordering issues, and ModelSnapshot discrepancies between branches

**Parameters:**

| Parameter | Type | Description |
|-----------|------|-------------|
| `projectPath` | string | EF Core project path (default: auto-detect) |
| `branch` | string | Git branch to check (default: current) |
| `compareBranch` | string | Branch to compare against |

**Response:** `MigrationCheckResult` with `hasConflicts`, `migrations[]`, `conflicts[]`, `suggestions[]`

---

## Why MCP Integration?

1. **Consistency:** Identical analysis logic for single branch (`/efcore:conflicts`) and multi-branch (`/efcore:scan`)
2. **Accuracy:** Structured parsing instead of regex on ModelSnapshot files
3. **Extensibility:** New conflict types added in MCP benefit all commands
4. **Caching:** MCP can cache results for faster subsequent scans
