Search code examples
aspnetboilerplate

EF Core Migration with aspnetboilerplate Where to trigger context.Database.Migrate();


I need to ensure my application itself is able to upgrade his database model (apply migrations)

In the ABP architecture, where should I make the call to Migrate?

context.Database.Migrate();

As this is a call to a infraestructure logic (Entity framework Core) it should be kept out from domain services and application services.

Thanks in advance


Solution

  • Hi you can execute database migrations in PostInitialize method in EntityFrameworkCoreModule.

     public class MyApplicationEntityFrameworkCoreModule : AbpModule
        {
    
            public override void PostInitialize()
            {
                if (!SkipDbSeed)
                {
                    SeedHelper.SeedHostDb(IocManager);
                }
    
                // --> You can execute migrations here <--
            }
        }