Class Flyway
- java.lang.Object
-
- org.flywaydb.core.Flyway
-
public class Flyway extends Object
This 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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
baseline()
Baselines an existing database, excluding all migrations up to and including baselineVersion.void
clean()
Drops all objects (tables, views, procedures, triggers, ...) in the configured schemas.static FluentConfiguration
configure()
This is your starting point.static FluentConfiguration
configure(ClassLoader classLoader)
This is your starting point.Configuration
getConfiguration()
MigrationInfoService
info()
Retrieves the complete information about all the migrations including applied, pending and current migrations with details and status.int
migrate()
Starts the database migration.void
repair()
Repairs the Flyway schema history table.int
undo()
Undoes the most recently applied versioned migration.void
validate()
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(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 FlywayException
Starts 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 FlywayException
Undoes 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 FlywayException
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.
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
schemas
property.- 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 FlywayException
Baselines an existing database, excluding all migrations up to and including baselineVersion.
- Throws:
FlywayException
- when the schema baselining failed.
-
repair
public void repair() throws FlywayException
Repairs 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.
-
-