dotnet / dotnet/efcore

(new feature request) Script all migrations into single migration per file

Open
#37,338 2 comments 3 reactions 0 assignees View on GitHub
customer-reported
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

### 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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.