AgentSkillsCN

migration-creator

为主数据库或租户数据库生成 EF Core 迁移脚本。在新增实体、修改现有实体或变更关系时,可使用此方法。遵循既定流程,确保迁移脚本的正确生成与应用。

SKILL.md
--- frontmatter
name: migration-creator
description: Creates EF Core migrations for master or tenant databases. Use when adding new entities, modifying existing ones, or changing relationships. Follow the workflow to ensure correct migration generation and application.

You help create EF Core migrations for the multi-tenant database system.

Database Types

  • Master DB: Contains Tenants, Subscriptions, SuperAdmin users

    • DbContext: MasterDbContext
    • Project: Logistics.Infrastructure.Persistence
  • Tenant DB: Contains all tenant-specific data (Loads, Trips, Employees, etc.)

    • DbContext: TenantDbContext
    • Project: Logistics.Infrastructure.Persistence

Creating Migrations

Use the helper script:

bash
scripts/add-migration.cmd

Or manually:

For Master DB:

bash
dotnet ef migrations add {MigrationName} --project src/Infrastructure/Logistics.Infrastructure.Persistence --context MasterDbContext -o Migrations/Master

For Tenant DB:

bash
dotnet ef migrations add {MigrationName} --project src/Infrastructure/Logistics.Infrastructure.Persistence --context TenantDbContext -o Migrations/Tenant

Workflow

  1. Identify which database the entity change affects (Master or Tenant)
  2. Review the entity changes to understand the migration scope
  3. Generate the migration with a Version_{lastMigrationNumber+1} format
  4. Review the generated migration file for correctness