db-migration

Create EF Core migrations for MySQL and SQL Server with separate DbContexts.

56|14|Updated Dec 30, 2024
One-click install
npx skills add https://github.com/xin-lai/CodeSpirit --skill db-migration-xin-lai
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: db-migration
Source: https://github.com/xin-lai/CodeSpirit/tree/main/.cursor/skills/db-migration
Command: npx skills add https://github.com/xin-lai/CodeSpirit --skill db-migration-xin-lai

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) components.

What problem does it solve?

Ensures consistent database schema changes across MySQL and SQL Server by guiding developers to create, validate, and apply separate EF Core migrations per database while handling database-specific differences and snowflake ID configuration.

Core Features & Use Cases

  • Dual-database migration workflow: Step-by-step instructions to create matching migrations for MySQL and SQL Server using database-specific DbContext types.
  • DbContext pattern and configuration guidance: Describes the recommended three-layer DbContext inheritance and how to configure ValueGeneratedNever for snowflake IDs.
  • Database-specific adjustments: Notes on MySQL datetime, character set, boolean and long-text mappings and minimal SQL Server adjustments.
  • Validation and automation scripts: Includes PowerShell scripts to validate migration files and apply migrations to both databases.
  • Use Case: Add a new entity or modify fields and generate two synchronized migration sets that can be applied in development and committed to version control.

Quick Start

Create matching MySQL and SQL Server migrations for your service by running migrations against MySql{Service}DbContext and SqlServer{Service}DbContext and outputting them to Data/Migrations/MySql and Data/Migrations/SqlServer.

Frequently Asked Questions about db-migration

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create synchronized EF Core migrations for both MySQL and SQL Server?

To create synchronized EF Core migrations, run migration commands against database-specific DbContext types like MySql{Service}DbContext and SqlServer{Service}DbContext, outputting them to separate Data/Migrations directories for each database provider.

What is the recommended DbContext pattern for dual-database EF Core migration workflows?

The recommended DbContext pattern uses a three-layer inheritance structure with database-specific DbContext types. This separates MySQL and SQL Server configurations while enforcing rules like ValueGeneratedNever for snowflake IDs during EF Core migrations.

How do I handle snowflake ID configuration in EF Core migrations?

Handle snowflake ID configuration in EF Core migrations by enforcing the ValueGeneratedNever option on your entity properties. This ensures both MySQL and SQL Server schemas treat snowflake IDs as application-generated rather than database-generated values.

What database-specific adjustments are needed for MySQL in EF Core migrations?

MySQL EF Core migrations require specific adjustments for datetime mappings, character sets, boolean mappings, and long-text fields. SQL Server needs minimal adjustments compared to MySQL when generating synchronized database migrations.

Can I validate and apply EF Core migrations to MySQL and SQL Server automatically?

You can validate and apply EF Core migrations automatically using included PowerShell scripts. These scripts verify migration files and execute database updates against both MySQL and SQL Server targets.

Why do my EF Core migrations fail when using a single DbContext for both MySQL and SQL Server?

EF Core migrations fail with a single DbContext because MySQL and SQL Server require distinct provider configurations. Using separate database-specific DbContext types ensures correct schema mappings and prevents migration conflicts.