public class FlywayCustomization extends Object
Because of https://github.com/flyway/flyway/issues/1078 we have to customize FLyway to be able to replace default migration resolvers
Constructor and Description |
---|
FlywayCustomization() |
Modifier and Type | Method and Description |
---|---|
void |
baseline()
<p>Baselines an existing database, excluding all migrations up to and including baselineVersion.
|
void |
clean()
<p>Drops all objects (tables, views, procedures, triggers, …) in the configured schemas.
|
void |
configure(Properties properties)
Configures Flyway with these properties.
|
String |
getBaselineDescription()
Retrieves the description to tag an existing schema with when executing baseline.
|
org.flywaydb.core.api.MigrationVersion |
getBaselineVersion()
Retrieves the version to tag an existing schema with when executing baseline.
|
org.flywaydb.core.api.callback.FlywayCallback[] |
getCallbacks()
Gets the callbacks for lifecycle notifications.
|
DataSource |
getDataSource()
Retrieves the dataSource to use to access the database.
|
String |
getEncoding()
Retrieves the encoding of Sql migrations.
|
String[] |
getLocations()
Retrieves the locations to scan recursively for migrations.
|
String |
getTable()
<p>Retrieves the name of the schema metadata table that will be used by Flyway.
|
org.flywaydb.core.api.MigrationVersion |
getTarget()
Retrieves the target version up to which Flyway should consider migrations.
|
org.flywaydb.core.api.MigrationInfoService |
info()
<p>Retrieves the complete information about all the migrations including applied, pending and current migrations with details and status.
|
void |
init()
Deprecated.
Use baseline() instead. Will be removed in Flyway 4.0.
|
int |
migrate()
<p>Starts the database migration.
|
void |
setBaselineDescription(String baselineDescription)
Sets the description to tag an existing schema with when executing baseline.
|
void |
setBaselineOnMigrate(boolean baselineOnMigrate)
<p> Whether to automatically call baseline when migrate is executed against a non-empty schema with no metadata table.
|
void |
setBaselineVersion(org.flywaydb.core.api.MigrationVersion baselineVersion)
Sets the version to tag an existing schema with when executing baseline.
|
void |
setBaselineVersionAsString(String baselineVersion)
Sets the version to tag an existing schema with when executing baseline.
|
void |
setCallbacks(org.flywaydb.core.api.callback.FlywayCallback... callbacks)
Set the callbacks for lifecycle notifications.
|
void |
setCallbacksAsClassNames(String... callbacks)
Set the callbacks for lifecycle notifications.
|
void |
setCleanOnValidationError(boolean cleanOnValidationError)
Whether to automatically call clean or not when a validation error occurs.
|
void |
setDataSource(DataSource dataSource)
Sets the datasource to use.
|
void |
setDataSource(String url,
String user,
String password,
String... initSqls)
Sets the datasource to use.
|
void |
setEncoding(String encoding)
Sets the encoding of Sql migrations.
|
void |
setIgnoreFailedFutureMigration(boolean ignoreFailedFutureMigration)
Ignores failed future migrations when reading the metadata table.
|
void |
setLocations(String... locations)
Sets the locations to scan recursively for migrations.
|
void |
setOutOfOrder(boolean outOfOrder)
Allows migrations to be run "out of order".
|
void |
setPlaceholderPrefix(String placeholderPrefix)
Sets the prefix of every placeholder.
|
void |
setPlaceholders(Map<String,String> placeholders)
Sets the placeholders to replace in sql migration scripts.
|
void |
setPlaceholderSuffix(String placeholderSuffix)
Sets the suffix of every placeholder.
|
void |
setResolvers(org.flywaydb.core.api.resolver.MigrationResolver... resolvers)
Sets custom MigrationResolvers to be used in addition to the built-in ones for resolving Migrations to apply.
|
void |
setResolversAsClassNames(String... resolvers)
Sets custom MigrationResolvers to be used in addition to the built-in ones for resolving Migrations to apply.
|
void |
setSchemas(String... schemas)
Sets the schemas managed by Flyway.
|
void |
setSqlMigrationPrefix(String sqlMigrationPrefix)
Sets the file name prefix for sql migrations.
|
void |
setSqlMigrationSeparator(String sqlMigrationSeparator)
Sets the file name separator for sql migrations.
|
void |
setSqlMigrationSuffix(String sqlMigrationSuffix)
Sets the file name suffix for sql migrations.
|
void |
setTable(String table)
<p>Sets the name of the schema metadata table that will be used by Flyway.
|
void |
setTarget(org.flywaydb.core.api.MigrationVersion target)
Sets the target version up to which Flyway should consider migrations.
|
void |
setTarget(String target)
Deprecated.
Will be removed in Flyway 4.0. Use setTargetAsString(String) instead.
|
void |
setTransactionManager(org.springframework.transaction.PlatformTransactionManager transactionManager)
Set the transaction manager to use for transaction handling.
|
void |
setValidateOnMigrate(boolean validateOnMigrate)
Whether to automatically call validate or not when running migrate.
|
void |
validate()
<p>Validate applied migration with classpath migrations to detect accidental changes.
|
public String getEncoding()
Retrieves the encoding of Sql migrations.
public String getTable()
<p>Retrieves the name of the schema metadata table that will be used by Flyway.</p><p> By default (single-schema mode) the metadata table is placed in the default schema for the connection provided by the datasource. </p> <p> When the <i>flyway.schemas</i> property is set (multi-schema mode), the metadata table is placed in the first schema of the list. </p>
public org.flywaydb.core.api.MigrationVersion getTarget()
Retrieves the target version up to which Flyway should consider migrations. Migrations with a higher version number will be ignored. The special value current
designates the current version of the schema.
public org.flywaydb.core.api.MigrationVersion getBaselineVersion()
Retrieves the version to tag an existing schema with when executing baseline.
public String getBaselineDescription()
Retrieves the description to tag an existing schema with when executing baseline.
public DataSource getDataSource()
Retrieves the dataSource to use to access the database. Must have the necessary privileges to execute ddl.
public void setIgnoreFailedFutureMigration(boolean ignoreFailedFutureMigration)
Ignores failed future migrations when reading the metadata 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 metadata table indicates that a migration to version 4.0 (unknown to us) has already been attempted and failed. Instead of bombing out (fail fast) with an exception, a warning is logged and Flyway terminates normally. This is useful for situations where a database rollback is not an option. An older version of the application can then be redeployed, even though a newer one failed due to a bad migration.
ignoreFailedFutureMigration
- true
to terminate normally and log a warning, false
to fail fast with an exception. (default: false
)public void setValidateOnMigrate(boolean validateOnMigrate)
Whether to automatically call validate or not when running migrate.
validateOnMigrate
- true
if validate should be called. false
if not. (default: true
)public void setCleanOnValidationError(boolean cleanOnValidationError)
Whether to automatically call clean or not when a validation error occurs. <p> This is exclusively intended as a convenience for development. Even tough 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.</p> <p><b>Warning ! Do not enable in production !</b></p>
cleanOnValidationError
- true
if clean should be called. false
if not. (default: false
)public void setLocations(String... locations)
Sets the locations to scan recursively for migrations. <p/> <p>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 and may only contain sql migrations.</p>
locations
- Locations to scan recursively for migrations. (default: db/migration)public String[] getLocations()
Retrieves the locations to scan recursively for migrations. <p/> <p>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 and may only contain sql migrations.</p>
public void setEncoding(String encoding)
Sets the encoding of Sql migrations.
encoding
- The encoding of Sql migrations. (default: UTF-8)public void setSchemas(String... schemas)
Sets the schemas managed by Flyway. These schema names are case-sensitive. (default: The default schema for the datasource connection) <p>Consequences:</p> <ul> <li>The first schema in the list will be automatically set as the default one during the migration.</li> <li>The first schema in the list will also be the one containing the metadata table.</li> <li>The schemas will be cleaned in the order of this list.</li> </ul>
schemas
- The schemas managed by Flyway. May not be null
. Must contain at least one element.public void setTable(String table)
<p>Sets the name of the schema metadata table that will be used by Flyway.</p><p> By default (single-schema mode) the metadata table is placed in the default schema for the connection provided by the datasource. </p> <p> When the <i>flyway.schemas</i> property is set (multi-schema mode), the metadata table is placed in the first schema of the list. </p>
table
- The name of the schema metadata table that will be used by flyway. (default: schema_version)public void setTarget(org.flywaydb.core.api.MigrationVersion target)
Sets the target version up to which Flyway should consider migrations. Migrations with a higher version number will be ignored.
target
- The target version up to which Flyway should consider migrations. (default: the latest version)@Deprecated public void setTarget(String target)
Sets the target version up to which Flyway should consider migrations. Migrations with a higher version number will be ignored.
target
- The target version up to which Flyway should consider migrations. The special value current
designates the current version of the schema. (default: the
latest version)public void setPlaceholders(Map<String,String> placeholders)
Sets the placeholders to replace in sql migration scripts.
placeholders
- The map of <placeholder, replacementValue> to apply to sql migration scripts.public void setPlaceholderPrefix(String placeholderPrefix)
Sets the prefix of every placeholder.
placeholderPrefix
- The prefix of every placeholder. (default: ${ )public void setPlaceholderSuffix(String placeholderSuffix)
Sets the suffix of every placeholder.
placeholderSuffix
- The suffix of every placeholder. (default: } )public void setSqlMigrationPrefix(String sqlMigrationPrefix)
Sets the file name prefix for sql migrations. <p/> <p>Sql migrations have the following file name structure: prefixVERSIONseparatorDESCRIPTIONsuffix , which using the defaults translates to V1_1__My_description.sql</p>
sqlMigrationPrefix
- The file name prefix for sql migrations (default: V)public void setSqlMigrationSeparator(String sqlMigrationSeparator)
Sets the file name separator for sql migrations. <p/> <p>Sql migrations have the following file name structure: prefixVERSIONseparatorDESCRIPTIONsuffix , which using the defaults translates to V1_1__My_description.sql</p>
sqlMigrationSeparator
- The file name separator for sql migrations (default: __)public void setSqlMigrationSuffix(String sqlMigrationSuffix)
Sets the file name suffix for sql migrations. <p/> <p>Sql migrations have the following file name structure: prefixVERSIONseparatorDESCRIPTIONsuffix , which using the defaults translates to V1_1__My_description.sql</p>
sqlMigrationSuffix
- The file name suffix for sql migrations (default: .sql)public void setDataSource(DataSource dataSource)
Sets the datasource to use. Must have the necessary privileges to execute ddl.
dataSource
- The datasource to use. Must have the necessary privileges to execute ddl.public void setDataSource(String url, String user, String password, String... initSqls)
Sets the datasource to use. Must have the necessary privileges to execute ddl. <p/> <p>To use a custom ClassLoader, setClassLoader() must be called prior to calling this method.</p>
url
- The JDBC URL of the database.user
- The user of the database.password
- The password of the database.initSqls
- The (optional) sql statements to execute to initialize a connection immediately after obtaining it.public void setTransactionManager(org.springframework.transaction.PlatformTransactionManager transactionManager)
Set the transaction manager to use for transaction handling.
transactionManager
- the transaction managerpublic void setBaselineVersion(org.flywaydb.core.api.MigrationVersion baselineVersion)
Sets the version to tag an existing schema with when executing baseline.
baselineVersion
- The version to tag an existing schema with when executing baseline. (default: 1)public void setBaselineVersionAsString(String baselineVersion)
Sets the version to tag an existing schema with when executing baseline.
baselineVersion
- The version to tag an existing schema with when executing baseline. (default: 1)public void setBaselineDescription(String baselineDescription)
Sets the description to tag an existing schema with when executing baseline.
baselineDescription
- The description to tag an existing schema with when executing baseline. (default: << Flyway Baseline >>)public void setBaselineOnMigrate(boolean baselineOnMigrate)
<p> Whether to automatically call baseline when migrate is executed against a non-empty schema with no metadata table. This schema will then be baselined with the baselineVersion
before executing the migrations. Only migrations above baselineVersion
will then be applied. </p> <p> This is useful for initial Flyway production
deployments on projects with an existing DB. </p> <p> Be careful when enabling this as it removes the safety net that ensures Flyway does not migrate the wrong database in
case of a configuration mistake! </p>
baselineOnMigrate
- true
if baseline should be called on migrate for non-empty schemas, false
if not. (default: false
)public void setOutOfOrder(boolean outOfOrder)
Allows migrations to be run "out of order". <p>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.</p>
outOfOrder
- true
if outOfOrder migrations should be applied, false
if not. (default: false
)public org.flywaydb.core.api.callback.FlywayCallback[] getCallbacks()
Gets the callbacks for lifecycle notifications.
public void setCallbacks(org.flywaydb.core.api.callback.FlywayCallback... callbacks)
Set the callbacks for lifecycle notifications.
callbacks
- The callbacks for lifecycle notifications. (default: none)public void setCallbacksAsClassNames(String... callbacks)
Set the callbacks for lifecycle notifications.
callbacks
- The fully qualified class names of the callbacks for lifecycle notifications. (default: none)public void setResolvers(org.flywaydb.core.api.resolver.MigrationResolver... resolvers)
Sets custom MigrationResolvers to be used in addition to the built-in ones for resolving Migrations to apply.
resolvers
- The custom MigrationResolvers to be used in addition to the built-in ones for resolving Migrations to apply. (default: empty list)public void setResolversAsClassNames(String... resolvers)
Sets custom MigrationResolvers to be used in addition to the built-in ones for resolving Migrations to apply.
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)public int migrate() throws org.flywaydb.core.api.FlywayException
<p>Starts the database migration. All pending migrations will be applied in order. Calling migrate on an up-to-date database has no effect.</p> <img src="http://flywaydb.org/assets/balsamiq/command-migrate.png" alt="migrate">
org.flywaydb.core.api.FlywayException
- when the migration failed.public void validate() throws org.flywaydb.core.api.FlywayException
<p>Validate applied migration with classpath migrations to detect accidental changes.</p> <img src="http://flywaydb.org/assets/balsamiq/command-validate.png" alt="validate">
org.flywaydb.core.api.FlywayException
- when the validation failed.public void clean()
<p>Drops all objects (tables, views, procedures, triggers, …) in the configured schemas. The schemas are cleaned in the order specified by the schemas
property.</p> <img src="http://flywaydb.org/assets/balsamiq/command-clean.png" alt="clean">
org.flywaydb.core.api.FlywayException
- when the clean fails.public org.flywaydb.core.api.MigrationInfoService info()
<p>Retrieves the complete information about all the migrations including applied, pending and current migrations with details and status.</p> <img src="http://flywaydb.org/assets/balsamiq/command-info.png" alt="info">
org.flywaydb.core.api.FlywayException
- when the info retrieval failed.@Deprecated public void init() throws org.flywaydb.core.api.FlywayException
Baselines an existing database, excluding all migrations up to and including baselineVersion.
org.flywaydb.core.api.FlywayException
- when the schema baselining failed.public void baseline() throws org.flywaydb.core.api.FlywayException
<p>Baselines an existing database, excluding all migrations up to and including baselineVersion.</p> <p/> <img src="http://flywaydb.org/assets/balsamiq/command-baseline.png" alt="baseline">
org.flywaydb.core.api.FlywayException
- when the schema baselining failed.public void configure(Properties properties)
Configures Flyway with these properties. This overwrites any existing configuration. Property names are documented in the flyway maven plugin. <p/> <p>To use a custom ClassLoader, setClassLoader() must be called prior to calling this method.</p>
properties
- Properties used for configuration.org.flywaydb.core.api.FlywayException
- when the configuration failed.Copyright © 2010 - 2019 edorasware ag. All Rights Reserved.