Class Flyway


  • public class Flyway
    extends java.lang.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 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
      BaselineResult baseline()
      Baselines an existing database, excluding all migrations up to and including baselineVersion.
      CleanResult clean()
      Drops all objects (tables, views, procedures, triggers, ...) in the configured schemas.
      static FluentConfiguration configure()
      This is your starting point.
      static FluentConfiguration configure​(java.lang.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.
      MigrateResult migrate()
      Starts the database migration.
      RepairResult repair()
      Repairs the Flyway schema history table.
      UndoResult 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.
      ValidateResult 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 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 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 the validation failed.
      • 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 UndoResult 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.