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 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 Details

    • 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 Details

    • 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.
    • 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

      public MigrateResult 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. migrate
      Returns:
      An object summarising the successfully applied migrations.
      Throws:
      FlywayException - when the migration failed.
    • info

      public MigrationInfoService info()
      Retrieves the complete information about all the migrations including applied, pending and current migrations with details and status. info
      Returns:
      All migrations sorted by version, oldest first.
      Throws:
      FlywayException - when the info retrieval failed.
    • clean

      public CleanResult clean()
      Drops all objects (tables, views, procedures, triggers, ...) in the configured schemas. The schemas are cleaned in the order specified by the schemas property. clean
      Returns:
      An object summarising the actions taken
      Throws:
      FlywayException - when the clean fails.
    • 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
      validate
      Throws:
      FlywayException - when something went wrong during validation.
      FlywayValidateException - when the validation failed.
    • validateWithResult

      public ValidateResult validateWithResult() 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
      validate
      Returns:
      An object summarising the validation results
      Throws:
      FlywayException - when something went wrong during validation.
    • baseline

      public BaselineResult baseline() throws FlywayException
      Baselines an existing database, excluding all migrations up to and including baselineVersion. baseline
      Returns:
      An object summarising the actions taken
      Throws:
      FlywayException - when the schema baseline failed.
    • repair

      public RepairResult 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
      repair
      Returns:
      An object summarising the actions taken
      Throws:
      FlywayException - when the schema history table repair failed.
    • undo

      public OperationResult 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 Teams only undo
      Returns:
      An object summarising the successfully undone migrations.
      Throws:
      FlywayException - when undo failed.
    • setFlywayTelemetryManager

      @Deprecated public void setFlywayTelemetryManager(org.flywaydb.core.FlywayTelemetryManager flywayTelemetryManager)
      Deprecated.