New! – Spin up instant copies of your dev databases in the cloud for free Learn more

Flyway Documentation

Poll

API

Flyway brings the largest benefits when integrated within an application. By integrating Flyway you can ensure that the application and its database will always be compatible, with no manual intervention required. Flyway checks the version of the database and applies new migrations automatically before the rest of the application starts. This is important, because the database must first be migrated to a state the rest of the code can work with.

Supported Java Versions

Download

Maven
<dependency>
    <groupId>org.flywaydb</groupId>
    <artifactId>flyway-core</artifactId>
    <version>8.0.0-beta1</version>
</dependency>
Gradle
compile "org.flywaydb:flyway-core:8.0.0-beta1"
Binary flyway-core-8.0.0-beta1.jar md5 sha1
Sources flyway-core-8.0.0-beta1-sources.jar md5 sha1
Maven
<dependency>
    <groupId>org.flywaydb.enterprise</groupId>
    <artifactId>flyway-core</artifactId>
    <version>8.0.0-beta1</version>
</dependency>
Gradle
compile "org.flywaydb.enterprise:flyway-core:8.0.0-beta1"
Binary flyway-core-8.0.0-beta1.jar md5 sha1

For older versions see Accessing Older Versions of Flyway

The Flyway Class

The central piece of Flyway’s database migration infrastructure is the org.flywaydb.core.Flyway class. It is your one-stop shop for working with Flyway programmatically. It serves both as a configuration and a launching point for all of Flyway’s functions.

Programmatic Configuration (Java)

Flyway is super easy to use programmatically:

import org.flywaydb.core.Flyway;

...
Flyway flyway = Flyway.configure().dataSource(url, user, password).load();
flyway.migrate();

// Start the rest of the application (incl. Hibernate)
...
Tip: When running inside a Boxfuse instance (both locally and on AWS), Flyway will automatically use the JDBC url, user and password provided by Boxfuse.

See configuration for a full list of supported configuration parameters.

JDBC Drivers

You will need to include the relevant JDBC driver for your chosen database as a dependency in your Java project. For instance in your pom.xml for a Maven project. The version of the JDBC driver supported for each database is specified in the ‘Supported Databases’ list in the left hand side navigation menu.

Spring Configuration

As an alternative to the programmatic configuration, here is how you can configure and start Flyway in a classic Spring application using XML bean configuration:

<bean id="flywayConfig" class="org.flywaydb.core.api.configuration.ClassicConfiguration">
    <property name="dataSource" ref="..."/>
    ...
</bean>

<bean id="flyway" class="org.flywaydb.core.Flyway" init-method="migrate">
    <constructor-arg ref="flywayConfig"/>
</bean>

<!-- The rest of the application (incl. Hibernate) -->
<!-- Must be run after Flyway to ensure the database is compatible with the code -->
<bean id="sessionFactory" class="..." depends-on="flyway">
    ...
</bean>

API: Hooks