---
name: step-04-validate
description: Validate rebase-snapshot - build and test
next_step: null
---

# Step 4: Validate

## YOUR TASK:

Validate the rebased migration by building and generating a script.

**Previous step:** `step-03-create.md`

---

## EXECUTION SEQUENCE:

### 1. Build Project

```bash
echo "Building project..."

dotnet build "$INFRA_PROJECT" --no-restore

if [ $? -ne 0 ]; then
  echo ""
  echo "ERROR: Build failed"
  echo "Restoring from backup..."
  cp "$BACKUP_DIR"/*.cs "$MIGRATIONS_DIR/"
  exit 1
fi

echo "Build: OK"
```

### 2. Generate Script

```bash
echo ""
echo "Generating migration script..."

SCRIPT_FILE="$BACKUP_DIR/migration_script.sql"

dotnet ef migrations script \
  --context "$DBCONTEXT" \
  --project "$INFRA_PROJECT" \
  --startup-project "$STARTUP_PROJECT" \
  --idempotent \
  --no-build \
  -o "$SCRIPT_FILE"

if [ $? -ne 0 ]; then
  echo ""
  echo "ERROR: Script generation failed"
  echo "Restoring from backup..."
  cp "$BACKUP_DIR"/*.cs "$MIGRATIONS_DIR/"
  exit 1
fi

echo "Script: $SCRIPT_FILE"
```

### 3. List Migrations

```bash
echo ""
echo "Migration list:"

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

### 4. Final Summary

```bash
FINAL_COUNT=$(find "$MIGRATIONS_DIR" -name "*.cs" 2>/dev/null | grep -v "Designer\|Snapshot" | wc -l)

echo ""
echo "==========================================="
echo "REBASE-SNAPSHOT COMPLETE"
echo "==========================================="
echo ""
echo "Branch:      $CURRENT_BRANCH"
echo "Parent:      $BASE_BRANCH"
echo "DbContext:   $DBCONTEXT ($DBCONTEXT_TYPE)"
echo ""
echo "Changes:"
echo "  - Snapshot reset to $BASE_BRANCH"
echo "  - Removed: ${#BRANCH_MIGRATIONS[@]} branch migrations"
echo "  - Created: 1 consolidated migration"
echo ""
echo "Result:"
echo "  Migration: $MIGRATION_NAME"
echo "  Total:     $FINAL_COUNT migrations"
echo ""
echo "Backup:      $BACKUP_DIR"
echo "Script:      $SCRIPT_FILE"
echo ""
echo "==========================================="
echo ""
echo "Next steps:"
echo "  /efcore db-reset      # Reset local database"
echo "  /efcore db-deploy     # Apply migrations"
echo "  /gitflow commit       # Commit changes"
echo ""
```

---

## OUTPUT FORMAT:

```
REBASE-SNAPSHOT COMPLETE
========================
Branch:      {current_branch}
Parent:      {base_branch}
DbContext:   {dbcontext} ({dbcontext_type})

Changes:
  - Snapshot reset to {base_branch}
  - Removed: {count} branch migrations
  - Created: 1 consolidated migration

Result:
  Migration: {migration_name}
  Total:     {final_count} migrations

Backup:      {backup_dir}
Script:      {backup_dir}/migration_script.sql

Next: /efcore db-reset, /efcore db-deploy, /gitflow commit
```

---

## ERROR HANDLING:

| Error | Action |
|-------|--------|
| Build fails | Restore backup |
| Script fails | Restore backup |

---

## SUCCESS CRITERIA:

- Build passes
- Script generates
- Summary displayed

## COMPLETION:

Rebase-snapshot complete. Use `/efcore db-reset` then `/efcore db-deploy` to apply.
