Class Flyway
- java.lang.Object
-
- org.flywaydb.core.Flyway
-
public class Flyway extends java.lang.ObjectThis is the centre point of Flyway, and for most users, the only class they will ever have to deal with.It is THE public API from which all important Flyway functions such as clean, validate and migrate can be called.
To get started all you need to do is
Flyway flyway = Flyway.configure().dataSource(url, user, password).load(); flyway.migrate();
-
-
Constructor Summary
Constructors Constructor Description Flyway(Configuration configuration)Creates a new instance of Flyway with this configuration.
-
Method Summary
Modifier and Type Method Description voidbaseline()Baselines an existing database, excluding all migrations up to and including baselineVersion.voidclean()Drops all objects (tables, views, procedures, triggers, ...) in the configured schemas.static FluentConfigurationconfigure()This is your starting point.static FluentConfigurationconfigure(java.lang.ClassLoader classLoader)This is your starting point.ConfigurationgetConfiguration()MigrationInfoServiceinfo()Retrieves the complete information about all the migrations including applied, pending and current migrations with details and status.intmigrate()Starts the database migration.voidrepair()Repairs the Flyway schema history table.intundo()Undoes the most recently applied versioned migration.voidvalidate()Validate applied migrations against resolved ones (on the filesystem or classpath) to detect accidental changes that may prevent the schema(s) from being recreated exactly.
-
-
-
Constructor Detail
-
Flyway
public Flyway(Configuration configuration)
Creates a new instance of Flyway with this configuration. In general the Flyway.configure() factory method should be preferred over this constructor, unless you need to create or reuse separate Configuration objects.- Parameters:
configuration- The configuration to use.
-
-
Method Detail
-
configure
public static FluentConfiguration configure()
This is your starting point. This creates a configuration which can be customized to your needs before being loaded into a new Flyway instance using the load() method.In its simplest form, this is how you configure Flyway with all defaults to get started:
Flyway flyway = Flyway.configure().dataSource(url, user, password).load();
After that you have a fully-configured Flyway instance at your disposal which can be used to invoke Flyway functionality such as migrate() or clean().
- Returns:
- A new configuration from which Flyway can be loaded.
-
configure
public static FluentConfiguration configure(java.lang.ClassLoader classLoader)
This is your starting point. This creates a configuration which can be customized to your needs before being loaded into a new Flyway instance using the load() method.In its simplest form, this is how you configure Flyway with all defaults to get started:
Flyway flyway = Flyway.configure().dataSource(url, user, password).load();
After that you have a fully-configured Flyway instance at your disposal which can be used to invoke Flyway functionality such as migrate() or clean().
- Parameters:
classLoader- The class loader to use when loading classes and resources.- Returns:
- A new configuration from which Flyway can be loaded.
-
getConfiguration
public Configuration getConfiguration()
- Returns:
- The configuration that Flyway is using.
-
migrate
public int migrate() throws FlywayExceptionStarts the database migration. All pending migrations will be applied in order. Calling migrate on an up-to-date database has no effect.

- Returns:
- The number of successfully applied migrations.
- Throws:
FlywayException- when the migration failed.
-
undo
public int undo() throws FlywayExceptionUndoes the most recently applied versioned migration. If target is specified, Flyway will attempt to undo versioned migrations in the order they were applied until it hits one with a version below the target. If there is no versioned migration to undo, calling undo has no effect.
Flyway Pro and Flyway Enterprise only

- Returns:
- The number of successfully undone migrations.
- Throws:
FlywayException- when the undo failed.
-
validate
public void validate() throws FlywayExceptionValidate applied migrations against resolved ones (on the filesystem or classpath) to detect accidental changes that may prevent the schema(s) from being recreated exactly.
Validation fails if
- differences in migration names, types or checksums are found
- versions have been applied that aren't resolved locally anymore
- versions have been resolved that haven't been applied yet

- Throws:
FlywayException- when the validation failed.
-
clean
public void clean()
Drops all objects (tables, views, procedures, triggers, ...) in the configured schemas. The schemas are cleaned in the order specified by the
schemasproperty.
- Throws:
FlywayException- when the clean fails.
-
info
public MigrationInfoService info()
Retrieves the complete information about all the migrations including applied, pending and current migrations with details and status.

- Returns:
- All migrations sorted by version, oldest first.
- Throws:
FlywayException- when the info retrieval failed.
-
baseline
public void baseline() throws FlywayExceptionBaselines an existing database, excluding all migrations up to and including baselineVersion.

- Throws:
FlywayException- when the schema baselining failed.
-
repair
public void repair() throws FlywayExceptionRepairs the Flyway schema history table. This will perform the following actions:- Remove any failed migrations on databases without DDL transactions (User objects left behind must still be cleaned up manually)
- Realign the checksums, descriptions and types of the applied migrations with the ones of the available migrations

- Throws:
FlywayException- when the schema history table repair failed.
-
-