Package org.flywaydb.core
Class Flyway
java.lang.Object
org.flywaydb.core.Flyway
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 create a configured Flyway object and then invoke its principal methods.
Flyway flyway = Flyway.configure().dataSource(url, user, password).load(); flyway.migrate();Note that a configured Flyway object is immutable. If you change the configuration you will end up creating a new Flyway object.
-
Constructor Summary
ConstructorDescriptionFlyway
(Configuration configuration) Creates a new instance of Flyway with this configuration. -
Method Summary
Modifier and TypeMethodDescriptionbaseline()
Baselines an existing database, excluding all migrations up to and including baselineVersion.clean()
Drops all objects (tables, views, procedures, triggers, ...) in the configured schemas.static FluentConfiguration
This is your starting point.static FluentConfiguration
configure
(ClassLoader classLoader) This is your starting point.<T extends org.flywaydb.core.extensibility.ConfigurationExtension>
TgetConfigurationExtension
(Class<T> configClass) info()
Retrieves the complete information about all the migrations including applied, pending and current migrations with details and status.migrate()
Starts the database migration.repair()
Repairs the Flyway schema history table.void
setFlywayTelemetryManager
(org.flywaydb.core.FlywayTelemetryManager flywayTelemetryManager) Deprecated.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.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 Details
-
Flyway
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 Details
-
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
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
- Returns:
- The configuration that Flyway is using.
-
getConfigurationExtension
public <T extends org.flywaydb.core.extensibility.ConfigurationExtension> T getConfigurationExtension(Class<T> configClass) - Returns:
- The configuration extension type requested from the plugin register.
-
migrate
Starts the database migration. All pending migrations will be applied in order. Calling migrate on an up-to-date database has no effect.- Returns:
- An object summarising the successfully applied migrations.
- Throws:
FlywayException
- when the migration failed.
-
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.
-
clean
Drops all objects (tables, views, procedures, triggers, ...) in the configured schemas. The schemas are cleaned in the order specified by theschemas
property.- Returns:
- An object summarising the actions taken
- Throws:
FlywayException
- when the clean fails.
-
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. 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 something went wrong during validation.FlywayValidateException
- when the validation failed.
-
validateWithResult
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
- Returns:
- An object summarising the validation results
- Throws:
FlywayException
- when something went wrong during validation.
-
baseline
Baselines an existing database, excluding all migrations up to and including baselineVersion.- Returns:
- An object summarising the actions taken
- Throws:
FlywayException
- when the schema baseline failed.
-
repair
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
- Returns:
- An object summarising the actions taken
- Throws:
FlywayException
- when the schema history table repair failed.
-
undo
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 Teams only- Returns:
- An object summarising the successfully undone migrations.
- Throws:
FlywayException
- when undo failed.
-
setFlywayTelemetryManager
@Deprecated public void setFlywayTelemetryManager(org.flywaydb.core.FlywayTelemetryManager flywayTelemetryManager) Deprecated.
-