Reputation: 10335
I use .NET 5 (Core) for my app. I would like to know what is the best practice to allow server doing migrations script on Production ? Should I create migrations script --idempotent and run dotnet ef database update on the server ? Or should I give the client pieces of migration scripts and do the update on there ? Should I put automating the migrationscript on the compiled app ?
Upvotes: 1
Views: 956
Reputation: 566
Here's the Microsoft documentation about migrations in production.
You can call the Database.Migrate();
inside the constructor of your Db Context class or in the dependency inversion process create a scope of the Db Context class and call:
var db = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
db.Database.Migrate();
But, be aware of the warning:
Upvotes: 3