efcore icon indicating copy to clipboard operation
efcore copied to clipboard

Script all migrations into single migration per file

Open marnilss opened this issue 1 month ago • 0 comments

What problem are you trying to solve?

Hi, I want to generate script for each of the migrations into its' own script file, in my CI pipeline. It can be done by using existing CLI commands and some scripting:

Pseudo-code:
allMigrations = dotnet ef migrations list
// loop allMigrations and run
    dotnet ef migrations script allMigrations[i-1] allmigrations[i] --output allmigrations[i].sql

The problem is that this takes some time. We have ~60 migrations and even when using a compiled model, it takes about 3 seconds to script each file. Meaning about 3 minutes to script all migrations into separate files.

We want them separate, because when we CD pipeline deploy to different environments (DEVELOPMENT, TEST, ACCEPTANCETEST, PRODUCTION), they are all running different database version, and require a unique set of migrations applied.

Describe the solution you'd like

So I would like an option like this, to specify a folder where it should place all files: dotnet ef migrations script --output-dir "migrations-scripts"

Given two migrations: 20251201143245_Initial, 20251202154255_Second, the output in the folder would be: migrations-scripts/20251201143245_Initial.sql migrations-scripts/20251202154255_Second.sql

marnilss avatar Dec 10 '25 14:12 marnilss