Open Closed

ABP DbMigrator - Reverting last database update (migration) #3209


User avatar
0
bozkan created

Hi,

How is it possible to revert the last database update (migration) via ABP's DbMigrator executable.

The methods over CLI and Package Manager Console were like the following, but I have no idea about doing this via executing DbMigrator.

CLI

dotnet ef database update <previous-migration-name>

Package Manager Console

PM> Update-Database <previous-migration-name>


3 Answer(s)
  • User Avatar
    0
    gterdem created
    Support Team Senior .NET Developer

    DbMigrator applies pending migrations and seeds data. It doesn't accept or use any parameter to roll back to the previous migration and remove the latest migration.

    If migration is already applied, you need to manually roll back to your desired migration:

    dotnet ef database update <migration-name-you-want-to-rollback>
    

    and remove the migration afterward:

    dotnet ef migrations remove
    
  • User Avatar
    0
    bozkan created

    Hi @gterdem, thank you for your feedback. But I think this is not a good solution in a production scenario or in a pipeline. (Since these command-line tools may not be available in some environments, and this is the most significant benefit of DbMigrator - a standard console application to do migrations)

    And if I would need to execute these ef commands manually in some scenarios, this situation seriously reduces the benefit/usefulness of DbMigrator application. As you may guess reverting a migration is almost always a requirement.

    So I think, it would be great if DbMigrator have some parameter <migration-name> and made the same reverting. Is there any roadmap to support such functionality?

  • User Avatar
    0
    gterdem created
    Support Team Senior .NET Developer

    And if I would need to execute these ef commands manually in some scenarios, this situation seriously reduces the benefit/usefulness of DbMigrator application. As you may guess reverting a migration is almost always a requirement.

    No no no. reverting a migration is almost always a requirement. this is not a correct approach. Why would you alter the Migration History? What happens when some systems already have the applied version and you present a new altered migration history to update? Since you mentioned the CI/CD pipeline, why would operation delete the migration history of an application? It is not related to the application environment at all. Furthermore, how can you version your application if you keep removing migration history?

    It is like it is named; migration history and it should be a part of your application life cycle. I am guessing it doesn't look or seem aesthetic (like DB table column order) so you keep removing migration history and re-creating a single one. This is against the very nature of code first application development.

    So I think, it would be great if DbMigrator have some parameter <migration-name> and made the same reverting. Is there any roadmap to support such functionality?

    No, because it is not DbMigrator's job description to add/remove migrations since it is directly related to Microsoft Entity Framework. Furthermore, it is used for NoSQL databases as well.

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11