-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Azure Web App migrations #3597
Comments
It may be more straightforward to have the application check and apply the migrations, rather than the publish process. This can be done, for example, by adding the following to your app startup sequence, after configuration of EF has been done.
This will check the db level using __EFMigrationHistory table and run missing increments. The migration seems to run in a transaction, so starting multiple server instances at the same time should be fine. To do this right after build, this command in the build script can be used to wake the application after publishing.
|
ADDENDA to what I wrote below: it seems that "Database.Migrate" already creates the database if it does not exist, so the call to:
Is enough. Thanks a lot! Thanks, I'll follow suggestion #1. I'm trying to call this from my ASP.NET vNext Startup.Configure() method:
It seems that the "EnsureCreated" does create the DB and it's schema, but it does not create the "EFMigrationsHistory" table. |
using (var scope = serviceProvider.GetRequiredService<IServiceScopeFactory>().CreateScope())
{
using(var context = scope.ServiceProvider.GetService<MyContext>())
{
context.Database.Migrate();
}
} Note that applying migrations at runtime is not in generally a good idea. E.g. if you have more than one Web server, this could cause multiple servers to try to update the database at the same time which will most likely cause errors and leave the database in a bad state. To the original question, we are still working in the publish story. @sayedihashimi may be able to offer more details and the timeframe. cc @rowanmiller |
Here is a slightly outdated doc that walks thru what we are building in terms of publish integration https://github.com/aspnet/EntityFramework/wiki/Visual-Studio-Publish-Integration. There are some minor technical details that are incorrect but the general flow is correct. |
Yes we are working on adding support for EF Migrations into the publish dialog now. I do not think this will make it for RC1 but should for the release after that. I just posted the spec on what we are working on at aspnet/Tooling#251. We should have the script working in a few weeks. When that happens if anyone wants to try it (without UI support) then I can describe the elements that need to be updated to get the migrations to be invoked. |
Thanks to everybody for the useful insight. @divega regarding applying migrations at runtime, what about a command line tool that executes "Database.Migrate()"? Regarding the DI scope, is it wrong to get a context in this way?
|
The main issue with running code directly in |
@divega Thanks for the details. |
Hello,
I've checked the docs but found nothing regarding the best practice for handling EF7 migrations on Azure Web App projects and I'm not sure on how to proceed. I'd like migrations to be checked and applied on publishing. Have I missed anything or are they scheduled for later release?
Thanks for any suggestion.
The text was updated successfully, but these errors were encountered: