1. Flyway

Flyway database migrations module.

1.1. Usage

1) Add the dependencies (hikari + flyway):

Maven
Gradle
<!-- DataSource via HikariCP-->
<dependency>
  <groupId>io.jooby</groupId>
  <artifactId>jooby-hikari</artifactId>
  <version>3.4.3</version>
</dependency>

<!-- Flyway Module-->
<dependency>
  <groupId>io.jooby</groupId>
  <artifactId>jooby-flyway</artifactId>
  <version>3.4.3</version>
</dependency>

2) Add database driver (mySQL here):

Maven
Gradle
<dependency>
  <groupId>mysql</groupId>
  <artifactId>mysql-connector-java</artifactId>
  <version>${mysql-connector-java.version}</version>
</dependency>

3) Set database properties

application.conf
db.url = "jdbc:mysql://localhost/mydb"
db.user = myuser
db.password = mypass

4) Install and use Flyway

Java
Kotlin
import io.jooby.hikari.HikariModule;
import io.jooby.flyway.FlywayModule;

{
  install(new HikariModule());                     (1)

  install(new FlywayModule());                     (2)

}
1 Install and creates a DataSource
2 Install and run Flyway

The flyway module runs a migrate command, you can override the default command by setting the flyway.run application configuration property:

application.conf
flyway.run = migrate

Multiple commands example:

application.conf
flyway.run = [clean, migrate]

Available commands: migrate, clean, info, validate, undo, baseline and repair.

1.2. Multiple databases

Multiple databases are supported too:

Java
Kotlin
import io.jooby.hikari.HikariModule;
import io.jooby.flyway.FlywayModule;

{
  install(new HikariModule("main"));
  install(new FlywayModule("main"));

  install(new HikariModule("audit"));
  install(new FlywayModule("audit"));
}

When using multiple database you need to specify the location of the migration scripts:

application.conf
main.flyway.locations = "classpath:db/main"
audit.flyway.locations = "classpath:db/audit"