Class FluentConfiguration

  • All Implemented Interfaces:
    Configuration

    public class FluentConfiguration
    extends Object
    implements Configuration
    Fluent interface for MigrateDB configurations, which delegates to an instance of DefaultConfiguration. This configuration can be passed to MigrateDB using the new MigrateDb(Configuration) constructor.
    • Constructor Detail

      • FluentConfiguration

        public FluentConfiguration()
      • FluentConfiguration

        public FluentConfiguration​(@Nullable ClassLoader classLoader)
        Parameters:
        classLoader - The ClassLoader to use for loading migrations, resolvers, etc. from the classpath. (default: same as ClassUtils.defaultClassLoader() )
    • Method Detail

      • load

        public MigrateDb load()
        Returns:
        The new fully-configured MigrateDb instance.
      • getLocations

        public List<Location> getLocations()
        Specified by:
        getLocations in interface Configuration
        Returns:
        The locations to scan recursively for migrations. The location type is determined by its prefix. Unprefixed locations or locations starting with classpath: point to a package on the classpath and may contain both SQL and Java-based migrations. Locations starting with filesystem: point to a directory on the filesystem, may only contain SQL migrations and are only scanned recursively down non-hidden directories. (default: classpath:db/migration)
      • getEncoding

        public Charset getEncoding()
        Specified by:
        getEncoding in interface Configuration
        Returns:
        The encoding of SQL migrations. (default: UTF-8)
      • getDefaultSchema

        public String getDefaultSchema()
        Specified by:
        getDefaultSchema in interface Configuration
        Returns:
        The default schema managed by MigrateDB. This schema name is case-sensitive. If not specified, but schemas is, MigrateDB uses the first schema in that list. If that is also not specified, MigrateDb uses the default schema for the database connection.

        Consequences:

        • This schema will be the one containing the schema history table.
        • This schema will be the default for the database connection (provided the database supports this concept) .
        (default: The first schema specified in getSchemas(), and failing that the default schema for the database connection)
      • getSchemas

        public List<String> getSchemas()
        Specified by:
        getSchemas in interface Configuration
        Returns:
        The schemas managed by MigrateDB. These schema names are case-sensitive. If not specified, MigrateDB uses the default schema for the database connection. If defaultSchemaName is not specified, then the first of this list also acts as default schema.

        Consequences:

        • MigrateDB will automatically attempt to create all these schemas, unless they already exist.
        (default: The default schema for the database connection)
      • getTable

        public String getTable()
        Specified by:
        getTable in interface Configuration
        Returns:
        The name of the schema history table that will be used by MigrateDB. By default, (single-schema mode) the schema history table is placed in the default schema for the connection provided by the datasource. When the migratedb.schemas property is set (multi-schema mode), the schema history table is placed in the first schema of the list. (default: migratedb_state)
      • getOldTable

        public @Nullable String getOldTable()
        Specified by:
        getOldTable in interface Configuration
        Returns:
        The old table to convert into the format used by MigrateDB. Only used for the "liberate" command.
      • isLiberateOnMigrate

        public boolean isLiberateOnMigrate()
        Specified by:
        isLiberateOnMigrate in interface Configuration
        Returns:
        Whether the liberate command is automatically executed on migrate if the schema history table does not exist, but oldTable exists. (Default: true)
      • getTablespace

        public @Nullable String getTablespace()
        Specified by:
        getTablespace in interface Configuration
        Returns:
        The tablespace where to create the schema history table that will be used by MigrateDB. If not specified, MigrateDB uses the default tablespace for the database connection. This setting is only relevant for databases that do support the notion of tablespaces. Its value is simply ignored for all others.
      • getTarget

        public TargetVersion getTarget()
        Specified by:
        getTarget in interface Configuration
        Returns:
        The target version up to which MigrateDB should consider migrations. Migrations with a higher version number will be ignored. Special values:
        • current: Designates the current version of the schema
        • latest: The latest version of the schema, as defined by the migration with the highest version
        • <version>? (end with a '?'): Instructs MigrateDB not to fail if the target version doesn't exist. In this case, MigrateDB will go up to but not beyond the specified target (default: fail if the target version doesn't exist)
        Defaults to latest
      • isFailOnMissingTarget

        public boolean isFailOnMissingTarget()
        Specified by:
        isFailOnMissingTarget in interface Configuration
        Returns:
        Whether to fail if no migration with the configured target version exists (default: true)
      • getCherryPick

        public List<MigrationPattern> getCherryPick()
        Specified by:
        getCherryPick in interface Configuration
        Returns:
        The migrations that MigrateDb should consider when migrating. Leave empty to consider all available migrations. Migrations not in this list will be ignored.
      • isPlaceholderReplacement

        public boolean isPlaceholderReplacement()
        Specified by:
        isPlaceholderReplacement in interface Configuration
        Returns:
        Whether placeholders should be replaced. (default: true)
      • getSqlMigrationPrefix

        public String getSqlMigrationPrefix()
        Specified by:
        getSqlMigrationPrefix in interface Configuration
        Returns:
        The file name prefix for versioned SQL migrations. Versioned SQL migrations have the following file name structure: prefixVERSIONseparatorDESCRIPTIONsuffix, which using the defaults translates to V1.1__My_description.sql. (default: V)
      • getBaselineMigrationPrefix

        public String getBaselineMigrationPrefix()
        Specified by:
        getBaselineMigrationPrefix in interface Configuration
        Returns:
        The file name prefix for baseline migrations. Baseline migrations represent all migrations with version <= current baseline migration version while keeping older migrations if needed for upgrading older deployments. They have the following file name structure: prefixVERSIONseparatorDESCRIPTIONsuffix, which using the defaults translates to B1.1__My_description.sql. (default: B)
      • getRepeatableSqlMigrationPrefix

        public String getRepeatableSqlMigrationPrefix()
        Specified by:
        getRepeatableSqlMigrationPrefix in interface Configuration
        Returns:
        The file name prefix for repeatable SQL migrations. Repeatable SQL migrations have the following file name structure: prefixSeparatorDESCRIPTIONsuffix, which using the defaults translates to R__My_description.sql. (default: R)
      • getSqlMigrationSeparator

        public String getSqlMigrationSeparator()
        Specified by:
        getSqlMigrationSeparator in interface Configuration
        Returns:
        The file name separator for SQL migrations. SQL migrations have the following file name structure: prefixVERSIONseparatorDESCRIPTIONsuffix, which using the defaults translates to V1.1__My_description.sql. (default: __)
      • getSqlMigrationSuffixes

        public List<String> getSqlMigrationSuffixes()
        Specified by:
        getSqlMigrationSuffixes in interface Configuration
        Returns:
        The file name suffixes for SQL migrations. SQL migrations have the following file name structure: prefixVERSIONseparatorDESCRIPTIONsuffix, which using the defaults translates to V1_1__My_description.sql Multiple suffixes (like .sql,.pkg,.pkb) can be specified for easier compatibility with other tools such as editors with specific file associations. (default: .sql)
      • getJavaMigrations

        public List<JavaMigration> getJavaMigrations()
        Specified by:
        getJavaMigrations in interface Configuration
        Returns:
        The additional Java-based migrations. These are not Java-based migrations discovered through classpath scanning and instantiated by MigrateDB. Instead, these are manually added instances of JavaMigration. This is particularly useful when working with a dependency injection container, where you may want the DI container to instantiate the class and wire up its dependencies for you. An empty list if none. (default: none)
      • isIgnoreMissingMigrations

        public boolean isIgnoreMissingMigrations()
        Specified by:
        isIgnoreMissingMigrations in interface Configuration
        Returns:
        Ignore missing migrations when reading the schema history table. These are migrations that were performed by an older deployment of the application that are no longer available in this version. For example: we have migrations available on the classpath with versions 1.0 and 3.0. The schema history table indicates that a migration with version 2.0 (unknown to us) has also been applied. Instead of bombing out (fail fast) with an exception, a warning is logged and MigrateDB continues normally. This is useful for situations where one must be able to deploy a newer version of the application even though it doesn't contain migrations included with an older one anymore. Note that if the most recently applied migration is removed, MigrateDb has no way to know it is missing and will mark it as future instead. true to continue normally and log a warning, false to fail fast with an exception. (default: false)
      • isIgnoreIgnoredMigrations

        public boolean isIgnoreIgnoredMigrations()
        Specified by:
        isIgnoreIgnoredMigrations in interface Configuration
        Returns:
        Ignore ignored migrations when reading the schema history table. These are migrations that were added in between already migrated migrations in this version. For example: we have migrations available on the classpath with versions from 1.0 to 3.0. The schema history table indicates that version 1 was finished on 1.0.15, and the next one was 2.0.0. But with the next release a new migration was added to version 1: 1.0.16. Such scenario is ignored by migrate command, but by default is rejected by validate. When ignoreIgnoredMigrations is enabled, such case will not be reported by validate command. This is useful for situations where one must be able to deliver complete set of migrations in a delivery package for multiple versions of the product, and allows for further development of older versions. true to continue normally, false to fail fast with an exception. (default: false)
      • isIgnorePendingMigrations

        public boolean isIgnorePendingMigrations()
        Specified by:
        isIgnorePendingMigrations in interface Configuration
        Returns:
        Ignore pending migrations when reading the schema history table. These are migrations that are available but have not yet been applied. This can be useful for verifying that in-development migration changes don't contain any validation-breaking changes of migrations that have already been applied to a production environment, e.g. as part of a CI/CD process, without failing because of the existence of new migration versions. true to continue normally, false to fail fast with an exception. (default: false)
      • isIgnoreFutureMigrations

        public boolean isIgnoreFutureMigrations()
        Specified by:
        isIgnoreFutureMigrations in interface Configuration
        Returns:
        Ignore future migrations when reading the schema history table. These are migrations that were performed by a newer deployment of the application that are not yet available in this version. For example: we have migrations available on the classpath up to version 3.0. The schema history table indicates that a migration to version 4.0 (unknown to us) has already been applied. Instead of bombing out (fail fast) with an exception, a warning is logged and MigrateDB continues normally. This is useful for situations where one must be able to redeploy an older version of the application after the database has been migrated by a newer one. true to continue normally and log a warning, false to fail fast with an exception. (default: true)
      • getIgnoreMigrationPatterns

        public List<ValidatePattern> getIgnoreMigrationPatterns()
        Specified by:
        getIgnoreMigrationPatterns in interface Configuration
        Returns:
        Patterns of ignored migrations. Each pattern is of the form <migration_type>:<migration_state>. See the website for full details.

        Example: repeatable:missing,versioned:pending,*:failed

        (default: none)

      • isValidateMigrationNaming

        public boolean isValidateMigrationNaming()
        Specified by:
        isValidateMigrationNaming in interface Configuration
        Returns:
        Whether to validate migrations and callbacks whose scripts do not obey the correct naming convention. A failure can be useful to check that errors such as case sensitivity in migration prefixes have been corrected. false to continue normally, true to fail fast with an exception. (default: false)
      • isValidateOnMigrate

        public boolean isValidateOnMigrate()
        Specified by:
        isValidateOnMigrate in interface Configuration
        Returns:
        Whether to automatically call validate or not when running migrate. true if validate should be called. false if not. (default: true)
      • getBaselineVersion

        public Version getBaselineVersion()
        Specified by:
        getBaselineVersion in interface Configuration
        Returns:
        The version to tag an existing schema with when executing baseline. (default: 1)
      • getBaselineDescription

        public String getBaselineDescription()
        Specified by:
        getBaselineDescription in interface Configuration
        Returns:
        The description to tag an existing schema with when executing baseline. (default: << MigrateDB Baseline >>)
      • isBaselineOnMigrate

        public boolean isBaselineOnMigrate()
        Specified by:
        isBaselineOnMigrate in interface Configuration
        Returns:
        Whether to automatically call baseline when migrate is executed against a non-empty schema with no schema history table. This schema will then be initialized with the baselineVersion before executing the migrations. Only migrations above baselineVersion will then be applied.

        This is useful for initial MigrateDB production deployments on projects with an existing DB.

        Be careful when enabling this as it removes the safety net that ensures MigrateDB does not migrate the wrong database in case of a configuration mistake! (default: false)

      • isOutOfOrder

        public boolean isOutOfOrder()
        Specified by:
        isOutOfOrder in interface Configuration
        Returns:
        Whether migrations are allowed to be run "out of order". If you already have versions 1 and 3 applied, and now a version 2 is found, it will be applied too instead of being ignored. (default: false)
      • isSkipExecutingMigrations

        public boolean isSkipExecutingMigrations()
        Specified by:
        isSkipExecutingMigrations in interface Configuration
        Returns:
        Whether MigrateDB should skip actually executing the contents of the migrations and only update the schema history table. This should be used when you have applied a migration manually (via executing the sql yourself, or via an ide), and just want the schema history table to reflect this.

        Use in conjunction with cherryPick to skip specific migrations instead of all pending ones. (default: false)

      • getResolvers

        public List<MigrationResolver> getResolvers()
        Specified by:
        getResolvers in interface Configuration
        Returns:
        The custom MigrationResolvers to be used in addition to the built-in ones for resolving Migrations to apply. An empty list if none. (default: none)
      • isSkipDefaultResolvers

        public boolean isSkipDefaultResolvers()
        Specified by:
        isSkipDefaultResolvers in interface Configuration
        Returns:
        Whether default built-in resolvers should be skipped. If true, only custom resolvers are used. (default: false)
      • getDataSource

        public @Nullable ConnectionProvider getDataSource()
        Specified by:
        getDataSource in interface Configuration
        Returns:
        The data source to use to access the database. Must have the necessary privileges to execute DDL.
      • getConnectRetries

        public int getConnectRetries()
        Specified by:
        getConnectRetries in interface Configuration
        Returns:
        The maximum number of retries when attempting to connect to the database. After each failed attempt, MigrateDB will wait 1 second before attempting to connect again, up to the maximum number of times specified by * connectRetries. The interval between retries doubles with each subsequent attempt. (default: 0)
      • getConnectRetriesInterval

        public int getConnectRetriesInterval()
        Specified by:
        getConnectRetriesInterval in interface Configuration
        Returns:
        The maximum time between retries when attempting to connect to the database in seconds. This will cap the interval between connect retry to the value provided. (default: 120)
      • getInitSql

        public String getInitSql()
        Specified by:
        getInitSql in interface Configuration
        Returns:
        The SQL statements to run to initialize a new database connection immediately after opening it. (default: null)
      • getClassLoader

        public ClassLoader getClassLoader()
        Specified by:
        getClassLoader in interface Configuration
        Returns:
        The ClassLoader to use for loading migrations, resolvers, etc. from the classpath. (default: Thread.currentThread().getContextClassLoader() )
      • isMixed

        public boolean isMixed()
        Specified by:
        isMixed in interface Configuration
        Returns:
        Whether to allow mixing transactional and non-transactional statements within the same migration. Enabling this automatically causes the entire affected migration to be run without a transaction.

        Note that this is only applicable for PostgreSQL, Aurora PostgreSQL, SQL Server and SQLite which all have statements that do not run at all within a transaction. This is not to be confused with implicit transaction, as they occur in MySQL or Oracle, where even though a DDL statement was run within a transaction, the database will issue an implicit commit before and after its execution. true if mixed migrations should be allowed. false if an error should be thrown instead. (default: false)

      • getInstalledBy

        public String getInstalledBy()
        Specified by:
        getInstalledBy in interface Configuration
        Returns:
        The username that will be recorded in the schema history table as having applied the migration, or null for the current database user of the connection (default: null).
      • isGroup

        public boolean isGroup()
        Specified by:
        isGroup in interface Configuration
        Returns:
        Whether to group all pending migrations together in the same transaction when applying them (only recommended for databases with support for DDL transactions). true if migrations should be grouped. false if they should be applied individually instead. (default: false)
      • getResourceProvider

        public ResourceProvider getResourceProvider()
        Specified by:
        getResourceProvider in interface Configuration
        Returns:
        The custom ResourceProvider to be used to look up resources. If not set, the default strategy will be used. (default: null)
      • isOutputQueryResults

        public boolean isOutputQueryResults()
        Specified by:
        isOutputQueryResults in interface Configuration
        Returns:
        Whether MigrateDB should output a table with the results of queries when executing migrations. true to output the results table (default: true)
      • isCreateSchemas

        public boolean isCreateSchemas()
        Specified by:
        isCreateSchemas in interface Configuration
        Returns:
        Whether MigrateDB should attempt to create the schemas specified in the schemas property. (default: true)
      • getLockRetryCount

        public int getLockRetryCount()
        Specified by:
        getLockRetryCount in interface Configuration
        Returns:
        The maximum number of retries when trying to obtain a lock. -1 indicates attempting to repeat indefinitely.
      • isFailOnMissingLocations

        public boolean isFailOnMissingLocations()
        Specified by:
        isFailOnMissingLocations in interface Configuration
        Returns:
        Whether to fail if a location specified in the migratedb.locations option doesn't exist. (default: false)
      • getCallbacks

        public List<Callback> getCallbacks()
        Specified by:
        getCallbacks in interface Configuration
        Returns:
        The callbacks for lifecycle notifications. An empty list if none. (default: none)
      • isSkipDefaultCallbacks

        public boolean isSkipDefaultCallbacks()
        Specified by:
        isSkipDefaultCallbacks in interface Configuration
        Returns:
        Whether default built-in callbacks should be skipped. If true, only custom callbacks are used. (default: false)
      • group

        public FluentConfiguration group​(boolean group)
        Whether to group all pending migrations together in the same transaction when applying them (only recommended for databases with support for DDL transactions).
      • installedBy

        public FluentConfiguration installedBy​(String installedBy)
        The username that will be recorded in the schema history table as having applied the migration.
      • mixed

        public FluentConfiguration mixed​(boolean mixed)
        Whether to allow mixing transactional and non-transactional statements within the same migration. Enabling this automatically causes the entire affected migration to be run without a transaction.

        Note that this is only applicable for PostgreSQL, Aurora PostgreSQL, SQL Server and SQLite which all have statements that do not run at all within a transaction. This is not to be confused with implicit transaction, as they occur in MySQL or Oracle, where even though a DDL statement was run within a transaction, the database will issue an implicit commit before and after its execution.

      • ignoreMissingMigrations

        public FluentConfiguration ignoreMissingMigrations​(boolean ignoreMissingMigrations)
        Ignore missing migrations when reading the schema history table. These are migrations that were performed by an older deployment of the application that are no longer available in this version. For example: we have migrations available on the classpath with versions 1.0 and 3.0. The schema history table indicates that a migration with version 2.0 (unknown to us) has also been applied. Instead of bombing out (fail fast) with an exception, a warning is logged and MigrateDB continues normally. This is useful for situations where one must be able to deploy a newer version of the application even though it doesn't contain migrations included with an older one anymore. Note that if the most recently applied migration is removed, MigrateDb has no way to know it is missing and will mark it as future instead.
      • ignoreIgnoredMigrations

        public FluentConfiguration ignoreIgnoredMigrations​(boolean ignoreIgnoredMigrations)
        Ignore ignored migrations when reading the schema history table. These are migrations that were added in between already migrated migrations in this version. For example: we have migrations available on the classpath with versions from 1.0 to 3.0. The schema history table indicates that version 1 was finished on 1.0.15, and the next one was 2.0.0. But with the next release a new migration was added to version 1: 1.0.16. Such scenario is ignored by migrate command, but by default is rejected by validate. When ignoreIgnoredMigrations is enabled, such case will not be reported by validate command. This is useful for situations where one must be able to deliver complete set of migrations in a delivery package for multiple versions of the product, and allows for further development of older versions.
      • ignorePendingMigrations

        public FluentConfiguration ignorePendingMigrations​(boolean ignorePendingMigrations)
        Ignore pending migrations when reading the schema history table. These are migrations that are available but have not yet been applied. This can be useful for verifying that in-development migration changes don't contain any validation-breaking changes of migrations that have already been applied to a production environment, e.g. as part of a CI/CD process, without failing because of the existence of new migration versions.
      • ignoreFutureMigrations

        public FluentConfiguration ignoreFutureMigrations​(boolean ignoreFutureMigrations)
        Whether to ignore future migrations when reading the schema history table. These are migrations that were performed by a newer deployment of the application that are not yet available in this version. For example: we have migrations available on the classpath up to version 3.0. The schema history table indicates that a migration to version 4.0 (unknown to us) has already been applied. Instead of bombing out (fail fast) with an exception, a warning is logged and MigrateDB continues normally. This is useful for situations where one must be able to redeploy an older version of the application after the database has been migrated by a newer one.
      • ignoreMigrationPatternsAsStrings

        public FluentConfiguration ignoreMigrationPatternsAsStrings​(String... ignoreMigrationPatterns)
        Ignore migrations that match this list of patterns when validating migrations. Each pattern is of the form <migration_type>:<migration_state>. See the website for full details.

        Example: repeatable:missing,versioned:pending,*:failed

      • ignoreMigrationPatternsAsStrings

        public FluentConfiguration ignoreMigrationPatternsAsStrings​(Collection<String> ignoreMigrationPatterns)
        Ignore migrations that match this list of patterns when validating migrations. Each pattern is of the form <migration_type>:<migration_state>. See the website for full details.

        Example: repeatable:missing,versioned:pending,*:failed

      • ignoreMigrationPatterns

        public FluentConfiguration ignoreMigrationPatterns​(ValidatePattern... ignoreMigrationPatterns)
        Ignore migrations that match this array of ValidatePatterns when validating migrations.
      • ignoreMigrationPatterns

        public FluentConfiguration ignoreMigrationPatterns​(Collection<ValidatePattern> ignoreMigrationPatterns)
        Ignore migrations that match this array of ValidatePatterns when validating migrations.
      • validateMigrationNaming

        public FluentConfiguration validateMigrationNaming​(boolean validateMigrationNaming)
        Whether to validate migrations and callbacks whose scripts do not obey the correct naming convention. A failure can be useful to check that errors such as case sensitivity in migration prefixes have been corrected.
      • validateOnMigrate

        public FluentConfiguration validateOnMigrate​(boolean validateOnMigrate)
        Whether to automatically call validate or not when running migrate.
      • locations

        public FluentConfiguration locations​(String... locations)
        Sets the locations to scan recursively for migrations. The location type is determined by its prefix. Unprefixed locations or locations starting with classpath: point to a package on the classpath and may contain both SQL and Java-based migrations. Locations starting with filesystem: point to a directory on the filesystem, may only contain SQL migrations and are only scanned recursively down non-hidden directories.
      • locations

        public FluentConfiguration locations​(Location... locations)
        Sets the locations to scan recursively for migrations. The location type is determined by its prefix. Unprefixed locations or locations starting with classpath: point to a package on the classpath and may contain both SQL and Java-based migrations. Locations starting with filesystem: point to a directory on the filesystem, may only contain SQL migrations and are only scanned recursively down non-hidden directories.
      • locations

        public FluentConfiguration locations​(Collection<Location> locations)
        Sets the locations to scan recursively for migrations. The location type is determined by its prefix. Unprefixed locations or locations starting with classpath: point to a package on the classpath and may contain both SQL and Java-based migrations. Locations starting with filesystem: point to a directory on the filesystem, may only contain SQL migrations and are only scanned recursively down non-hidden directories.
      • defaultSchema

        public FluentConfiguration defaultSchema​(String schema)
        Sets the default schema managed by MigrateDB. This schema name is case-sensitive. If not specified, but schemas is, MigrateDB uses the first schema in that list. If that is also not specified, MigrateDB uses the default schema for the database connection.

        Consequences:

        • This schema will be the one containing the schema history table.
        • This schema will be the default for the database connection (provided the database supports this concept) .
      • schemas

        public FluentConfiguration schemas​(String... schemas)
        Sets the schemas managed by MigrateDB. These schema names are case-sensitive. If not specified, MigrateDB uses the default schema for the database connection. If defaultSchemaName is not specified, then the first of this list also acts as default schema.

        Consequences:

        • MigrateDB will automatically attempt to create all these schemas, unless they already exist.
      • schemas

        public FluentConfiguration schemas​(Collection<String> schemas)
        Sets the schemas managed by MigrateDB. These schema names are case-sensitive. If not specified, MigrateDB uses the default schema for the database connection. If defaultSchemaName is not specified, then the first of this list also acts as default schema.

        Consequences:

        • MigrateDB will automatically attempt to create all these schemas, unless they already exist.
      • table

        public FluentConfiguration table​(String table)
        Sets the name of the schema history table that will be used by MigrateDB. By default (single-schema mode) the schema history table is placed in the default schema for the connection provided by the datasource. When the migratedb.schemas property is set (multi-schema mode), the schema history table is placed in the first schema of the list.
      • oldTable

        public FluentConfiguration oldTable​(String oldTable)
        Sets the name of the old table to convert into the format used by MigrateDB. Only used for the "liberate" command.
      • liberateOnMigrate

        public FluentConfiguration liberateOnMigrate​(boolean liberateOnMigrate)
        Whether the liberate command is automatically executed on migrate if the schema history table does not exist, but oldTable exists. (Default: true)
      • tablespace

        public FluentConfiguration tablespace​(@Nullable String tablespace)
        Sets the tablespace where to create the schema history table that will be used by MigrateDB. If not specified, MigrateDB uses the default tablespace for the database connection. This setting is only relevant for databases that do support the notion of tablespaces. Its value is simply ignored for all others.
      • target

        public FluentConfiguration target​(TargetVersion target)
        Sets the target version up to which MigrateDB should consider migrations. Migrations with a higher version number will be ignored. Special values:
        • current: Designates the current version of the schema
        • latest: The latest version of the schema, as defined by the migration with the highest version
        • next: The next version of the schema, as defined by the first pending migration
        Defaults to latest.
      • target

        public FluentConfiguration target​(Version target)
        Sets the target version up to which MigrateDB should consider migrations.
      • target

        public FluentConfiguration target​(String target)
        Sets the target version up to which MigrateDB should consider migrations. Migrations with a higher version number will be ignored. Special values:
        • current: Designates the current version of the schema
        • latest: The latest version of the schema, as defined by the migration with the highest version
        • next: The next version of the schema, as defined by the first pending migration
        • <version>? (end with a '?'): Instructs MigrateDB not to fail if the target version doesn't exist. In this case, MigrateDb will go up to but not beyond the specified target (default: fail if the target version doesn't exist)
        Defaults to latest.
      • cherryPick

        public FluentConfiguration cherryPick​(MigrationPattern... cherryPick)
        Sets the migrations that MigrateDB should consider when migrating. Leave empty to consider all available migrations. Migrations not in this list will be ignored.
      • cherryPick

        public FluentConfiguration cherryPick​(Collection<MigrationPattern> cherryPick)
        Sets the migrations that MigrateDB should consider when migrating. Leave empty to consider all available migrations. Migrations not in this list will be ignored.
      • cherryPick

        public FluentConfiguration cherryPick​(String... cherryPickAsString)
        Sets the migrations that MigrateDB should consider when migrating. Leave empty to consider all available migrations. Migrations not in this list will be ignored. Values should be the version for versioned migrations (e.g. 1, 2.4, 6.5.3) or the description for repeatable migrations (e.g. Insert_Data, Create_Table)
      • placeholderReplacement

        public FluentConfiguration placeholderReplacement​(boolean placeholderReplacement)
        Sets whether placeholders should be replaced.
      • placeholderPrefix

        public FluentConfiguration placeholderPrefix​(String placeholderPrefix)
        Sets the prefix of every placeholder.
      • placeholderSuffix

        public FluentConfiguration placeholderSuffix​(String placeholderSuffix)
        Sets the suffix of every placeholder.
      • scriptPlaceholderPrefix

        public FluentConfiguration scriptPlaceholderPrefix​(String scriptPlaceholderPrefix)
        Sets the prefix of every script placeholder.
      • scriptPlaceholderSuffix

        public FluentConfiguration scriptPlaceholderSuffix​(String scriptPlaceholderSuffix)
        Sets the suffix of every script placeholder.
      • sqlMigrationPrefix

        public FluentConfiguration sqlMigrationPrefix​(String sqlMigrationPrefix)
        Sets the file name prefix for SQL migrations. SQL migrations have the following file name structure: prefixVERSIONseparatorDESCRIPTIONsuffix, which using the defaults translates to V1_1__My_description.sql
      • baselineMigrationPrefix

        public FluentConfiguration baselineMigrationPrefix​(String baselineMigrationPrefix)
        Sets the file name prefix for baseline migrations. They have the following file name structure: prefixVERSIONseparatorDESCRIPTIONsuffix, which using the defaults translates to B1.1__My_description.sql
      • repeatableSqlMigrationPrefix

        public FluentConfiguration repeatableSqlMigrationPrefix​(String repeatableSqlMigrationPrefix)
        Sets the file name prefix for repeatable SQL migrations. Repeatable SQL migrations have the following file name structure: prefixSeparatorDESCRIPTIONsuffix, which using the defaults translates to R__My_description.sql
      • sqlMigrationSeparator

        public FluentConfiguration sqlMigrationSeparator​(String sqlMigrationSeparator)
        Sets the file name separator for SQL migrations. SQL migrations have the following file name structure: prefixVERSIONseparatorDESCRIPTIONsuffix, which using the defaults translates to V1_1__My_description.sql
      • sqlMigrationSuffixes

        public FluentConfiguration sqlMigrationSuffixes​(String... sqlMigrationSuffixes)
        The file name suffixes for SQL migrations. (default: .sql) SQL migrations have the following file name structure: prefixVERSIONseparatorDESCRIPTIONsuffix, which using the defaults translates to V1_1__My_description.sql Multiple suffixes (like .sql,.pkg,.pkb) can be specified for easier compatibility with other tools such as editors with specific file associations.
      • sqlMigrationSuffixes

        public FluentConfiguration sqlMigrationSuffixes​(Collection<String> sqlMigrationSuffixes)
        The file name suffixes for SQL migrations. (default: .sql) SQL migrations have the following file name structure: prefixVERSIONseparatorDESCRIPTIONsuffix, which using the defaults translates to V1_1__My_description.sql Multiple suffixes (like .sql,.pkg,.pkb) can be specified for easier compatibility with other tools such as editors with specific file associations.
      • javaMigrations

        public FluentConfiguration javaMigrations​(JavaMigration... javaMigrations)
        The additional Java-based migrations. These are not Java-based migrations discovered through classpath scanning and instantiated by MigrateDB. Instead, these are application-controlled instances of JavaMigration. This is particularly useful when working with a dependency injection container, where you may want the DI container to instantiate the class and wire up its dependencies for you.
      • javaMigrations

        public FluentConfiguration javaMigrations​(Collection<JavaMigration> javaMigrations)
        The additional Java-based migrations. These are not Java-based migrations discovered through classpath scanning and instantiated by MigrateDB. Instead, these are application-controlled instances of JavaMigration. This is particularly useful when working with a dependency injection container, where you may want the DI container to instantiate the class and wire up its dependencies for you.
      • dataSource

        public FluentConfiguration dataSource​(DataSource dataSource)
        Sets the data source to use. Must have the necessary privileges to execute DDL.
      • connectRetries

        public FluentConfiguration connectRetries​(int connectRetries)
        The maximum number of retries when attempting to connect to the database. After each failed attempt, MigrateDB will wait 1 second before attempting to connect again, up to the maximum number of times specified by connectRetries. The interval between retries doubles with each subsequent attempt.
      • connectRetriesInterval

        public FluentConfiguration connectRetriesInterval​(int connectRetriesInterval)
        The maximum time between retries when attempting to connect to the database in seconds. This will cap the interval between connect retry to the value provided.
      • initSql

        public FluentConfiguration initSql​(String initSql)
        The SQL statements to run to initialize a new database connection immediately after opening it.
      • baselineVersion

        public FluentConfiguration baselineVersion​(Version baselineVersion)
        Sets the version to tag an existing schema with when executing baseline.
      • baselineVersion

        public FluentConfiguration baselineVersion​(String baselineVersion)
        Sets the version to tag an existing schema with when executing baseline.
      • baselineDescription

        public FluentConfiguration baselineDescription​(String baselineDescription)
        Sets the description to tag an existing schema with when executing baseline.
      • baselineOnMigrate

        public FluentConfiguration baselineOnMigrate​(boolean baselineOnMigrate)
        Whether to automatically call baseline when migrate is executed against a non-empty schema with no schema history table. This schema will then be baselined with the baselineVersion before executing the migrations. Only migrations above baselineVersion will then be applied.

        This is useful for initial MigrateDB production deployments on projects with an existing DB.

        Be careful when enabling this as it removes the safety net that ensures MigrateDB does not migrate the wrong database in case of a configuration mistake!

      • outOfOrder

        public FluentConfiguration outOfOrder​(boolean outOfOrder)
        Allows migrations to be run "out of order". If you already have versions 1 and 3 applied, and now a version 2 is found, it will be applied too instead of being ignored.
      • skipExecutingMigrations

        public FluentConfiguration skipExecutingMigrations​(boolean skipExecutingMigrations)
        Whether MigrateDB should skip actually executing the contents of the migrations and only update the schema history table. This should be used when you have applied a migration manually (via executing the sql yourself, or via an ide), and just want the schema history table to reflect this.

        Use in conjunction with cherryPick to skip specific migrations instead of all pending ones.

      • skipDefaultCallbacks

        public FluentConfiguration skipDefaultCallbacks​(boolean skipDefaultCallbacks)
        Whether MigrateDB should skip the default callbacks. If true, only custom callbacks are used.
      • resolvers

        public FluentConfiguration resolvers​(MigrationResolver... resolvers)
        Sets custom MigrationResolvers to be used in addition to the built-in ones for resolving Migrations to apply.
      • resolvers

        public FluentConfiguration resolvers​(String... resolvers)
        Sets custom MigrationResolvers to be used in addition to the built-in ones for resolving Migrations to apply.
      • skipDefaultResolvers

        public FluentConfiguration skipDefaultResolvers​(boolean skipDefaultResolvers)
        Whether MigrateDB should skip the default resolvers. If true, only custom resolvers are used.
      • lockRetryCount

        public FluentConfiguration lockRetryCount​(int lockRetryCount)
        Sets the maximum number of retries when trying to obtain a lock. -1 indicates attempting to repeat indefinitely.
      • resourceProvider

        public FluentConfiguration resourceProvider​(ResourceProvider resourceProvider)
        Custom ResourceProvider to be used to look up resources. If not set, the default strategy will be used.
      • outputQueryResults

        public FluentConfiguration outputQueryResults​(boolean outputQueryResults)
        Whether MigrateDB should output a table with the results of queries when executing migrations.
      • configuration

        public FluentConfiguration configuration​(Properties properties)
        Configures MigrateDB with these properties. This overwrites any existing configuration. Property names are documented in PropertyNames. To use a custom ClassLoader, setClassLoader() must be called prior to calling this method. To support the configuration of extensions, those extensions must be activated via useExtension prior to calling this method.
        Throws:
        MigrateDbException - if the configuration fails.
      • configuration

        public FluentConfiguration configuration​(Map<String,​String> props)
        Configures MigrateDB with these properties. This overwrites any existing configuration. Property names are documented in PropertyNames. To use a custom ClassLoader, it must be passed to the MigrateDb constructor prior to calling this method. To support the configuration of extensions, those extensions must be activated via useExtension prior to calling this method.
        Throws:
        MigrateDbException - if the configuration fails.
      • createSchemas

        public FluentConfiguration createSchemas​(boolean createSchemas)
        Whether MigrateDB should attempt to create the schemas specified in the schemas property
      • failOnMissingLocations

        public FluentConfiguration failOnMissingLocations​(boolean failOnMissingLocations)
        Whether to fail if a location specified in the migratedb.locations option doesn't exist
      • useExtensions

        public FluentConfiguration useExtensions​(Iterable<MigrateDbExtension> extensions)
        Enables multiple MigrateDB extensions. This is mainly used to load extensions from the ServiceLoader facility:
        
              config.useExtensions(ServiceLoader.load(MigrateDbExtension.class, someClassLoader))