-
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
Migrations: Improve existing database support #2167
Comments
This need came up while prototyping the solutions for aspnet/Identity#457. In that particular scenario a few new columns need to be added to the database as part of the upgrade, which may or may not pose an additional challenge. In general EF Core Migrations cannot predict the current schema of a database regardless of how it was created and whether there are additional model changes in the upgrade. Even if the database was maintained using EF6 Migrations there are functional differences between the stacks that will make the database look different. Here is a set of ideas we talked about that could be used to address this:
As @bricelam mentioned above, the database could have been created using EF6 Migrations in which case we will need to do something with the migrations history table, i.e. we either make the EF Core table compatible with the EF6 one in which case we can simply add a new row or we may have to drop/move the table and existing migration history rows somewhere else. |
Noticed this issue has the pri0 but hasn't been assigned. Assigning to @bricelam since he owns our migrations story. |
Also, note that the proposal described in a previous comment should be much easier to implement if the IModel that is the output of the reverse engineering pipeline used the same annotations and other constructs that a regular model produced by code first would use (see #2714). |
Decided we will handle this with docs. Because there are so many nuances to how you might want it to work, we don't think we can build a high level feature that just works. We may drive improvements to the building blocks as we write the docs. |
Is there any current guidance for porting/migrating ASP.NET MVC Identity 2 sites with existing databases ( and migrations ) to use Identity 3? |
The EF6 documentation Code First Migrations with an existing database is still relevant. The |
Although there are a few more steps involved since the ASP.NET Identity schema also changed. @HaoK, is there a script somewhere to migrate from v2 to v3? |
No script currently, @ToddThomson can you try out the prerelease compat package to migrate (assuming your app looks fairly similar to the Identity 2 template app)?
|
Will Visual Studio's reverse engineer (model from database) wizard come back (anytime soon) for Asp.Net Core web apps? Cuz we need it, we Visual Studio developers |
@HaoK I take it that you can start with the generic ASP.NET MVC Web Application with Nuget package Identity 2.2.1 installed. The AspNet.Identity.CoreCompat must then be a nuget package? I cannot locate this package name. Where can this package be found? |
@hoak I get the following error during the install of AspNetCoreCompat: Failed to add reference. The package 'Microsoft.AspNet.Identity.AspNetCoreCompat' tried to add a framework reference to 'System.Collections' which was not found in the GAC. This is possibly a bug in the package. Please contact the package owners for assistance. |
Hrm package might not be updated correctly, in the mean time you can just try manually picking up the files it includes in your project and seeing if migrations works once you have your Identity POCOs derive from them (all these do is add the V3 schema changes basically) https://github.com/aspnet/Identity/tree/dev/src/Microsoft.AspNet.Identity.AspNetCoreCompat |
@HaoK Since I couldn't install the AspNetCoreCompat package, I tried another approach. I created an ASP.NET generic web app with user accounts. I ran the web app which created the Identity v2 tables. I then created a generic ASP.NET Core web app. I used the same database connection string for both web apps. Using the ef dbcontext scaffold command I generated a dbcontext for the v2 schema and a v2 schema migration. With a few changes to the v2 schema migration class I obtained the IdentityV2Schema migration within ASP.NET Core web app. By commenting out the up method I updated the database with this migration. With the V2 schema migration I then added the IdentityV3Schema migration. The resulting migration needs to be changed slightly so that the alterations are done before the new tables are created. Updating the database now with the IdentityV3Schema migration yields a Identity V3 schema set of tables. The IdentityV3Schema migration ( v2 to v3 really ) is everything that most people would need. To login with the ASP.NET Core web app now, it appears that the dataprotection mechanism has changed. Would you please let me know how to use Identity v2 dataprotection with v3 Identity? |
@HaoK Sorry, I just notice that you posted a link to the AspNetCoreCompat source above. I see how the v2 data protection is used. |
Also worth dismissing any changes applied in the Model Snapshot just to be in sync I guess? |
There is a major issue when using plugable architectures , now the model configuration can be detached from the DbContext class and the configuration can be in a diferent .dll, we need to provide the same experience to in order to had the migration in the rights place, |
If I could +1000 this I would. Love to see something to support this soon. Maybe a starting migration parameter or a skip 1st [or list] or something. Thanks. :) |
It would be great to have some sort of equivalent functionality as the old |
We need to create a good experience to bootstrap an existing database with Migrations.
Things to consider:
The text was updated successfully, but these errors were encountered: