Upgrade scenario when using Flyway

2019-09-07 10:18发布

Just integrated Flyway into our app and it works great in the following situations:

  • brand new app install with empty schema, creates the schema_version table and executes the complete schema script after which app is on it's way..works great!

  • have a patch sql script, we set the version higher than the current version, patch get's applied automatically, version is incremented, no issues here!

Now the problem is the following: We have older versions of our app out there. Say our current application version is 7.5 (schema version 1.0), when a user is using 7.4 of the application (we will manually set the schema version to say 0.9) and is upgraded to 7.5 the schema upgrade to v 1.0 should be migrated using an Upgrade script rather than the complete script for an empty database. Make sense? How can I approach this scenario, it does not seem to be covered by Flyway.

In summary we have these two scenarios:

Brand new install of our app v7.5: - installation of new schema v1.0 uses MX_1_0__complete.sql

Upgrade of app from v7.4 to v7.5: - upgrade of schema from v0.9 to v1.0 should use MX_1_0__74upgrade.sql

since both target schema versions are 1.0 how does Flyway choose one over the other? In addition either only an upgrade or a complete script is to be executed depending on the existing version#, not both!! If current version is 0.9 then upgrade script to be chosen, if current version is 1.0 then nothing is to be done, if there is no current version then the complete 1.0 script to be applied to create a new schema.

Should be simple enough...

标签: flyway
1条回答
霸刀☆藐视天下
2楼-- · 2019-09-07 11:06

Always run all scripts.

  • Brand new install of v7.4: Run 0.9 script.
  • Brand new install of v7.5: Run 0.9 script and 1.0 upgrade.
  • Upgrade v7.4 to v7.5 ... : Run 1.0 upgrade.
查看更多
登录 后发表回答