Class MigrateDb


  • public class MigrateDb
    extends Object
    This is the centre point of MigrateDB, and for most users, the only class they will ever have to deal with.

    It is THE public API from which all important MigrateDB functions such as validate and migrate can be called.

    To get started all you need to do is create a configured MigrateDb object and then invoke its principal methods.

     MigrateDb migratedb = MigrateDb.configure().dataSource(url, user, password).load();
     migratedb.migrate();
     
    Note that a configured MigrateDb object is unmodifiable.
    • Constructor Detail

      • MigrateDb

        public MigrateDb​(Configuration configuration)
        Creates a new instance of MigrateDB with this configuration. In general the MigrateDb.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 MigrateDb instance using the load() method.

        In its simplest form, this is how you configure MigrateDb with all defaults to get started:

        MigrateDb migratedb = MigrateDb.configure().dataSource(url, user, password).load();

        After that you have a fully-configured MigrateDb instance at your disposal which can be used to invoke MigrateDB functionality such as migrate().

        Returns:
        A new configuration from which MigrateDb 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 MigrateDb instance using the load() method.

        In its simplest form, this is how you configure MigrateDb with all defaults to get started:

        MigrateDb migratedb = MigrateDb.configure().dataSource(url, user, password).load();

        After that you have a fully-configured MigrateDb instance at your disposal which can be used to invoke MigrateDb functionality such as migrate().

        Parameters:
        classLoader - The class loader to use when loading classes and resources.
        Returns:
        A new configuration from which MigrateDB can be loaded.
      • getConfiguration

        public Configuration getConfiguration()
        Returns:
        A copy of the configuration that MigrateDB is using. Modifying the returned object has no effect on the configuration used by this MigrateDB instance.
      • liberate

        public LiberateResult liberate()
        Converts an existing Flyway schema history into the format used by MigrateDB. This operation does not modify the old schema history table.
        Returns:
        Summary of schema history conversion.
        Throws:
        MigrateDbException - if the conversion failed, e.g. because the schema history table used by MigrateDB already contains applied migrations.
      • migrate

        public MigrateResult migrate()

        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:
        MigrateDbException - 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:
        MigrateDbException - when the info retrieval failed.
      • validate

        public void validate()
                      throws MigrateDbException

        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:
        MigrateDbException - when the validation failed.
      • validateWithResult

        public ValidateResult validateWithResult()
                                          throws MigrateDbException

        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:
        MigrateDbException - when the validation failed.
      • baseline

        public BaselineResult baseline()
                                throws MigrateDbException

        Baselines an existing database, excluding all migrations up to and including baselineVersion.

        baseline
        Returns:
        An object summarising the actions taken
        Throws:
        MigrateDbException - when the schema baselining failed.
      • repair

        public RepairResult repair()
                            throws MigrateDbException
        Repairs the MigrateDb 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:
        MigrateDbException - when the schema history table repair failed.