---
name: step-03-create
description: Create consolidated migration with MCP naming
next_step: step-04-validate.md
---

# Step 3: Create Consolidated Migration

## YOUR TASK:

Generate a new consolidated migration capturing all branch changes.

**MANDATORY:** Use MCP for naming. NEVER hardcode.

**Previous step:** `step-02-fetch.md`

---

## EXECUTION SEQUENCE:

### 1. Build Description

```bash
# Extract feature name from branch
FEATURE_NAME=$(echo "$CURRENT_BRANCH" | sed 's|.*/||' | sed 's/-/ /g' | \
  awk '{for(i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) tolower(substr($i,2))}1' | \
  tr -d ' ')

DESCRIPTION="${FEATURE_NAME}Consolidated"

echo "Description: $DESCRIPTION"
```

### 2. Call MCP for Migration Name (MANDATORY)

```javascript
// DESCRIPTION = from above (e.g., "UserAuthConsolidated")
// DBCONTEXT_TYPE = "core" or "extensions" (from detect_dbcontext)

const result = await mcp__smartstack__suggest_migration({
  description: DESCRIPTION,
  context: DBCONTEXT_TYPE    // NEVER hardcode!
});

// Result example: core_v1.7.0_001_UserAuthConsolidated
MIGRATION_NAME = result.migrationName;
```

**FORBIDDEN:**
- Manual name calculation
- Hardcoding context

### 3. Create Migration

```bash
echo ""
echo "Creating migration: $MIGRATION_NAME"
echo "Context: $DBCONTEXT"
echo ""

dotnet ef migrations add "$MIGRATION_NAME" \
  --context "$DBCONTEXT" \
  --project "$INFRA_PROJECT" \
  --startup-project "$STARTUP_PROJECT" \
  -o Persistence/Migrations \
  --verbose
```

### 4. Verify Files Created

```bash
MIGRATION_FILE="$MIGRATIONS_DIR/${MIGRATION_NAME}.cs"
DESIGNER_FILE="$MIGRATIONS_DIR/${MIGRATION_NAME}.Designer.cs"

if [ ! -f "$MIGRATION_FILE" ]; then
  echo "ERROR: Migration file not created"

  # Restore backup
  cp "$BACKUP_DIR"/*.cs "$MIGRATIONS_DIR/"
  echo "Restored from backup"
  exit 1
fi

echo ""
echo "Migration created:"
echo "  $MIGRATION_FILE"
echo "  $DESIGNER_FILE"
```

### 5. Inject SQL Objects (Functions, Views, SP)

Load: `references/sql-objects-injection.md`

---

## STATE OUTPUT:

| Variable | Description |
|----------|-------------|
| `{migration_name}` | Name from MCP |
| `{migration_file}` | Path to .cs file |

---

## SUCCESS CRITERIA:

- MCP called successfully
- Migration files created

## NEXT STEP:

→ `step-04-validate.md`
