Wednesday, 31 October 2012

Flyway Db Migrations with Maven

Flyway is a tool that can be used to make database migrations a little easier. Heres a quick walkthrough on how to set it up with maven.

Firstly add the following to your pom:
          <!-- Fly way -->

          <!-- mysql jdbc driver -->



It isn't necessary to create a profile, you can place the setting in you global pom profile. Having a seperate profile allows to seperate the migration configurations per db and remove the migration from the main build phase making it optional. 

Migrations scripts are located under: src/main/resources/db/migration. The file names follow the default flyway conventions:

Now run the following commands to run the flyway goals to migrate the db.

mvn -PDev flyway:clean    //cleans the db (run first time)
mvn -PDev flyway:migrate  //run migration scripts

-PDev tells maven to use the dev profile

To find out more about flyway goals goto:

No comments:

Post a Comment