skills/ef-migration-manager/SKILL.md
EF Core migration lifecycle with safety checks and rollback planning. Use when creating, reviewing, or applying database migrations in .NET projects. Do NOT use when the goal is initial schema design or ad-hoc SQL management; Do NOT use when the project uses Dapper or raw SQL without an EF Core DbContext.
npx skillsauth add michaelalber/ai-toolkit ef-migration-managerInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
"Data is a precious thing and will last longer than the systems themselves." -- Tim Berners-Lee
This skill manages the full Entity Framework Core migration lifecycle: Plan → Create → Review SQL → Test Rollback → Apply. Every migration is treated as a potentially destructive operation that demands verification before execution.
Non-negotiable constraints:
Down() correctly reverses all changes before applying Up().--idempotent. Manual SQL requires existence checks.| # | Principle | Description | Priority |
|---|-----------|-------------|----------|
| 1 | Data Integrity First | Column drops, type narrowing, and table removal require data migration plans. | Critical |
| 2 | Rollback Safety | Every Up() must have a Down() that fully reverses the change. Test rollback before applying forward. | Critical |
| 3 | Idempotent Scripts | Production scripts must be safe to run multiple times. Use --idempotent or guard clauses. | Critical |
| 4 | Zero-Downtime Awareness | Evaluate whether a migration can run while the application is live. Flag blocking operations. | High |
| 5 | Migration Ordering | Migrations form a linear chain. Never reorder, edit, or delete applied migrations. | Critical |
| 6 | SQL Review Mandatory | The C# migration code is not sufficient -- inspect the actual DDL before applying. | Critical |
| 7 | Schema Validation | After applying, verify the database schema matches the EF model snapshot. | High |
| 8 | Environment Parity | Dev, staging, and production must follow the same migration chain. No ad-hoc SQL to production only. | High |
| 9 | Seed Data Management | Seed data belongs in migrations or HasData(), not application startup code. | Medium |
| 10 | Migration Naming | Use descriptive names that convey intent: AddUserEmailIndex, SplitAddressFromCustomer. | Medium |
| Query | When to Call |
|-------|--------------|
| search_knowledge("EF Core migration create apply rollback script generation") | At session start — confirms dotnet-ef CLI commands and lifecycle |
| search_knowledge("EF Core migration Up Down idempotent script SQL generation") | During REVIEW SQL — authoritative idempotent script patterns |
| search_knowledge("database migration zero downtime column rename data loss") | During PLAN — zero-downtime migration strategies |
| search_knowledge("EF Core DbContext model snapshot migration conflict resolution") | When resolving migration conflicts |
| search_knowledge("SQL Server PostgreSQL DDL ALTER TABLE index constraint") | When reviewing generated DDL — safe vs. dangerous operations by database |
Search before REVIEW SQL and TEST ROLLBACK phases. Cite source paths in migration review comments.
The migration lifecycle flows: PLAN → CREATE → REVIEW SQL → TEST ROLLBACK → APPLY; on apply failure, emergency rollback returns to PLAN.
Before creating any migration:
dotnet ef migrations list)Before creating a migration, classify the change: column drop or table drop with data → Critical; type narrowing or NOT NULL addition on existing rows → High; widening type change or empty table removal → Low; additive change → None. See references/data-loss-matrix.md for full risk matrix.
Step 1: PLAN — Identify the schema change. Consult the data loss matrix. Determine if a data migration step is needed. Decide single migration vs. multi-step.
Step 2: CREATE
dotnet ef migrations add <MigrationName> --project <DataProject> --startup-project <StartupProject>
Review the generated Up(), Down(), and updated ModelSnapshot.cs.
Step 3: REVIEW SQL
dotnet ef migrations script --idempotent --project <DataProject> --startup-project <StartupProject>
Inspect for: data loss operations, blocking locks, missing index recreations, constraint naming.
Step 4: TEST ROLLBACK
# Apply the migration
dotnet ef database update --project <DataProject> --startup-project <StartupProject>
# Roll back to the previous migration
dotnet ef database update <PreviousMigrationName> --project <DataProject> --startup-project <StartupProject>
# Re-apply to verify forward path
dotnet ef database update --project <DataProject> --startup-project <StartupProject>
Step 5: APPLY — Development: dotnet ef database update. Staging/production: generate an idempotent script or migration bundle.
<ef-migration-state>
step: [PLAN | CREATE | REVIEW_SQL | TEST_ROLLBACK | APPLY | ROLLBACK | ERROR_RECOVERY]
migration_name: [descriptive name, e.g., AddUserEmailIndex]
data_loss_risk: [none | low | high | critical]
rollback_ready: [true | false]
sql_reviewed: [true | false]
last_action: [what was just done]
next_action: [what should happen next]
blockers: [any issues preventing progress]
</ef-migration-state>
Example:
<ef-migration-state>
step: PLAN
migration_name: SplitCustomerAddress
data_loss_risk: high
rollback_ready: false
sql_reviewed: false
last_action: Identified need to extract Address columns into separate table
next_action: Create migration with data copy logic
blockers: Must verify all existing customers have address data
</ef-migration-state>
## Migration Review: [MigrationName]
**Risk**: [none|low|high|critical] | **SQL Reviewed**: [yes|no] | **Rollback Tested**: [yes|no]
| Operation | Table/Column | Risk | Notes |
|-----------|-------------|------|-------|
| [ADD/ALTER/DROP] | [target] | [level] | [details] |
**Findings**: [any issues from SQL review]
**Rollback Command**: `dotnet ef database update [PreviousMigration] ...`
Full report templates (Creation Report, SQL Review Report, Apply Report): references/migration-commands.md.
Never apply without SQL review. Generate the script with --idempotent, inspect every statement for data loss potential, then apply. If the SQL has not been reviewed, STOP.
Always verify rollback before production. Apply to development, run dotnet ef database update <PreviousMigration>, verify the schema returns to its prior state, re-apply to confirm. A migration without a working Down() is not production-ready.
Never ignore data loss warnings. When dotnet ef migrations add warns about data loss, STOP. Assess impact using references/data-loss-matrix.md. Create a data preservation step (new column → copy data → drop old column) rather than suppressing the warning. Explicit acknowledgment and mitigation must be in place before proceeding.
Always check pending migrations before creating new ones. Run dotnet ef migrations list first. If any migrations are marked as pending, apply them before adding new ones. Creating a migration on top of unapplied migrations creates ordering risks and conflicts.
| Anti-Pattern | Why It's Dangerous | Correct Approach |
|--------------|-------------------|------------------|
| Apply migration without reviewing SQL | Hidden data loss, unexpected locks, constraint violations | Always generate and review SQL script first |
| Skip rollback testing | Discover broken Down() during production incident | Test rollback in development for every migration |
| Edit an already-applied migration | Breaks migration chain, causes snapshot desync | Create a new corrective migration instead |
| Bundle unrelated schema changes | One failure blocks all changes, rollback is all-or-nothing | One concern per migration |
| Use EnsureCreated() alongside migrations | EnsureCreated bypasses migration history entirely | Use migrations exclusively for schema management |
| Delete migration files to "fix" issues | Corrupts migration history and model snapshot | Use dotnet ef migrations remove for unapplied migrations |
| Hardcode connection strings in migrations | Security risk, environment coupling | Use configuration and IDesignTimeDbContextFactory |
| Apply migrations in application startup | Race conditions in multi-instance deployments | Use deployment scripts, bundles, or CI/CD pipeline |
Migration apply failed mid-execution: Check __EFMigrationsHistory to see if the migration was recorded. Manually revert partial changes via SQL. Remove the history entry if needed (DELETE FROM __EFMigrationsHistory WHERE MigrationId = '<id>'). Fix the migration and re-apply. Wrap complex migrations in explicit transactions to prevent partial application.
Broken migration chain: Run dotnet ef migrations list to see the discrepancy. If migrations exist in DB but not in code, restore missing files from git. If code migrations were never applied, apply them in order. Last resort: create a baseline migration, empty its Up() method (schema already exists), and apply as a no-op.
Data loss detected after apply: STOP all further migrations immediately. Restore from the most recent backup. Re-examine the offending migration, create a corrected version with data preservation, and add the scenario to the team review checklist.
Model snapshot out of sync: Do NOT manually edit ModelSnapshot.cs. Run dotnet ef migrations remove to remove the last unapplied migration (this regenerates the snapshot). Verify alignment, then re-create the migration.
Migration timeout on large table: Increase command timeout in the migration using migrationBuilder.Sql("SET LOCK_TIMEOUT <ms>;"). For very large tables, use batched data migrations or online schema change tools (pt-online-schema-change for MySQL; online index operations for SQL Server). Schedule blocking operations during maintenance windows.
dotnet-vertical-slice -- When creating a new vertical slice feature, use this skill to manage schema changes required by the feature's data layer. The migration should be part of the slice implementation.legacy-migration-analyzer -- When analyzing legacy systems, use this skill to plan the EF Core schema replacing the legacy database. Coordinate between legacy analysis findings and the new migration plan.development
Federal / government security overlay applied ON TOP OF a base language security review (dotnet/python/php/rust/react). Language-agnostic: adds NIST SP 800-53 control mapping, FIPS 140-2/3 cryptographic compliance (with a per-language crypto table), CUI handling, EO 14028 supply-chain requirements, and DOE Order 205.1B, and emits POA&M-ready findings with FIPS 199 impact levels. Use for federal/DOE/DOD/national-laboratory systems. Triggers on "federal security review", "NIST compliance", "NIST 800-53", "FISMA", "CUI", "FIPS audit", "DOE security", "POA&M", "ATO review". Do NOT use alone — run the matching <lang>-security-review FIRST; this overlay maps and extends it.
tools
OWASP-based security review of React / TypeScript front-end applications. Detects the framework (Vite/CRA/Next), entry points, and data flows, scans against the OWASP Top 10 (2025) mapped to React client-side patterns (XSS via raw HTML, URL/protocol injection, secrets in the bundle, insecure token storage, dependency CVEs, missing CSP, open redirects), and produces a manager-friendly executive summary plus a graded technical findings table. Use to audit React code for vulnerabilities. Triggers on "react security review", "frontend security audit", "audit react for vulnerabilities", "owasp react", "react xss", "react security posture", "npm audit review". For federal / gov / DOE / NIST / FIPS / CUI context, run security-review-federal after this base review. Do NOT use to grade architecture/structure — use react-architecture-checklist.
tools
Analyzes legacy React codebases and produces actionable modernization plans. Primary migration paths include class components to function components + hooks, Create React App to Vite, React 16/17 to 18 to 19, JavaScript to TypeScript, Enzyme to React Testing Library, legacy Redux to Redux Toolkit / Zustand / Context, and deprecated lifecycle/API removal. Does NOT perform the migration — assesses, quantifies risk, and plans. Triggers on phrases like "modernize react", "class to hooks", "upgrade react", "migrate CRA to vite", "react legacy migration", "react 17 to 18", "react js to typescript", "react technical debt", "enzyme to RTL".
development
Scaffolds feature-based React / TypeScript architecture using feature folders, presentational + container components, custom hooks, a typed data layer, and structural CQRS (query hooks vs mutation hooks). React analog of dotnet-vertical-slice and python-feature-slice — no DI framework; uses props/context for dependency injection and a query cache for server state. Use when creating feature-based React projects, adding React features, organizing components by feature rather than by technical type, or scaffolding a feature's data layer. Triggers on phrases like "scaffold react feature", "create react slice", "react feature folder", "react vertical slice", "add react feature", "react feature architecture", "organize react by feature".