Migrate

codewithmukesh/dotnet-claude-kit/skills/migrate

作者 codewithmukesh23300897f4d1无许可证754 个星标收录于 2026年10月8日更新于 2026年10月8日仓库2个月前更新

Guided, safe migration workflow covering EF Core schema migrations, .NET version upgrades, and NuGet dependency updates — each with rollback strategies and verification steps. Invoke when: "add migration", "update database", "create migration", "schema change", "new table", "rename column", "upgrade nuget", "update packages", "dependency update", "version upgrade", ".NET upgrade".

AI 生成的概览

指导 EF Core 架构迁移、.NET 版本升级与 NuGet 包更新的工作流,包含回滚与验证步骤。

功能
为三类变更提供分步迁移工作流:EF Core 架构迁移、.NET 版本升级和 NuGet 依赖更新。内容涵盖评估当前状态、审查模型变更、生成并审查迁移 SQL、应用变更、通过构建与测试验证,以及记录回滚方案。还列出了用于定位符号、检查类型层次和审计项目图的 MCP 工具。
适用场景
适用于修改实体类、DbContext 配置或关系之后,或被要求添加或创建迁移、更新数据库、重命名列、新增表时。也适用于 .NET 版本升级、NuGet 包更新以及存在漏洞的包告警。
运行要求
需要 .NET SDK 及 EF Core 命令行工具(dotnet ef),以及 dotnet build、dotnet test 和 dotnet format。部分步骤引用 MCP 工具,如 find_symbol、find_references、get_type_hierarchy、get_project_graph 和 get_diagnostics,并引用 knowledge/ 下的知识文件。不附带脚本,仅为说明文档。

/migrate

What

The single migration workflow for three change types, with EF Core schema migrations as the primary flow:

  1. EF Core schema — review pending model changes, generate a descriptively named migration, review the SQL for data loss and locking risks, apply with a documented rollback path.
  2. .NET version upgrade — phased TFM/SDK/package upgrade with verification at each phase.
  3. NuGet updates — incremental, one-package-at-a-time updates so breakage is always attributable.

Shared principles: verify before applying, rollback plan always, test after every step, one logical change per migration.

When

  • After modifying entity classes, DbContext configuration, or relationships
  • "add migration", "update database", "create migration", "new table", "rename column"
  • When generating SQL scripts for DBA review
  • "upgrade to .NET 10", "version upgrade", ".NET upgrade"
  • "upgrade nuget", "update packages", "dependency update", vulnerable package alerts

How

First, classify the request: schema change → Flow A; framework upgrade → Flow B; package update → Flow C. Then follow that flow end to end.

Flow A: EF Core Schema Migration (primary)

Step 1: Assess current state

bash
dotnet ef migrations list --project <InfraProject> --startup-project <ApiProject>

Check for pending migrations and uncaptured model changes.

Step 2: Review model changes

Use MCP tools instead of reading whole files:

find_symbol(name: entity or DbSet)        -- locate the changed entityget_type_hierarchy(typeName: entity)      -- check TPH/TPT/TPC inheritance changesfind_references(symbolName: property)     -- assess downstream query impact

Confirm the change is one logical unit. If not, split into multiple migrations — mixed migrations make rollback all-or-nothing.

Step 3: Generate migration

Name describes the change, not the entity: Add|Remove|Rename|Modify + WhatChanged.

bash
# GOODdotnet ef migrations add AddOrderShippingAddress --project <Infra> --startup-project <Api># BAD — names the entity, not the changedotnet ef migrations add Order

Step 4: Review generated SQL

database update has no dry-run flag — preview by generating an idempotent script and reading it:

bash
dotnet ef migrations script --idempotent --project <Infra> --startup-project <Api>

Flag and report:

  • DROP COLUMN / DROP TABLE — confirm data loss is intentional
  • ALTER COLUMN type changes — check precision loss or truncation
  • ALTER on large tables — warn about lock duration
  • New non-nullable columns — need defaults for existing rows

If data must survive a rename/retype, use a multi-step migration with raw SQL:

csharp
protected override void Up(MigrationBuilder migrationBuilder){    migrationBuilder.AddColumn<string>("ContactEmail", "Customers", nullable: true);    migrationBuilder.Sql("UPDATE \"Customers\" SET \"ContactEmail\" = \"Email\"");    migrationBuilder.AlterColumn<string>("ContactEmail", "Customers", nullable: false);    migrationBuilder.DropColumn("Email", "Customers");}

Step 5: Apply and verify

bash
dotnet ef database update --project <Infra> --startup-project <Api>dotnet build && dotnet test   # integration tests catch schema mismatches

Step 6: Document rollback

bash
dotnet ef database update <PreviousMigrationName> --project <Infra> --startup-project <Api>dotnet ef migrations remove --project <Infra> --startup-project <Api>   # if unapplying from code

Never modify a migration that is already applied — create a new one.

Flow B: .NET Version Upgrade

  1. Assess — get_project_graph to list all TFMs; flag mixed versions.
  2. Pre-flight — all tests green, no pending EF migrations, dependencies checked for target-version compatibility, dedicated branch created (branch IS the rollback plan).
  3. Update global.json — SDK version with "rollForward": "latestMinor".
  4. Update TFMs — <TargetFramework>net10.0</TargetFramework> and <LangVersion>14</LangVersion> in .csproj or Directory.Build.props.
  5. Update packages — dotnet outdated --upgrade Major --include Microsoft.*, then build and fix.
  6. Adopt new features — per knowledge/dotnet-whats-new.md: TimeProvider, HybridCache, primary constructors, collection expressions.
  7. Verify — dotnet build, dotnet test, dotnet format --verify-no-changes.

Flow C: NuGet Package Updates

  1. Audit — dotnet list package --outdated and dotnet list package --vulnerable. Vulnerable packages are urgent: update, test, deploy.
  2. Categorize — patch (batch-safe), minor (one at a time), major (one at a time, read release notes first).
  3. Update incrementally — one package, then dotnet build && dotnet test before the next. Batched updates make failures unattributable.
  4. Check fit — consult knowledge/package-recommendations.md before adding new packages; prefer built-in .NET alternatives. Moving off MediatR (commercial license from v13)? Follow the step-by-step guide in knowledge/mediatr-to-mediator-migration.md.
  5. Rollback — git revert the package bump; never downgrade other packages to compensate.

MCP Tools Used

  • find_symbol / find_references — locate entities, assess schema-change impact
  • get_type_hierarchy — entity inheritance for TPH/TPT/TPC
  • get_project_graph — TFM audit before version upgrades
  • get_diagnostics — catch warnings after migration generation or upgrades

Example

User: /migrate
Claude: Checking migration state...  Last applied: 20250710_AddOrderTable  Model changes detected: new ShippingAddress property on Order entity.
  Creating migration: AddOrderShippingAddress  Reviewing SQL (dotnet ef migrations script --idempotent)...  - ALTER TABLE "Orders" ADD "ShippingStreet" text NULL  - ALTER TABLE "Orders" ADD "ShippingCity" text NULL  No data loss. No locking risk. Safe to apply.
  Applying migration... Done. Build: green. Tests: 34/34 passed.
  Rollback (if needed):  dotnet ef database update AddOrderTable --project src/Infrastructure --startup-project src/Api

Related

  • ef-core — entity configuration, query patterns, migration internals
  • /verify — full verification pipeline after migration work
  • /checkpoint — commit a safe state before risky migrations

来源与署名

来源:codewithmukesh/dotnet-claude-kit位于skills/migrate提交2330089

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架

更多来自 codewithmukesh/dotnet-claude-kit 的技能

Wrap Up

codewithmukesh

在会话结束时把已完成工作、待办任务与经验写入交接文件,并在会话开始时重新载入。

Productivity & Workflow7542个月前更新

Workflow Mastery

codewithmukesh

Claude Code workflow mastery for .NET developers. Covers parallel execution with git worktrees, plan mode strategy, verification loops, auto-formatting hooks, permission setup for dotnet CLI, prompting techniques, subagent patterns, and context discipline — token budget management, MCP-first navigation, lazy loading, and subagent isolation — all adapted for the .NET ecosystem. Load this skill when setting up Claude Code for a .NET project, optimizing workflows, running parallel sessions, when context is running low or sessions feel sluggish, when exploring a large codebase efficiently, or when the user mentions "productivity", "workflow", "parallel", "worktree", "plan mode", "permissions", "hooks", "10x", "setup Claude Code", "speed up development", "context", "tokens", "budget", "running out of context", "too many files", or "large codebase". Inspired by tips from Boris Cherny (creator of Claude Code) and the Anthropic team.

待分类7542个月前更新

Vertical Slice

codewithmukesh

指导 .NET 开发者采用垂直切片架构组织应用,涵盖功能文件夹、端点分组与处理程序模式。

Software Development7542个月前更新

Testing

codewithmukesh

Testing strategy for .NET 10 applications. Covers xUnit v3, WebApplicationFactory for integration tests, Testcontainers for real database testing, Verify for snapshot testing, and the AAA pattern. Load this skill when writing tests, setting up test infrastructure, reviewing test coverage, or when the user mentions "test", "xUnit", "WebApplicationFactory", "Testcontainers", "integration test", "unit test", "bUnit", "snapshot test", "Verify", "test coverage", "AAA pattern", "WireMock", or "FakeTimeProvider".

待分类7542个月前更新

Tdd

codewithmukesh

Guided test-driven development workflow for .NET 10 using xUnit v3, WebApplicationFactory, Testcontainers, and Verify snapshots. Follows the strict red-green-refactor cycle. Use when: "TDD", "test-driven", "let's TDD this", "red green refactor", "write the test first", or when building a feature with clear acceptance criteria.

待分类7542个月前更新

Spec

codewithmukesh

通过结构化提问,把模糊的功能想法转化为双方确认并持久化的规格说明文件。

Productivity & Workflow7542个月前更新