Flyway with MAVEN


  • Have a project setup using MAVEN
  • The example will be connecting to a MYSQL database but FLYWAY can connect to several different types of databases

What is Quick Search?

Flyway is a tool used to manage a scheme across several developers. Using GIT or SVN flyway allows you to commit SQL that other developers will pull down and using the flyway:migrate command the needed SQL queries will be performed to their database. The process for getting FLYWAY stood up is fairy straight forward and for any further documentation can be viewed HERE.


First and for most lets add the FLYWAY plugin to our pom.xml file. So open up your pom.xml file and add the following snippet:


The above snippet is to connect to a MYSQL database however many different types of databases can be connected to. To connect to different databases you would need the change the dependency to use the correct connector for your db.



  • {IP_ADDRESS} with the ip address of your database instance.
  • {PORT_NUMBER} with the port number to connect to your database instance.
  • {DATABASE_NAME} with your database name.
  • {USERNAME} with a user to connect to the database with.
  • {PASSWORD} with the password for the user to use to connect to the database.


mvn clean package

To pull down any FLYWAY artifacts that aren’t in your local repository yet.

Next you need to create the directory:


under your “resources” directory. This is the default location of where FLYWAY is looking for new scripts to be executed.

Next up run:

mvn flyway:baseline

This command will create a new table called “scheme_versions” that FLYWAY uses to know which scripts have and have not been executed.


Now lets test it out by adding a dummy file under the “db/migrations” ┬ácalled “V1_1__Create_dummy_table.sql” with the following content in it:

create table DUMMY1 (
    ID int not null,
    NAME varchar(100) not null

Notice the same of the script. All scripts in this directory must be called “V{VERSION_NUMBER}__{DESCRIPTION_OF_SQL_SCRIPT}.sql“. FLYWAY parses the version part of the file name to keep an index of which scripts have/havent been executed yet.

To run any pending migrations (any migrations in this directory that have yet to get applied to your database) run the following command:

mvn compile flyway:migrate

And there you have it. Your project is now integrated in with FLYWAY!

Go you!