---
name: efcore-rebase-snapshot
description: EF Core snapshot rebaser - resync ModelSnapshot with develop
color: yellow
model: sonnet
tools: Bash, Glob, Read, Edit
steps:
  - steps/shared/step-00-init.md
  - steps/rebase-snapshot/step-00-init.md
  - steps/rebase-snapshot/step-01-backup.md
  - steps/rebase-snapshot/step-02-fetch.md
  - steps/rebase-snapshot/step-03-create.md
  - steps/rebase-snapshot/step-04-validate.md
---

# EF Core Rebase-Snapshot Agent

Rebases ModelSnapshot on develop to resolve conflicts.

**Progressive Steps:** Load `steps/rebase-snapshot/` for detailed instructions.

## Workflow

1. **Backup** all migrations
2. **Reset** ModelSnapshot to develop
3. **Delete** branch migrations
4. **Regenerate** consolidated migration
5. **Validate** build OK

## Key Commands

```bash
# Détection projet et DbContext
detect_efcore_project   # → $DBCONTEXT, $DBCONTEXT_TYPE, $SCHEMA
determine_base_branch   # → $BASE_BRANCH, $BRANCH_TYPE

# Backup
BACKUP_DIR=".claude/gitflow/backup/migrations/rebase_$(date +%Y%m%d_%H%M%S)"
mkdir -p "$BACKUP_DIR"
cp Migrations/*.cs "$BACKUP_DIR/"

# Reset snapshot to parent branch (develop ou main selon contexte)
git fetch origin "$BASE_BRANCH"
git checkout "origin/$BASE_BRANCH" -- Migrations/*ModelSnapshot.cs

# Récupérer les migrations de la branche parente
BASE_MIGS=$(git ls-tree -r --name-only "origin/$BASE_BRANCH" -- Migrations/ | grep "\.cs$" | grep -v "Designer\|Snapshot")
for base_mig in $BASE_MIGS; do
  base_name=$(basename "${base_mig%.cs}")
  git checkout "origin/$BASE_BRANCH" -- "Migrations/${base_name}.cs" 2>/dev/null || true
  git checkout "origin/$BASE_BRANCH" -- "Migrations/${base_name}.Designer.cs" 2>/dev/null || true
done

# Delete branch migrations only
rm -f Migrations/*${BRANCH_TYPE}_*.cs
rm -f Migrations/*${BRANCH_TYPE}_*.Designer.cs

# Regenerate with MCP naming - OBLIGATOIRE
mcp__smartstack__suggest_migration({ description: "...", context: DBCONTEXT_TYPE })
# Résultat: core_v1.7.0_001_UserAuthConsolidated

dotnet ef migrations add "$MIGRATION_NAME" --context "$DBCONTEXT"

# Validate
dotnet build
```

## Migration Naming (via MCP)

**OBLIGATOIRE : Utiliser le MCP pour le nommage**

```
{context}_v{version}_{sequence}_{Description}

core_v1.7.0_001_UserAuthConsolidated
core_v1.6.2_001_LoginFixFix
core_v1.7.0_001_ReleaseInitial
```

> **INTERDIT :** Pattern ancien `Feature_1_7_0_UserAuth_Consolidated`

## Safety Checks

- [ ] Clean working directory
- [ ] Backup created
- [ ] Build OK after rebase
- [ ] SQL script can be generated

## Priority

Safety > Correctness > Speed. Backup mandatory.
