How to execute the upgrade process for your Java program by using Flyway

In MyCollab product, we want to automate the upgrade version process. Our goal is the site administrator do not need manually perform many steps to upgrade the MyCollab to the newer version. Instead of asking site administrator perform tasks like:

  • Step 1: Go to the configure file to do blah blah
  • Step 2: Edit the database file and do blah blah blah
  • Step 3: Copy files from A to B and blah blah

We just request users to keep the same configuration files, run the newer MyCollab program and we will do all upgrade steps if needed. We know what to upgrade, and as we say the automation process will prevent the mistakes of human activities.

We have been using the toolkit named Flyway, it never make us disappointed. By default, Flyway is mainly used to migrate the database. But in our real practice, we utilize Flyway when we do any migrate data structure such as file locations, resources handling etc.

To run Flyway is simple

and below is what we configure Flyway to run in the Spring container with another bean DataSource

The migration scripts could be the SQL scripts or the Java files that keep us can control the migration process easily

  • SQL Script
  • Java file
We use Flyway to install and migrate database schema, data at the first MyCollab program and upgrade process later. Because Flyway allows using the Java program during the migration process, we usually write the Java file to perform some complex code such as migrating the resources/files locations or insert data follow on the new program logics. For instance, we change the way we handle timezone in MyCollab, and we write the associated script for that change

For instance, we change the way we handle timezone in MyCollab, and we write the associated script for that change

Naming conventions best practices

Flyway has the conventions of naming the script, it has V[version]__[Description]. It sorts the order of versions and performs the migration process base on this order. Of course, you can name the version is 001, oo2, 003 etc that keeps you can perform the migration for 999 scripts. If you use the format V1, V2, … V9 then you just perform the migration for 9 scripts because 10 is considered less than 2 in the string comparison.

My suggestion is using the version format yyyyMMdd because it reflects the day you perform the migration, and the second the sort order of scripts is always true both in the IDE and in the migration process.

Screen Shot 2016-06-16 at 3.25.47 PM

Leave a Reply

Your email address will not be published. Required fields are marked *