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

# Step 2: Create Migration

## YOUR TASK:

Get migration description from user, call MCP for compliant name, and create migration.

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

**Previous step:** `step-01-check.md`

---

## EXECUTION SEQUENCE:

### 1. Get Description from User

**If NOT force mode with predefined description:**

```yaml
AskUserQuestion:
  header: "Description"
  question: "Short description for the migration (e.g., 'Add User Roles'):"
  options:
    - label: "Add..."
      description: "Adding tables/columns"
    - label: "Update..."
      description: "Modifying structure"
    - label: "Fix..."
      description: "Schema correction"
    - label: "Remove..."
      description: "Deleting elements"
  multiSelect: false
```

**User can also provide free text (Other option).**

```bash
# DESCRIPTION = user response or predefined value
# Examples: "Add User Roles", "Update Tenant Schema", "Fix Foreign Keys"

echo ""
echo "Description: $DESCRIPTION"
```

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

```javascript
// DESCRIPTION = from user input (e.g., "Add User Roles")
// 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.8.0_001_AddUserRoles
MIGRATION_NAME = result.migrationName;
```

**FORBIDDEN:**
- Calculating name manually
- Hardcoding context as "core"
- Using wrong version format

### 3. Display Migration Name

```bash
echo ""
echo "Migration name: $MIGRATION_NAME"
echo "Context: $DBCONTEXT"
echo ""
```

### 4. Create Migration

```bash
echo "Creating migration..."
echo ""

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

### 5. Verify Creation

```bash
# Check files were created
MIGRATION_FILE="$MIGRATIONS_DIR/${MIGRATION_NAME}.cs"
DESIGNER_FILE="$MIGRATIONS_DIR/${MIGRATION_NAME}.Designer.cs"

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

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

---

## STATE OUTPUT:

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

---

## ERROR HANDLING:

| Error | Resolution |
|-------|------------|
| MCP unavailable | Check connection, retry |
| Creation fails | Check dotnet ef output |
| File not created | Verify paths and permissions |

---

## SUCCESS CRITERIA:

- Description captured
- MCP called successfully
- Migration files created

## NEXT STEP:

→ `step-03-validate.md`
