Flyway

The Flyway extension module provides a very thin layer to use Spring Boot’s integration with Flyway

Setup

Dependency Management

Add a section for Flyway's own BOM:

pom.xml
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.apache.causeway.extensions</groupId>
            <artifactId>causeway-extensions-flyway</artifactId>
            <scope>import</scope>
            <type>pom</type>
            <version>2.0.0-RC1</version>
        </dependency>
    </dependencies>
</dependencyManagement>

Dependencies

In the webapp module of your application, add the following dependency:

pom.xml
<dependencies>
    <dependency>
        <groupId>org.apache.causeway.extensions</groupId>
        <artifactId>causeway-extensions-flyway-impl</artifactId>
    </dependency>
</dependencies>

Update AppManifest

Also add the following module to your AppManifest:

@Configuration
@Import({
    ...
    CausewayModuleExtFlywayImpl.class,
    ...
})
public static class AppManifest {
}

Configuration Properties

Configure Flyway connection parameters:

application.properties
spring.flyway.enabled=true
spring.flyway.default-schema=SIMPLE             (1)
spring.flyway.schemas=SIMPLE                    (2)
spring.flyway.create-schemas=true               (3)

causeway.persistence.schema.auto-create-schemas=    (4)
1 the default schema managed by Flyway (containing the schema_version table); see flyway.defaultSchema config property (Flyway docs) for more info
2 all of the schemas managed by Flyway; see flyway.schemas config property (Flyway docs) for more info
3 whether Flyway should automatically create schemas ; see flyway.createSchemas for more info
4 instruct Apache Causeway to not attempt to create schemas

The ORM should also be configured to not automatically create tables:

  • if using JPA/Eclipselink, then:

    application.properties
    eclipselink.ddl-generation=none
  • if using JDO/DataNucleus, then:

    application.properties
    datanucleus.schema.autoCreateAll=false

Managing different variants

When running with an in-memory object store - either for prototyping or integration tests - you will need the database tables to be created first.

In normal circumstances this is most easily accomplished with the ORM automatically creating the tables (and Flyway disabled).

However, if you want your tests to check your Flyway scripts beforehand, there is nothing to prevent you from using Flyway all the time, even for integration tests. One point to be aware of though is that the DDL syntax may vary between an in-memory database (such as H2) and a typical production database (such as PostgreSQL or SQL Server).

Luckily, Spring Boot’s Flyway integration allows different variants of scripts for different vendors to be stored, in db.migration.{vendor} package (where {vendor} is as defined by the DatabaseDriver class). The simpleapp starter app also provides an example of this.

See also