Open Closed

How to use the Database Migration System for EF Core? #5985


User avatar
0
a3x created
  • ABP Framework version: v7.4.3
  • UI Type: MVC
  • Database System: EF Core (SQL Server)
  • Tiered (for MVC) or Auth Server Separated (for Angular): no

You describe the new database migration system here: https://blog.abp.io/abp/ABP.IO-Platform-7-4-RC-Has-Been-Published I like to auto migrate my application on startup, however, the description is not total clear for me. Can you please bring an example how to implement it in a normal MVC application?


5 Answer(s)
  • User Avatar
    0
    Anjali_Musmade created
    Support Team Support Team Member

    If you are using abp suite after performing package install at front end it will prompt on abp suite browser window like you want to add migration. If going through command line then you can do manually https://docs.abp.io/en/commercial/latest/getting-started-running-solution?UI=MVC&DB=EF&Tiered=No#running-the-dbmigrator

  • User Avatar
    0
    a3x created

    I know, however, in the post mentioned above you describe the new feature "In this version, ABP Framework provides base classes and events to migrate the database schema and seed the database on application startup. This system works compatibly with multi-tenancy and whenever a new tenant is created or a tenant's database connection string has been updated, it checks and applies database migrations for the new tenant state."

    I like to have an practical example here how to implement it :)

  • User Avatar
    0
    Anjali_Musmade created
    Support Team Support Team Member

    While creating new project with abp suite added connection string

    After downloading project on abp suite window got prompt message for migration of initial data.

    Is this you want or I am missing something?

  • User Avatar
    0
    a3x created

    In the article you describe: < In this version, ABP Framework provides base classes and events to migrate the database schema and seed the database on application startup. This system works compatibly with multi-tenancy and whenever a new tenant is created or a tenant's database connection string has been updated, it checks and applies database migrations for the new tenant state.

    This system is especially useful to migrate databases for microservices. In this way, when you deploy a new version of a microservice, you don't need to manually migrate its database.

    You need to take the following actions to use the database migration system:

    Create a class that derives from EfCoreRuntimeDatabaseMigratorBase class, override and implement its SeedAsync method. And lastly, execute the CheckAndApplyDatabaseMigrationsAsync method of your class in the OnPostApplicationInitializationAsync method of your module class. Create a class that derives from DatabaseMigrationEventHandlerBase class, override and implement its SeedAsync method. Then, whenever a new tenant is created or a tenant's connection string is changed then the SeedAsync method will be executed. >

    I like to see a practcal implementation how to implement the described steps in a MVC application.

  • User Avatar
    0
    EngincanV created
    Support Team .NET Developer

    In the article you describe: < > In this version, ABP Framework provides base classes and events to migrate the database schema and seed the database on application startup. This system works compatibly with multi-tenancy and whenever a new tenant is created or a tenant's database connection string has been updated, it checks and applies database migrations for the new tenant state.

    This system is especially useful to migrate databases for microservices. In this way, when you deploy a new version of a microservice, you don't need to manually migrate its database.

    You need to take the following actions to use the database migration system:

    Create a class that derives from EfCoreRuntimeDatabaseMigratorBase class, override and implement its SeedAsync method. And lastly, execute the CheckAndApplyDatabaseMigrationsAsync method of your class in the OnPostApplicationInitializationAsync method of your module class. Create a class that derives from DatabaseMigrationEventHandlerBase class, override and implement its SeedAsync method. Then, whenever a new tenant is created or a tenant's connection string is changed then the SeedAsync method will be executed.

    I like to see a practcal implementation how to implement the described steps in a MVC application.

    Hi, here is the issue of this feature: https://github.com/abpframework/abp/pull/16862

    You need to do the steps mentioned in the issue and then execute the CheckAndApplyDatabaseMigrationsAsync method of your class that derives from the EfCoreRuntimeDatabaseMigratorBase class in the OnPostApplicationInitializationAsync method of your module class:

Made with ❤️ on ABP v9.1.0-preview. Updated on December 10, 2024, 06:38