How to roll back migrations using Flyway?

前端 未结 3 1886
醉话见心
醉话见心 2020-12-12 23:49

MyBatis migrations splits each SQL file into two sections:

  1. One for migrating forward one version
  2. One for migrating back one version

How

3条回答
  •  半阙折子戏
    2020-12-13 00:16

    I assume you need a rollback strategy, when e.g. a partner fails at production stage and his deployment is essential for your release.

    You could name your flyway SQL scripts like these:
    V< YourReleaseNumber >.000_< description >.sql

    Now you can leave
    V< YourReleaseNumber >.998_rollback.sql for rollback
    and make V< YourReleaseNumber >.999_reenroll.sql to reenroll.

    In your CI/CD Environment you need 2 more Jobs (manually triggered) after your deployment job. One for rollback, which runs the rollback process including flyway migrate. Other for reenroll.
    You just have to care for the target configuration in flyway.
    For your deployment job your target should be < YourReleaseNumber >.997
    For your rollback job < YourReleaseNumber >.998

    When you start a new release, make sure you won't run the rollback/reenroll script of the old release.

    As said before a well tested, backup and restore strategy is the recommended solution.

    (sry for bad english)

提交回复
热议问题