Adding Flyway to a maven project

Add the following to your pom:


                org.flywaydb
                flyway-maven-plugin
                3.2.1
                
                    jdbc:h2:file:target/foobar
                    sa
                
                
                    
                        com.h2database
                        h2
                        1.3.170
                    
                



Note that you need to use the jdbc url, username and password of the database that you use in your application.

The database migration scripts must be located in src/main/resources/db/migration.
The script must follow the following name convention: V{version}__{description}.sql

The version may me be a single number (3214), a number separated by underscores (12_1_1) or a number separated by a dot (12.1.1). Note that there are two underscores between the {version} and {description}.

As an example, we can add this first script: src/main/resources/db/migration/V1.1__create_person_table.sql:

create table PERSON (
    ID int not null,
    NAME varchar(255) not null
);

The database can be migrated using the following command:

mvn compile flyway:migrate

When you get the error “Unable to determine URL for classpath location: db/migration”, then it probably means that the update scripts are not copied to the target folder your. You can run a “mvn install”, check if the scripts are now copied and then try again.