erikbra / grate

grate - the SQL scripts migration runner
MIT License
209 stars 40 forks source link

--drop without continuing migration use case #526

Open Jantero93 opened 6 months ago

erikbra commented 2 months ago

Hi, @Jantero93 - to try to generalise a bit, how do you run your EF migrations? It looks like the recommended way from Microsoft to run EF migrations in production is to generate SQL scripts:

https://learn.microsoft.com/en-us/ef/core/managing-schemas/migrations/applying?tabs=dotnet-core-cli

It even looks like they have some functionality similar to grate, with the Idempotent SQL scripts (same page, further down).

Microsoft says in this same page:

The EF command-line tools can be used to apply migrations to a database. While productive for local development and testing of migrations, this approach isn't ideal for managing production databases:

The SQL commands are applied directly by the tool, without giving the developer a chance to inspect or modify them. This can be dangerous in a production environment. The .NET SDK and the EF tool must be installed on production servers and requires the project's source code.

I would recommend:

Depending on the rest of your grate scripts, where they fit in with the EF migrations, you might want to use another folder than up for the EF migrations scripts, if you always want to run these before the other migrations. But I would definitely recommend using a one-time-scripts type of folder for EF migrations, as this fits well with how EF migrations work.

You can customise the grate Folder configuration completely, if you want either a simpler or more complex folder structure than the default: https://erikbra.github.io/grate/folder-configuration/