Application Integration (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.

The Flyway Class

The central piece of Flyway's database migration infrastructure is the com.googlecode.flyway.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

Flyway is super easy to use programmatically:

import com.googlecode.flyway.core.Flyway;

...

Flyway flyway = new Flyway();
flyway.setDataSource(...);
flyway.migrate();

// Start the rest of the application (incl. Hibernate)
...

Spring Configuration

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

<bean id="flyway" class="com.googlecode.flyway.core.Flyway" init-method="migrate">
    <property name="dataSource" ref="..."/>
    ...
</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>

Details

Browse the Javadoc