none
How to deploy with automatic migration enabled? RRS feed

  • Question

  • I don't understand the concept of automatic migration.

    Having set "AutomaticMigrationsEnabled = true;" in the Migrations.Configuration class I can't find the place where migration steps are stored.

    How will Entity Framework recognize the current state of a production database and update it accordingly when, e.g., my console application is run at the customers' office?

    So, basically, what do I need to deploy to have my customers merely download the latest version of my software and have the software automatically install/update the database at the customer's site automatically from any arbitrary previous (or non-existing) version of the software?

    Any information on this is very appreciated.

    Thanks,
    Axel


    Still people out there alive using the keyboard?

    Working with SQL Server/Visual Studio/Office/Windows and their poor keyboard support they seem extinct...

    Thursday, November 27, 2014 5:46 PM

Answers

  • Hello Axel,

    >>Is my assumption correct?

    Yes, it is correct.

    >>In contrast to automatic migration, how will deloyment of manual migration work?

    For manual migration, you could check this link:

    http://msdn.microsoft.com/en-us/data/jj591621.aspx

    We usually use the PMC, if without the Visual Studio, we can use the migrate.exe to apply these migrations.

    >> Above initializer won't work with manual migration, will it?

    Unfortunately, as far as I know, this initializer won't work with manual migration.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by BetterToday Monday, December 1, 2014 6:33 PM
    Monday, December 1, 2014 6:17 AM
    Moderator

All replies

  • Hello Axel,

    >>Having set "AutomaticMigrationsEnabled = true;" in the Migrations.Configuration class I can't find the place where migration steps are stored.

    As far as I know, with automatic migration, it would not generate the migration step file and it would apply the migration to database directly.

    >>How will Entity Framework recognize the current state of a production database and update it accordingly when, e.g., my console application is run at the customers' office?

    In actual, code first would also contain an edmx model while it is not shown explicitly, it stores the edmx to the Model column of the _MigrationHistory table. So it should be that every time, when we restart the application, Entity Framework would generate a model(in memory or a temp file) and compare it with the last one stored in  the Model column and generate the  update script to update database.

    >> So, basically, what do I need to deploy to have my customers merely download the…

    For this, I think the MigrateDatabaseToLatestVersion Database Initializer would be appropriate, if the database does not exist, it creates one, if there is a database, and the new application has an update mode, it would update the database automatically.

    To use it, after enabling the automatically, create a constructor and set the database initializer as below:

    public class CodeFirstContext : DbContext
    
        {
    
            public CodeFirstContext()
    
            {
    
                Database.SetInitializer<CodeFirstContext>(new MigrateDatabaseToLatestVersion<CodeFirstContext, CFs.Migrations.Configuration>());
    
            }
    
            public DbSet<A> As { get; set; }
    
        }
    

    Please have a try and if this does not work for you, please feel free let me know.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, November 28, 2014 2:10 AM
    Moderator
  • Thank you for helping me on this.

    So the following will be true:

    • When a customer downloads my software for the first time, EF creates the database and creates an entry in his/her [_MigrationHistory] table.
    • When a customer downloads an update of my software, EF compares the current model of the software with the last entry of the customer's [_MigrationHistory] table and updates the database accordingly.


    Is my assumption correct?

    In contrast to automatic migration, how will deloyment of manual migration work? Above initializer won't work with manual migration, will it?

    Your help is very much appreciated!

    Thanks,
    Axel


    Still people out there alive using the keyboard?

    Working with SQL Server/Visual Studio/Office/Windows and their poor keyboard support they seem extinct...


    • Edited by BetterToday Friday, November 28, 2014 1:59 PM
    Friday, November 28, 2014 1:58 PM
  • Hello Axel,

    >>Is my assumption correct?

    Yes, it is correct.

    >>In contrast to automatic migration, how will deloyment of manual migration work?

    For manual migration, you could check this link:

    http://msdn.microsoft.com/en-us/data/jj591621.aspx

    We usually use the PMC, if without the Visual Studio, we can use the migrate.exe to apply these migrations.

    >> Above initializer won't work with manual migration, will it?

    Unfortunately, as far as I know, this initializer won't work with manual migration.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by BetterToday Monday, December 1, 2014 6:33 PM
    Monday, December 1, 2014 6:17 AM
    Moderator
  • Excellent help. Thanks a lot!

    I don't know what PMC stands for. Would you mind giving me a quick hint on what this is?

    Thanks and cheers,
    Axel


    Still people out there alive using the keyboard?

    Working with SQL Server/Visual Studio/Office/Windows and their poor keyboard support they seem extinct...

    Monday, December 1, 2014 6:36 PM
  • Hello,

    It is a tool in Visual Studio(check this link), you could open it as:

    Click ToolS in Visual Studio -> Select NuGet Package Manager -> Click Package Manage Console.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, December 2, 2014 1:18 AM
    Moderator