Class FluentConfiguration
- java.lang.Object
-
- migratedb.core.api.configuration.FluentConfiguration
-
- All Implemented Interfaces:
Configuration
public class FluentConfiguration extends Object implements Configuration
Fluent configuration for MigrateDB . This is the preferred means of configuring the MigrateDB API. This configuration can be passed to MigrateDB using thenew MigrateDb(Configuration)constructor.
-
-
Constructor Summary
Constructors Constructor Description FluentConfiguration()FluentConfiguration(ClassLoader classLoader)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FluentConfigurationbaselineDescription(String baselineDescription)Sets the description to tag an existing schema with when executing baseline.FluentConfigurationbaselineMigrationPrefix(String baselineMigrationPrefix)Sets the file name prefix for baseline migrations.FluentConfigurationbaselineOnMigrate(boolean baselineOnMigrate)Whether to automatically call baseline when migrate is executed against a non-empty schema with no schema history table.FluentConfigurationbaselineVersion(String baselineVersion)Sets the version to tag an existing schema with when executing baseline.FluentConfigurationbaselineVersion(Version baselineVersion)Sets the version to tag an existing schema with when executing baseline.FluentConfigurationcallbacks(String... callbacks)Set the callbacks for lifecycle notifications.FluentConfigurationcallbacks(Callback... callbacks)Set the callbacks for lifecycle notifications.FluentConfigurationcherryPick(String... cherryPickAsString)Gets the migrations that MigrateDB should consider when migrating.FluentConfigurationcherryPick(MigrationPattern... cherryPick)Gets the migrations that MigrateDB should consider when migrating.FluentConfigurationcleanDisabled(boolean cleanDisabled)Whether to disable clean.FluentConfigurationcleanOnValidationError(boolean cleanOnValidationError)Whether to automatically call clean or not when a validation error occurs.FluentConfigurationconfiguration(Map<String,String> props)Configures MigrateDB with these properties.FluentConfigurationconfiguration(Properties properties)Configures MigrateDB with these properties.FluentConfigurationconfiguration(Configuration configuration)Configure with the same values as this existing configuration.FluentConfigurationconnectRetries(int connectRetries)The maximum number of retries when attempting to connect to the database.FluentConfigurationconnectRetriesInterval(int connectRetriesInterval)The maximum time between retries when attempting to connect to the database in seconds.FluentConfigurationcreateSchemas(boolean createSchemas)Whether MigrateDB should attempt to create the schemas specified in the schemas propertyFluentConfigurationdataSource(String url, String user, String password)Sets the datasource to use.FluentConfigurationdataSource(DataSource dataSource)Sets the datasource to use.FluentConfigurationdefaultSchema(String schema)Sets the default schema managed by MigrateDB.FluentConfigurationencoding(String encoding)Sets the encoding of SQL migrations.FluentConfigurationencoding(Charset encoding)Sets the encoding of SQL migrations.FluentConfigurationerrorOverrides(String... errorOverrides)Rules for the built-in error handler that let you override specific SQL states and errors codes in order to force specific errors or warnings to be treated as debug messages, info messages, warnings or errors.<T extends ExtensionConfig>
FluentConfigurationextensionConfig(Class<T> extensionConfigType, T value)Sets the extension config of typeT.FluentConfigurationfailOnMissingLocations(boolean failOnMissingLocations)Whether to fail if a location specified in the migratedb.locations option doesn't existStringgetBaselineDescription()Retrieves the description to tag an existing schema with when executing baseline.StringgetBaselineMigrationPrefix()The file name prefix for baseline migrations.VersiongetBaselineVersion()Retrieves the version to tag an existing schema with when executing baseline.Callback[]getCallbacks()Gets the callbacks for lifecycle notifications.MigrationPattern[]getCherryPick()Gets the migrations that MigrateDB should consider when migrating.ClassLoadergetClassLoader()Retrieves the ClassLoader to use for loading migrations, resolvers, etc. from the classpath.intgetConnectRetries()The maximum number of retries when attempting to connect to the database.intgetConnectRetriesInterval()The maximum time between retries when attempting to connect to the database in seconds.booleangetCreateSchemas()Whether MigrateDB should attempt to create the schemas specified in the schemas property.DatabaseTypeRegistergetDatabaseTypeRegister()The database type register.DataSourcegetDataSource()Retrieves the dataSource to use to access the database.StringgetDefaultSchema()The default schema managed by MigrateDB.CharsetgetEncoding()Retrieves the encoding of SQL migrations.String[]getErrorOverrides()Rules for the built-in error handler that let you override specific SQL states and errors codes in order to force specific errors or warnings to be treated as debug messages, info messages, warnings or errors.Map<Class<? extends ExtensionConfig>,? extends ExtensionConfig>getExtensionConfig()A read-only view of the extension config (by type).booleangetFailOnMissingLocations()Whether to fail if a location specified in the migratedb.locations option doesn't existbooleangetFailOnMissingTarget()Whether to fail if no migration with the configured target version exists (default:true)ValidatePattern[]getIgnoreMigrationPatterns()Ignore migrations that match this comma-separated list of patterns when validating migrations.StringgetInitSql()The SQL statements to run to initialize a new database connection immediately after opening it.StringgetInstalledBy()The username that will be recorded in the schema history table as having applied the migration.ClassProvider<JavaMigration>getJavaMigrationClassProvider()Retrieves the custom ClassProvider to be used to look upJavaMigrationclasses.JavaMigration[]getJavaMigrations()The additional Java-based migrations.Map<String,String>getJdbcProperties()Properties to pass to the JDBC driver objectSet<MigrateDbExtension>getLoadedExtensions()Unmodifiable set of extensions that have been loaded into this configuration.Location[]getLocations()Retrieves the locations to scan recursively for migrations.intgetLockRetryCount()The maximum number of retries when trying to obtain a lock. -1 indicates attempting to repeat indefinitely.LogSystemgetLogger()The log system MigrateDB should use.@Nullable StringgetOldTable()The old table to convert into the format used by MigrateDB.StringgetPassword()Retrieves the password used to construct the dataSource.StringgetPlaceholderPrefix()Retrieves the prefix of every placeholder.Map<String,String>getPlaceholders()Retrieves the map of <placeholder, replacementValue> to apply to sql migration scripts.StringgetPlaceholderSuffix()Retrieves the suffix of every placeholder.StringgetRepeatableSqlMigrationPrefix()Retrieves the file name prefix for repeatable SQL migrations.MigrationResolver[]getResolvers()Retrieves the custom MigrationResolvers to be used in addition to the built-in ones for resolving Migrations to apply.ResourceProvidergetResourceProvider()Retrieves the custom ResourceProvider to be used to look up resources.String[]getSchemas()The schemas managed by MigrateDB.StringgetScriptPlaceholderPrefix()Retrieves the prefix of every script placeholder.StringgetScriptPlaceholderSuffix()Retrieves the suffix of every script placeholder.StringgetSqlMigrationPrefix()The file name prefix for versioned SQL migrations.StringgetSqlMigrationSeparator()Retrieves the file name separator for sql migrations.String[]getSqlMigrationSuffixes()The file name suffixes for SQL migrations.StringgetTable()Retrieves the name of the schema history table that will be used by MigrateDB.StringgetTablespace()The tablespace where to create the schema history table that will be used by MigrateDB.TargetVersiongetTarget()Gets the target version up to which MigrateDB should consider migrations.StringgetUrl()Retrieves the url used to construct the dataSource.StringgetUser()Retrieves the user used to construct the dataSource.FluentConfigurationgroup(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).FluentConfigurationignoreFutureMigrations(boolean ignoreFutureMigrations)Whether to ignore future migrations when reading the schema history table.FluentConfigurationignoreIgnoredMigrations(boolean ignoreIgnoredMigrations)Ignore ignored migrations when reading the schema history table.FluentConfigurationignoreMigrationPatterns(String... ignoreMigrationPatterns)Ignore migrations that match this comma-separated list of patterns when validating migrations.FluentConfigurationignoreMigrationPatterns(ValidatePattern... ignoreMigrationPatterns)Ignore migrations that match this array of ValidatePatterns when validating migrations.FluentConfigurationignoreMissingMigrations(boolean ignoreMissingMigrations)Ignore missing migrations when reading the schema history table.FluentConfigurationignorePendingMigrations(boolean ignorePendingMigrations)Ignore pending migrations when reading the schema history table.FluentConfigurationinitSql(String initSql)The SQL statements to run to initialize a new database connection immediately after opening it.FluentConfigurationinstalledBy(String installedBy)The username that will be recorded in the schema history table as having applied the migration.booleanisBaselineOnMigrate()Whether to automatically call baseline when migrate is executed against a non-empty schema with no schema history table.booleanisCleanDisabled()Whether to disable clean.booleanisCleanOnValidationError()Whether to automatically call clean or not when a validation error occurs.booleanisGroup()Whether to group all pending migrations together in the same transaction when applying them (only recommended for databases with support for DDL transactions).booleanisIgnoreFutureMigrations()Ignore future migrations when reading the schema history table.booleanisIgnoreIgnoredMigrations()Ignore ignored migrations when reading the schema history table.booleanisIgnoreMissingMigrations()Ignore missing migrations when reading the schema history table.booleanisIgnorePendingMigrations()Ignore pending migrations when reading the schema history table.booleanisMixed()Whether to allow mixing transactional and non-transactional statements within the same migration.booleanisOutOfOrder()Allows migrations to be run "out of order".booleanisOutputQueryResults()Whether MigrateDB should output a table with the results of queries when executing migrations.booleanisPlaceholderReplacement()Checks whether placeholders should be replaced.booleanisSkipDefaultCallbacks()Whether MigrateDB should skip the default callbacks.booleanisSkipDefaultResolvers()Whether MigrateDB should skip the default resolvers.booleanisSkipExecutingMigrations()Whether MigrateDB should skip actually executing the contents of the migrations and only update the schema history table.booleanisValidateMigrationNaming()Whether to validate migrations and callbacks whose scripts do not obey the correct naming convention.booleanisValidateOnMigrate()Whether to automatically call validate or not when running migrate.FluentConfigurationjavaMigrationClassProvider(ClassProvider<JavaMigration> javaMigrationClassProvider)Custom ClassProvider to be used to look upJavaMigrationclasses.FluentConfigurationjavaMigrations(Collection<JavaMigration> javaMigrations)The additional Java-based migrations.FluentConfigurationjavaMigrations(JavaMigration... javaMigrations)The additional Java-based migrations.FluentConfigurationjdbcProperties(Map<String,String> jdbcProperties)Properties to pass to the JDBC driver objectMigrateDbload()FluentConfigurationlocations(String... locations)Sets the locations to scan recursively for migrations.FluentConfigurationlocations(Location... locations)Sets the locations to scan recursively for migrations.FluentConfigurationlockRetryCount(int lockRetryCount)FluentConfigurationlogger(String... logger)The logger(s) MigrateDB should use.FluentConfigurationlogger(LogSystem logger)The logger MigrateDB should use.FluentConfigurationmixed(boolean mixed)Whether to allow mixing transactional and non-transactional statements within the same migration.FluentConfigurationoldTable(@Nullable String oldTable)Sets the name of the old table to convert into the format used by MigrateDB.FluentConfigurationoutOfOrder(boolean outOfOrder)Allows migrations to be run "out of order".FluentConfigurationoutputQueryResults(boolean outputQueryResults)Whether MigrateDB should output a table with the results of queries when executing migrations.FluentConfigurationplaceholderPrefix(String placeholderPrefix)Sets the prefix of every placeholder.FluentConfigurationplaceholderReplacement(boolean placeholderReplacement)Sets whether placeholders should be replaced.FluentConfigurationplaceholders(Map<String,String> placeholders)Sets the placeholders to replace in sql migration scripts.FluentConfigurationplaceholderSuffix(String placeholderSuffix)Sets the suffix of every placeholder.FluentConfigurationrepeatableSqlMigrationPrefix(String repeatableSqlMigrationPrefix)Sets the file name prefix for repeatable sql migrations.FluentConfigurationresolvers(String... resolvers)Sets custom MigrationResolvers to be used in addition to the built-in ones for resolving Migrations to apply.FluentConfigurationresolvers(MigrationResolver... resolvers)Sets custom MigrationResolvers to be used in addition to the built-in ones for resolving Migrations to apply.FluentConfigurationresourceProvider(ResourceProvider resourceProvider)Custom ResourceProvider to be used to look up resources.FluentConfigurationschemas(String... schemas)Sets the schemas managed by MigrateDB.FluentConfigurationscriptPlaceholderPrefix(String scriptPlaceholderPrefix)Sets the prefix of every script placeholder.FluentConfigurationscriptPlaceholderSuffix(String scriptPlaceholderSuffix)Sets the suffix of every script placeholder.FluentConfigurationskipDefaultCallbacks(boolean skipDefaultCallbacks)Whether MigrateDB should skip the default callbacks.FluentConfigurationskipDefaultResolvers(boolean skipDefaultResolvers)Whether MigrateDB should skip the default resolvers.FluentConfigurationskipExecutingMigrations(boolean skipExecutingMigrations)Whether MigrateDB should skip actually executing the contents of the migrations and only update the schema history table.FluentConfigurationsqlMigrationPrefix(String sqlMigrationPrefix)Sets the file name prefix for sql migrations.FluentConfigurationsqlMigrationSeparator(String sqlMigrationSeparator)Sets the file name separator for sql migrations.FluentConfigurationsqlMigrationSuffixes(String... sqlMigrationSuffixes)The file name suffixes for SQL migrations.FluentConfigurationtable(String table)Sets the name of the schema history table that will be used by MigrateDB.FluentConfigurationtablespace(String tablespace)Sets the tablespace where to create the schema history table that will be used by MigrateDB.FluentConfigurationtarget(String target)Sets the target version up to which MigrateDB should consider migrations.FluentConfigurationtarget(TargetVersion target)Sets the target version up to which MigrateDB should consider migrations.FluentConfigurationtarget(Version target)Sets the target version up to which MigrateDB should consider migrations.FluentConfigurationuseExtension(MigrateDbExtension extension)Enables a single MigrateDB extension.FluentConfigurationuseExtensions(Iterable<MigrateDbExtension> extensions)Enables multiple MigrateDB extensions.FluentConfigurationvalidateMigrationNaming(boolean validateMigrationNaming)Whether to validate migrations and callbacks whose scripts do not obey the correct naming convention.FluentConfigurationvalidateOnMigrate(boolean validateOnMigrate)Whether to automatically call validate or not when running migrate.
-
-
-
Constructor Detail
-
FluentConfiguration
public FluentConfiguration()
-
FluentConfiguration
public FluentConfiguration(ClassLoader classLoader)
- Parameters:
classLoader- The ClassLoader to use for loading migrations, resolvers, etc from the classpath. (default: same asClassUtils.defaultClassLoader())
-
-
Method Detail
-
load
public MigrateDb load()
- Returns:
- The new fully-configured MigrateDb instance.
-
configuration
public FluentConfiguration configuration(Configuration configuration)
Configure with the same values as this existing configuration.
-
getLocations
public Location[] getLocations()
Description copied from interface:ConfigurationRetrieves the locations to scan recursively for migrations. The location type is determined by its prefix. Unprefixed locations or locations starting withclasspath:point to a package on the classpath and may contain both SQL and Java-based migrations. Locations starting withfilesystem:point to a directory on the filesystem, may only contain SQL migrations and are only scanned recursively down non-hidden directories.- Specified by:
getLocationsin interfaceConfiguration- Returns:
- Locations to scan recursively for migrations. (default: classpath:db/migration)
-
getEncoding
public Charset getEncoding()
Description copied from interface:ConfigurationRetrieves the encoding of SQL migrations.- Specified by:
getEncodingin interfaceConfiguration- Returns:
- The encoding of SQL migrations. (default: UTF-8)
-
getDefaultSchema
public String getDefaultSchema()
Description copied from interface:ConfigurationThe 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) .
- Specified by:
getDefaultSchemain interfaceConfiguration- Returns:
- The schemas managed by MigrateDB. (default: The first schema specified in getSchemas(), and failing that the default schema for the database connection)
-
getSchemas
public String[] getSchemas()
Description copied from interface:ConfigurationThe 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.
- The schemas will be cleaned in the order of this list.
- If MigrateDB created them, the schemas themselves will be dropped when cleaning.
- Specified by:
getSchemasin interfaceConfiguration- Returns:
- The schemas managed by MigrateDB. (default: The default schema for the database connection)
-
getTable
public String getTable()
Description copied from interface:ConfigurationRetrieves 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.- Specified by:
getTablein interfaceConfiguration- Returns:
- The name of the schema history table that will be used by MigrateDb. (default: migratedb_state)
-
getOldTable
public @Nullable String getOldTable()
Description copied from interface:ConfigurationThe old table to convert into the format used by MigrateDB. Only used for the "liberate" command.- Specified by:
getOldTablein interfaceConfiguration
-
getTablespace
public String getTablespace()
Description copied from interface:ConfigurationThe 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.- Specified by:
getTablespacein interfaceConfiguration- Returns:
- The tablespace where to create the schema history table that will be used by MigrateDb.
-
getLogger
public LogSystem getLogger()
Description copied from interface:ConfigurationThe log system MigrateDB should use.- Specified by:
getLoggerin interfaceConfiguration
-
getTarget
public TargetVersion getTarget()
Description copied from interface:ConfigurationGets 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 schemalatest: 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)
- Specified by:
getTargetin interfaceConfiguration- Returns:
- The target version up to which MigrateDB should consider migrations. Defaults to
latest
-
getFailOnMissingTarget
public boolean getFailOnMissingTarget()
Description copied from interface:ConfigurationWhether to fail if no migration with the configured target version exists (default:true)- Specified by:
getFailOnMissingTargetin interfaceConfiguration
-
getCherryPick
public MigrationPattern[] getCherryPick()
Description copied from interface:ConfigurationGets the migrations that MigrateDB should consider when migrating. Leave empty to consider all available migrations. Migrations not in this list will be ignored.- Specified by:
getCherryPickin interfaceConfiguration- Returns:
- The migrations that MigrateDb should consider when migrating.
-
isPlaceholderReplacement
public boolean isPlaceholderReplacement()
Description copied from interface:ConfigurationChecks whether placeholders should be replaced.- Specified by:
isPlaceholderReplacementin interfaceConfiguration- Returns:
- Whether placeholders should be replaced. (default: true)
-
getPlaceholders
public Map<String,String> getPlaceholders()
Description copied from interface:ConfigurationRetrieves the map of <placeholder, replacementValue> to apply to sql migration scripts.- Specified by:
getPlaceholdersin interfaceConfiguration- Returns:
- The map of <placeholder, replacementValue> to apply to sql migration scripts.
-
getPlaceholderPrefix
public String getPlaceholderPrefix()
Description copied from interface:ConfigurationRetrieves the prefix of every placeholder.- Specified by:
getPlaceholderPrefixin interfaceConfiguration- Returns:
- The prefix of every placeholder. (default: ${ )
-
getPlaceholderSuffix
public String getPlaceholderSuffix()
Description copied from interface:ConfigurationRetrieves the suffix of every placeholder.- Specified by:
getPlaceholderSuffixin interfaceConfiguration- Returns:
- The suffix of every placeholder. (default: } )
-
getScriptPlaceholderPrefix
public String getScriptPlaceholderPrefix()
Description copied from interface:ConfigurationRetrieves the prefix of every script placeholder.- Specified by:
getScriptPlaceholderPrefixin interfaceConfiguration- Returns:
- The prefix of every script placeholder. (default: FP__ )
-
getScriptPlaceholderSuffix
public String getScriptPlaceholderSuffix()
Description copied from interface:ConfigurationRetrieves the suffix of every script placeholder.- Specified by:
getScriptPlaceholderSuffixin interfaceConfiguration- Returns:
- The suffix of every script placeholder. (default: __ )
-
getSqlMigrationPrefix
public String getSqlMigrationPrefix()
Description copied from interface:ConfigurationThe 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- Specified by:
getSqlMigrationPrefixin interfaceConfiguration- Returns:
- The file name prefix for sql migrations. (default: V)
-
getBaselineMigrationPrefix
public String getBaselineMigrationPrefix()
Description copied from interface:ConfigurationThe file name prefix for baseline migrations. Baseline migrations represent all migrations withversion <= current baseline migration versionwhile keeping older migrations if needed for upgrading older deployments. They have the following file name structure: prefixVERSIONseparatorDESCRIPTIONsuffix, which using the defaults translates to SB.1__My_description.sql- Specified by:
getBaselineMigrationPrefixin interfaceConfiguration- Returns:
- The file name prefix for baseline migration. (default: B)
-
getRepeatableSqlMigrationPrefix
public String getRepeatableSqlMigrationPrefix()
Description copied from interface:ConfigurationRetrieves 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- Specified by:
getRepeatableSqlMigrationPrefixin interfaceConfiguration- Returns:
- The file name prefix for repeatable sql migrations. (default: R)
-
getSqlMigrationSeparator
public String getSqlMigrationSeparator()
Description copied from interface:ConfigurationRetrieves 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- Specified by:
getSqlMigrationSeparatorin interfaceConfiguration- Returns:
- The file name separator for sql migrations. (default: __)
-
getSqlMigrationSuffixes
public String[] getSqlMigrationSuffixes()
Description copied from interface:ConfigurationThe 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.- Specified by:
getSqlMigrationSuffixesin interfaceConfiguration- Returns:
- The file name suffixes for SQL migrations.
-
getJavaMigrations
public JavaMigration[] getJavaMigrations()
Description copied from interface:ConfigurationThe 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.- Specified by:
getJavaMigrationsin interfaceConfiguration- Returns:
- The additional Java-based migrations. An empty array if none. (default: none)
-
isIgnoreMissingMigrations
public boolean isIgnoreMissingMigrations()
Description copied from interface:ConfigurationIgnore 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.- Specified by:
isIgnoreMissingMigrationsin interfaceConfiguration- Returns:
trueto continue normally and log a warning,falseto fail fast with an exception. (default:false)
-
isIgnoreIgnoredMigrations
public boolean isIgnoreIgnoredMigrations()
Description copied from interface:ConfigurationIgnore 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.- Specified by:
isIgnoreIgnoredMigrationsin interfaceConfiguration- Returns:
trueto continue normally,falseto fail fast with an exception. (default:false)
-
isIgnorePendingMigrations
public boolean isIgnorePendingMigrations()
Description copied from interface:ConfigurationIgnore 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.- Specified by:
isIgnorePendingMigrationsin interfaceConfiguration- Returns:
trueto continue normally,falseto fail fast with an exception. (default:false)
-
isIgnoreFutureMigrations
public boolean isIgnoreFutureMigrations()
Description copied from interface:ConfigurationIgnore 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.- Specified by:
isIgnoreFutureMigrationsin interfaceConfiguration- Returns:
trueto continue normally and log a warning,falseto fail fast with an exception. (default:true)
-
getIgnoreMigrationPatterns
public ValidatePattern[] getIgnoreMigrationPatterns()
Description copied from interface:ConfigurationIgnore migrations that match this comma-separated 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
- Specified by:
getIgnoreMigrationPatternsin interfaceConfiguration
-
isValidateMigrationNaming
public boolean isValidateMigrationNaming()
Description copied from interface:ConfigurationWhether 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.- Specified by:
isValidateMigrationNamingin interfaceConfiguration- Returns:
falseto continue normally,trueto fail fast with an exception. (default:false)
-
isValidateOnMigrate
public boolean isValidateOnMigrate()
Description copied from interface:ConfigurationWhether to automatically call validate or not when running migrate.- Specified by:
isValidateOnMigratein interfaceConfiguration- Returns:
trueif validate should be called.falseif not. (default:true)
-
isCleanOnValidationError
public boolean isCleanOnValidationError()
Description copied from interface:ConfigurationWhether to automatically call clean or not when a validation error occurs. This is exclusively intended as a convenience for development. even though we strongly recommend not to change migration scripts once they have been checked into SCM and run, this provides a way of dealing with this case in a smooth manner. The database will be wiped clean automatically, ensuring that the next migration will bring you back to the state checked into SCM. Warning! Do not enable in production!- Specified by:
isCleanOnValidationErrorin interfaceConfiguration- Returns:
trueif clean should be called.falseif not. (default:false)
-
isCleanDisabled
public boolean isCleanDisabled()
Description copied from interface:ConfigurationWhether to disable clean. This is especially useful for production environments where running clean can be quite a career limiting move.- Specified by:
isCleanDisabledin interfaceConfiguration- Returns:
trueto disable clean.falseto leave it enabled. (default:true)
-
getBaselineVersion
public Version getBaselineVersion()
Description copied from interface:ConfigurationRetrieves the version to tag an existing schema with when executing baseline.- Specified by:
getBaselineVersionin interfaceConfiguration- Returns:
- The version to tag an existing schema with when executing baseline. (default: 1)
-
getBaselineDescription
public String getBaselineDescription()
Description copied from interface:ConfigurationRetrieves the description to tag an existing schema with when executing baseline.- Specified by:
getBaselineDescriptionin interfaceConfiguration- Returns:
- The description to tag an existing schema with when executing baseline. (default: << MigrateDB Baseline >>)
-
isBaselineOnMigrate
public boolean isBaselineOnMigrate()
Description copied from interface:ConfigurationWhether 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 thebaselineVersionbefore executing the migrations. Only migrations abovebaselineVersionwill 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!
- Specified by:
isBaselineOnMigratein interfaceConfiguration- Returns:
trueif baseline should be called on migrate for non-empty schemas,falseif not. (default:false)
-
isOutOfOrder
public boolean isOutOfOrder()
Description copied from interface:ConfigurationAllows 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.- Specified by:
isOutOfOrderin interfaceConfiguration- Returns:
trueif outOfOrder migrations should be applied,falseif not. (default:false)
-
isSkipExecutingMigrations
public boolean isSkipExecutingMigrations()
Description copied from interface:ConfigurationWhether 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
cherryPickto skip specific migrations instead of all pending ones.- Specified by:
isSkipExecutingMigrationsin interfaceConfiguration- Returns:
trueif executing the migrations should be skipped on migrate,falseif not. (default:false)
-
getResolvers
public MigrationResolver[] getResolvers()
Description copied from interface:ConfigurationRetrieves the custom MigrationResolvers to be used in addition to the built-in ones for resolving Migrations to apply.- Specified by:
getResolversin interfaceConfiguration- Returns:
- The custom MigrationResolvers to be used in addition to the built-in ones for resolving Migrations to apply. An empty array if none. (default: none)
-
isSkipDefaultResolvers
public boolean isSkipDefaultResolvers()
Description copied from interface:ConfigurationWhether MigrateDB should skip the default resolvers. If true, only custom resolvers are used.- Specified by:
isSkipDefaultResolversin interfaceConfiguration- Returns:
- Whether default built-in resolvers should be skipped. (default: false)
-
getUrl
public String getUrl()
Description copied from interface:ConfigurationRetrieves the url used to construct the dataSource. May be null if the dataSource was passed in directly.- Specified by:
getUrlin interfaceConfiguration- Returns:
- The url used to construct the dataSource. May be null if the dataSource was passed in directly.
-
getUser
public String getUser()
Description copied from interface:ConfigurationRetrieves the user used to construct the dataSource. May be null if the dataSource was passed in directly, or if dataSource did not need a user.- Specified by:
getUserin interfaceConfiguration- Returns:
- The user used to construct the dataSource. May be null if the dataSource was passed in directly, or if dataSource did not need a user.
-
getPassword
public String getPassword()
Description copied from interface:ConfigurationRetrieves the password used to construct the dataSource. May be null if the dataSource was passed in directly, or if dataSource did not need a password.- Specified by:
getPasswordin interfaceConfiguration- Returns:
- The password used to construct the dataSource. May be null if the dataSource was passed in directly, or if dataSource did not need a password.
-
getDataSource
public DataSource getDataSource()
Description copied from interface:ConfigurationRetrieves the dataSource to use to access the database. Must have the necessary privileges to execute DDL.- Specified by:
getDataSourcein interfaceConfiguration- Returns:
- The dataSource to use to access the database. Must have the necessary privileges to execute DDL.
-
getConnectRetries
public int getConnectRetries()
Description copied from interface:ConfigurationThe 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.- Specified by:
getConnectRetriesin interfaceConfiguration- Returns:
- The maximum number of retries when attempting to connect to the database. (default: 0)
-
getConnectRetriesInterval
public int getConnectRetriesInterval()
Description copied from interface:ConfigurationThe 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.- Specified by:
getConnectRetriesIntervalin interfaceConfiguration- Returns:
- The maximum time between retries in seconds (default: 120)
-
getInitSql
public String getInitSql()
Description copied from interface:ConfigurationThe SQL statements to run to initialize a new database connection immediately after opening it.- Specified by:
getInitSqlin interfaceConfiguration- Returns:
- The SQL statements. (default:
null)
-
getClassLoader
public ClassLoader getClassLoader()
Description copied from interface:ConfigurationRetrieves the ClassLoader to use for loading migrations, resolvers, etc. from the classpath.- Specified by:
getClassLoaderin interfaceConfiguration- Returns:
- The ClassLoader to use for loading migrations, resolvers, etc. from the classpath. (default: Thread.currentThread().getContextClassLoader() )
-
isMixed
public boolean isMixed()
Description copied from interface:ConfigurationWhether 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.
- Specified by:
isMixedin interfaceConfiguration- Returns:
trueif mixed migrations should be allowed.falseif an error should be thrown instead. (default:false)
-
getInstalledBy
public String getInstalledBy()
Description copied from interface:ConfigurationThe username that will be recorded in the schema history table as having applied the migration.- Specified by:
getInstalledByin interfaceConfiguration- Returns:
- The username or
nullfor the current database user of the connection. (default:null).
-
isGroup
public boolean isGroup()
Description copied from interface:ConfigurationWhether to group all pending migrations together in the same transaction when applying them (only recommended for databases with support for DDL transactions).- Specified by:
isGroupin interfaceConfiguration- Returns:
trueif migrations should be grouped.falseif they should be applied individually instead. (default:false)
-
getErrorOverrides
public String[] getErrorOverrides()
Description copied from interface:ConfigurationRules for the built-in error handler that let you override specific SQL states and errors codes in order to force specific errors or warnings to be treated as debug messages, info messages, warnings or errors.Each error override has the following format:
STATE:12345:W. It is a 5 character SQL state (or * to match all SQL states), a colon, the SQL error code (or * to match all SQL error codes), a colon and finally the desired behavior that should override the initial one.The following behaviors are accepted:
Dto force a debug messageD-to force a debug message, but do not show the original sql state and error codeIto force an info messageI-to force an info message, but do not show the original sql state and error codeWto force a warningW-to force a warning, but do not show the original sql state and error codeEto force an errorE-to force an error, but do not show the original sql state and error code
Example 1: to force Oracle stored procedure compilation issues to produce errors instead of warnings, the following errorOverride can be used:
99999:17110:EExample 2: to force SQL Server PRINT messages to be displayed as info messages (without SQL state and error code details) instead of warnings, the following errorOverride can be used:
S0001:0:I-Example 3: to force all errors with SQL error code 123 to be treated as warnings instead, the following errorOverride can be used:
*:123:W- Specified by:
getErrorOverridesin interfaceConfiguration- Returns:
- The ErrorOverrides or an empty array if none are defined. (default: none)
-
getResourceProvider
public ResourceProvider getResourceProvider()
Description copied from interface:ConfigurationRetrieves the custom ResourceProvider to be used to look up resources. If not set, the default strategy will be used.- Specified by:
getResourceProviderin interfaceConfiguration- Returns:
- The custom ResourceProvider to be used to look up resources (default: null)
-
getJavaMigrationClassProvider
public ClassProvider<JavaMigration> getJavaMigrationClassProvider()
Description copied from interface:ConfigurationRetrieves the custom ClassProvider to be used to look upJavaMigrationclasses. If not set, the default strategy will be used.- Specified by:
getJavaMigrationClassProviderin interfaceConfiguration- Returns:
- The custom ClassProvider to be used to look up
JavaMigrationclasses (default: null)
-
isOutputQueryResults
public boolean isOutputQueryResults()
Description copied from interface:ConfigurationWhether MigrateDB should output a table with the results of queries when executing migrations.- Specified by:
isOutputQueryResultsin interfaceConfiguration- Returns:
trueto output the results table (default:true)
-
getCreateSchemas
public boolean getCreateSchemas()
Description copied from interface:ConfigurationWhether MigrateDB should attempt to create the schemas specified in the schemas property.- Specified by:
getCreateSchemasin interfaceConfiguration- Returns:
trueto attempt to create the schemas (default:true)
-
getLockRetryCount
public int getLockRetryCount()
Description copied from interface:ConfigurationThe maximum number of retries when trying to obtain a lock. -1 indicates attempting to repeat indefinitely.- Specified by:
getLockRetryCountin interfaceConfiguration
-
getJdbcProperties
public Map<String,String> getJdbcProperties()
Description copied from interface:ConfigurationProperties to pass to the JDBC driver object- Specified by:
getJdbcPropertiesin interfaceConfiguration- Returns:
- Properties that will be passed to the JDBC driver object
-
getFailOnMissingLocations
public boolean getFailOnMissingLocations()
Description copied from interface:ConfigurationWhether to fail if a location specified in the migratedb.locations option doesn't exist- Specified by:
getFailOnMissingLocationsin interfaceConfiguration- Returns:
trueto fail (default:false)
-
getDatabaseTypeRegister
public DatabaseTypeRegister getDatabaseTypeRegister()
Description copied from interface:ConfigurationThe database type register.- Specified by:
getDatabaseTypeRegisterin interfaceConfiguration
-
getLoadedExtensions
public Set<MigrateDbExtension> getLoadedExtensions()
Description copied from interface:ConfigurationUnmodifiable set of extensions that have been loaded into this configuration.- Specified by:
getLoadedExtensionsin interfaceConfiguration
-
getExtensionConfig
public Map<Class<? extends ExtensionConfig>,? extends ExtensionConfig> getExtensionConfig()
Description copied from interface:ConfigurationA read-only view of the extension config (by type).- Specified by:
getExtensionConfigin interfaceConfiguration
-
errorOverrides
public FluentConfiguration errorOverrides(String... errorOverrides)
Rules for the built-in error handler that let you override specific SQL states and errors codes in order to force specific errors or warnings to be treated as debug messages, info messages, warnings or errors.Each error override has the following format:
STATE:12345:W. It is a 5 character SQL state (or * to match all SQL states), a colon, the SQL error code (or * to match all SQL error codes), a colon and finally the desired behavior that should override the initial one.The following behaviors are accepted:
Dto force a debug messageD-to force a debug message, but do not show the original sql state and error codeIto force an info messageI-to force an info message, but do not show the original sql state and error codeWto force a warningW-to force a warning, but do not show the original sql state and error codeEto force an errorE-to force an error, but do not show the original sql state and error code
Example 1: to force Oracle stored procedure compilation issues to produce errors instead of warnings, the following errorOverride can be used:
99999:17110:EExample 2: to force SQL Server PRINT messages to be displayed as info messages (without SQL state and error code details) instead of warnings, the following errorOverride can be used:
S0001:0:I-Example 3: to force all errors with SQL error code 123 to be treated as warnings instead, the following errorOverride can be used:
*:123:W- Parameters:
errorOverrides- The ErrorOverrides or an empty array if none are defined. (default: none)
-
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).- Parameters:
group-trueif migrations should be grouped.falseif they should be applied individually instead. (default:false)
-
installedBy
public FluentConfiguration installedBy(String installedBy)
The username that will be recorded in the schema history table as having applied the migration.- Parameters:
installedBy- The username ornullfor the current database user of the connection. (default:null).
-
logger
public FluentConfiguration logger(LogSystem logger)
The logger MigrateDB should use.
-
logger
public FluentConfiguration logger(String... logger)
The logger(s) MigrateDB should use.
-
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.
- Parameters:
mixed-trueif mixed migrations should be allowed.falseif an error should be thrown instead. (default:false)
-
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.- Parameters:
ignoreMissingMigrations-trueto continue normally and log a warning,falseto fail fast with an exception. (default:false)
-
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.- Parameters:
ignoreIgnoredMigrations-trueto continue normally,falseto fail fast with an exception. (default:false)
-
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.- Parameters:
ignorePendingMigrations-trueto continue normally,falseto fail fast with an exception. (default:false)
-
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.- Parameters:
ignoreFutureMigrations-trueto continue normally and log a warning,falseto fail fast with an exception. (default:true)
-
ignoreMigrationPatterns
public FluentConfiguration ignoreMigrationPatterns(String... ignoreMigrationPatterns)
Ignore migrations that match this comma-separated 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.
-
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.- Parameters:
validateMigrationNaming-falseto continue normally,trueto fail fast with an exception. (default:false)
-
validateOnMigrate
public FluentConfiguration validateOnMigrate(boolean validateOnMigrate)
Whether to automatically call validate or not when running migrate.- Parameters:
validateOnMigrate-trueif validate should be called.falseif not. (default:true)
-
cleanOnValidationError
public FluentConfiguration cleanOnValidationError(boolean cleanOnValidationError)
Whether to automatically call clean or not when a validation error occurs. This is exclusively intended as a convenience for development. even though we strongly recommend not to change migration scripts once they have been checked into SCM and run, this provides a way of dealing with this case in a smooth manner. The database will be wiped clean automatically, ensuring that the next migration will bring you back to the state checked into SCM. Warning! Do not enable in production!- Parameters:
cleanOnValidationError-trueif clean should be called.falseif not. (default:false)
-
cleanDisabled
public FluentConfiguration cleanDisabled(boolean cleanDisabled)
Whether to disable clean. This is especially useful for production environments where running clean can be quite a career limiting move.- Parameters:
cleanDisabled-trueto disable clean.falseto leave it enabled. (default:false)
-
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 withclasspath:point to a package on the classpath and may contain both SQL and Java-based migrations. Locations starting withfilesystem:point to a directory on the filesystem, may only contain SQL migrations and are only scanned recursively down non-hidden directories.- Parameters:
locations- Locations to scan recursively for migrations. (default: db/migration)
-
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 withclasspath:point to a package on the classpath and may contain both SQL and Java-based migrations. Locations starting withfilesystem:point to a directory on the filesystem, may only contain SQL migrations and are only scanned recursively down non-hidden directories.- Parameters:
locations- Locations to scan recursively for migrations. (default: db/migration)
-
encoding
public FluentConfiguration encoding(String encoding)
Sets the encoding of SQL migrations.- Parameters:
encoding- The encoding of SQL migrations. (default: UTF-8)
-
encoding
public FluentConfiguration encoding(Charset encoding)
Sets the encoding of SQL migrations.- Parameters:
encoding- The encoding of SQL migrations. (default: UTF-8)
-
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) .
- Parameters:
schema- The default schema managed by MigrateDb.
-
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.
- The schemas will be cleaned in the order of this list.
- If MigrateDB created them, the schemas themselves will be dropped when cleaning.
- Parameters:
schemas- The schemas managed by MigrateDb. May not benull. Must contain at least one element.
-
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.- Parameters:
table- The name of the schema history table that will be used by MigrateDB. (default: migratedb_state)
-
oldTable
public FluentConfiguration oldTable(@Nullable String oldTable)
Sets the name of the old table to convert into the format used by MigrateDB. Only used for the "liberate" command.- Parameters:
oldTable- Name of old table to convert.
-
tablespace
public FluentConfiguration tablespace(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.- Parameters:
tablespace- The tablespace where to create the schema history table that will be used by MigrateDb.
-
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 schemalatest: The latest version of the schema, as defined by the migration with the highest versionnext: The next version of the schema, as defined by the first pending migration
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 schemalatest: The latest version of the schema, as defined by the migration with the highest versionnext: 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)
latest.
-
cherryPick
public FluentConfiguration cherryPick(MigrationPattern... cherryPick)
Gets 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)
Gets 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.- Parameters:
placeholderReplacement- Whether placeholders should be replaced. (default: true)
-
placeholders
public FluentConfiguration placeholders(Map<String,String> placeholders)
Sets the placeholders to replace in sql migration scripts.- Parameters:
placeholders- The map of <placeholder, replacementValue> to apply to sql migration scripts.
-
placeholderPrefix
public FluentConfiguration placeholderPrefix(String placeholderPrefix)
Sets the prefix of every placeholder.- Parameters:
placeholderPrefix- The prefix of every placeholder. (default: ${ )
-
placeholderSuffix
public FluentConfiguration placeholderSuffix(String placeholderSuffix)
Sets the suffix of every placeholder.- Parameters:
placeholderSuffix- The suffix of every placeholder. (default: } )
-
scriptPlaceholderPrefix
public FluentConfiguration scriptPlaceholderPrefix(String scriptPlaceholderPrefix)
Sets the prefix of every script placeholder.- Parameters:
scriptPlaceholderPrefix- The prefix of every placeholder. (default: FP__ )
-
scriptPlaceholderSuffix
public FluentConfiguration scriptPlaceholderSuffix(String scriptPlaceholderSuffix)
Sets the suffix of every script placeholder.- Parameters:
scriptPlaceholderSuffix- The suffix of every script placeholder. (default: __ )
-
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- Parameters:
sqlMigrationPrefix- The file name prefix for sql migrations (default: V)
-
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- Parameters:
baselineMigrationPrefix- The file name prefix for baseline migrations (default: B)
-
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- Parameters:
repeatableSqlMigrationPrefix- The file name prefix for repeatable sql migrations (default: R)
-
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- Parameters:
sqlMigrationSeparator- The file name separator for sql migrations (default: __)
-
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.- Parameters:
sqlMigrationSuffixes- The file name suffixes for SQL migrations.
-
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.- Parameters:
javaMigrations- The additional Java-based migrations. An empty array if none. (default: none)
-
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.- Parameters:
javaMigrations- The additional Java-based migrations. An empty array if none. (default: none)
-
dataSource
public FluentConfiguration dataSource(DataSource dataSource)
Sets the datasource to use. Must have the necessary privileges to execute DDL.- Parameters:
dataSource- The datasource to use. Must have the necessary privileges to execute DDL.
-
dataSource
public FluentConfiguration dataSource(String url, String user, String password)
Sets the datasource to use. Must have the necessary privileges to execute DDL.- Parameters:
url- The JDBC URL of the database.user- The user of the database.password- The password of the database.
-
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.- Parameters:
connectRetries- The maximum number of retries (default: 0).
-
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.- Parameters:
connectRetriesInterval- The maximum time between retries in seconds (default: 120).
-
initSql
public FluentConfiguration initSql(String initSql)
The SQL statements to run to initialize a new database connection immediately after opening it.- Parameters:
initSql- The SQL statements. (default:null)
-
baselineVersion
public FluentConfiguration baselineVersion(Version baselineVersion)
Sets the version to tag an existing schema with when executing baseline.- Parameters:
baselineVersion- The version to tag an existing schema with when executing baseline. (default: 1)
-
baselineVersion
public FluentConfiguration baselineVersion(String baselineVersion)
Sets the version to tag an existing schema with when executing baseline.- Parameters:
baselineVersion- The version to tag an existing schema with when executing baseline. (default: 1)
-
baselineDescription
public FluentConfiguration baselineDescription(String baselineDescription)
Sets the description to tag an existing schema with when executing baseline.- Parameters:
baselineDescription- The description to tag an existing schema with when executing baseline. (default: << MigrateDb 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 thebaselineVersionbefore executing the migrations. Only migrations abovebaselineVersionwill 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!
- Parameters:
baselineOnMigrate-trueif baseline should be called on migrate for non-empty schemas,falseif not. (default:false)
-
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.- Parameters:
outOfOrder-trueif outOfOrder migrations should be applied,falseif not. (default:false)
-
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
cherryPickto skip specific migrations instead of all pending ones.
-
getCallbacks
public Callback[] getCallbacks()
Gets the callbacks for lifecycle notifications.- Specified by:
getCallbacksin interfaceConfiguration- Returns:
- The callbacks for lifecycle notifications. An empty array if none. (default: none)
-
isSkipDefaultCallbacks
public boolean isSkipDefaultCallbacks()
Description copied from interface:ConfigurationWhether MigrateDB should skip the default callbacks. If true, only custom callbacks are used.- Specified by:
isSkipDefaultCallbacksin interfaceConfiguration- Returns:
- Whether default built-in callbacks should be skipped. (default: false)
-
callbacks
public FluentConfiguration callbacks(Callback... callbacks)
Set the callbacks for lifecycle notifications.- Parameters:
callbacks- The callbacks for lifecycle notifications. (default: none)
-
callbacks
public FluentConfiguration callbacks(String... callbacks)
Set the callbacks for lifecycle notifications.- Parameters:
callbacks- The fully qualified class names, or full qualified package to scan, of the callbacks for lifecycle notifications. (default: none)
-
skipDefaultCallbacks
public FluentConfiguration skipDefaultCallbacks(boolean skipDefaultCallbacks)
Whether MigrateDB should skip the default callbacks. If true, only custom callbacks are used.- Parameters:
skipDefaultCallbacks- Whether default built-in callbacks should be skipped. (default: false)
-
resolvers
public FluentConfiguration resolvers(MigrationResolver... resolvers)
Sets custom MigrationResolvers to be used in addition to the built-in ones for resolving Migrations to apply.- Parameters:
resolvers- The custom MigrationResolvers to be used in addition to the built-in ones for resolving Migrations to apply. (default: empty list)
-
resolvers
public FluentConfiguration resolvers(String... resolvers)
Sets custom MigrationResolvers to be used in addition to the built-in ones for resolving Migrations to apply.- Parameters:
resolvers- The fully qualified class names of the custom MigrationResolvers to be used in addition to the built-in ones for resolving Migrations to apply. (default: empty list)
-
skipDefaultResolvers
public FluentConfiguration skipDefaultResolvers(boolean skipDefaultResolvers)
Whether MigrateDB should skip the default resolvers. If true, only custom resolvers are used.- Parameters:
skipDefaultResolvers- Whether default built-in resolvers should be skipped. (default: false)
-
lockRetryCount
public FluentConfiguration lockRetryCount(int lockRetryCount)
-
jdbcProperties
public FluentConfiguration jdbcProperties(Map<String,String> jdbcProperties)
Properties to pass to the JDBC driver object- Parameters:
jdbcProperties- The properties to pass to the JDBC driver object
-
extensionConfig
public <T extends ExtensionConfig> FluentConfiguration extensionConfig(Class<T> extensionConfigType, T value)
Sets the extension config of typeT.
-
resourceProvider
public FluentConfiguration resourceProvider(ResourceProvider resourceProvider)
Custom ResourceProvider to be used to look up resources. If not set, the default strategy will be used.- Parameters:
resourceProvider- Custom ResourceProvider to be used to look up resources
-
javaMigrationClassProvider
public FluentConfiguration javaMigrationClassProvider(ClassProvider<JavaMigration> javaMigrationClassProvider)
Custom ClassProvider to be used to look upJavaMigrationclasses. If not set, the default strategy will be used.- Parameters:
javaMigrationClassProvider- Custom ClassProvider to be used to look upJavaMigrationclasses.
-
outputQueryResults
public FluentConfiguration outputQueryResults(boolean outputQueryResults)
Whether MigrateDB should output a table with the results of queries when executing migrations.- Parameters:
outputQueryResults-trueto output a table with the results of queries when executing migrations. (default:true)
-
configuration
public FluentConfiguration configuration(Properties properties)
Configures MigrateDB with these properties. This overwrites any existing configuration. Property names are documented inPropertyNames. 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 viauseExtensionprior to calling this method.- Parameters:
properties- Properties used for configuration.- Throws:
MigrateDbException- when the configuration failed.
-
configuration
public FluentConfiguration configuration(Map<String,String> props)
Configures MigrateDB with these properties. This overwrites any existing configuration. Property names are documented inPropertyNames. 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 viauseExtensionprior to calling this method.- Parameters:
props- Properties used for configuration.- Throws:
MigrateDbException- when the configuration failed.
-
createSchemas
public FluentConfiguration createSchemas(boolean createSchemas)
Whether MigrateDB should attempt to create the schemas specified in the schemas property- Parameters:
createSchemas-trueto attempt to create the schemas (default:true)
-
failOnMissingLocations
public FluentConfiguration failOnMissingLocations(boolean failOnMissingLocations)
Whether to fail if a location specified in the migratedb.locations option doesn't exist- Returns:
trueto fail (default:false)
-
useExtension
public FluentConfiguration useExtension(MigrateDbExtension extension)
Enables a single MigrateDB extension.
-
useExtensions
public FluentConfiguration useExtensions(Iterable<MigrateDbExtension> extensions)
Enables multiple MigrateDB extensions. This is mainly used to load extensions from theServiceLoaderfacility:config.useExtensions(ServiceLoader.load(MigrateDbExtension.class, someClassLoader))
-
-