Configuration
public class Flyway extends Object implements Configuration
It is THE public API from which all important Flyway functions such as clean, validate and migrate can be called.
To get started all you need to do is
Flyway flyway = new Flyway(); flyway.setDataSource(url, user, password); flyway.migrate();
Constructor | Description |
---|---|
Flyway() |
Creates a new instance of Flyway.
|
Flyway(ClassLoader classLoader) |
Creates a new instance of Flyway.
|
Flyway(Configuration configuration) |
Creates a new instance of Flyway with this configuration.
|
Flyway(FlywayConfiguration configuration) |
Deprecated.
Use
Flyway(Configuration) instead. Will be removed in Flyway 6.0. |
Modifier and Type | Method | Description |
---|---|---|
void |
baseline() |
Baselines an existing database, excluding all migrations up to and including baselineVersion.
|
void |
clean() |
Drops all objects (tables, views, procedures, triggers, ...) in the configured schemas.
|
void |
configure(Map<String,String> props) |
Configures Flyway with these properties.
|
void |
configure(Properties properties) |
Configures Flyway with these properties.
|
String |
getBaselineDescription() |
Retrieves the description to tag an existing schema with when executing baseline.
|
MigrationVersion |
getBaselineVersion() |
Retrieves the version to tag an existing schema with when executing baseline.
|
Callback[] |
getCallbacks() |
Gets the callbacks for lifecycle notifications.
|
ClassLoader |
getClassLoader() |
Retrieves the ClassLoader to use for loading migrations, resolvers, etc from the classpath.
|
Configuration |
getConfiguration() |
|
DataSource |
getDataSource() |
Retrieves the dataSource to use to access the database.
|
OutputStream |
getDryRunOutput() |
The stream where to output the SQL statements of a migration dry run.
|
Charset |
getEncoding() |
Retrieves the encoding of Sql migrations.
|
ErrorHandler[] |
getErrorHandlers() |
Handlers for errors and warnings that occur during a migration.
|
String[] |
getErrorOverrides() |
Rules for the built-in error handler that lets you override specific SQL states and errors codes from error
to warning or from warning to error.
|
String |
getInstalledBy() |
The username that will be recorded in the schema history table as having applied the migration.
|
Location[] |
getLocations() |
Retrieves the locations to scan recursively for migrations.
|
String |
getPlaceholderPrefix() |
Retrieves the prefix of every placeholder.
|
Map<String,String> |
getPlaceholders() |
Retrieves the map of <placeholder, replacementValue> to apply to sql migration scripts.
|
String |
getPlaceholderSuffix() |
Retrieves the suffix of every placeholder.
|
String |
getRepeatableSqlMigrationPrefix() |
Retrieves the file name prefix for repeatable SQL migrations.
|
MigrationResolver[] |
getResolvers() |
Retrieves the The custom MigrationResolvers to be used in addition to the built-in ones for resolving Migrations to apply.
|
String[] |
getSchemas() |
Retrieves the schemas managed by Flyway.
|
String |
getSqlMigrationPrefix() |
The file name prefix for versioned SQL migrations.
|
String |
getSqlMigrationSeparator() |
Retrieves the file name separator for sql migrations.
|
String |
getSqlMigrationSuffix() |
Deprecated.
|
String[] |
getSqlMigrationSuffixes() |
The file name suffixes for SQL migrations.
|
String |
getTable() |
Retrieves the name of the schema schema history table that will be used by Flyway.
|
MigrationVersion |
getTarget() |
Retrieves the target version up to which Flyway should consider migrations.
|
String |
getUndoSqlMigrationPrefix() |
The file name prefix for undo SQL migrations.
|
MigrationInfoService |
info() |
Retrieves the complete information about all the migrations including applied, pending and current migrations with
details and status.
|
boolean |
isBaselineOnMigrate() |
Whether to automatically call baseline when migrate is executed against a non-empty schema with no schema history table.
|
boolean |
isBatch() |
Whether to batch SQL statements when executing them.
|
boolean |
isCleanDisabled() |
Whether to disable clean.
|
boolean |
isCleanOnValidationError() |
Whether to automatically call clean or not when a validation error occurs.
|
boolean |
isGroup() |
Whether to group all pending migrations together in the same transaction when applying them (only recommended for databases with support for DDL transactions).
|
boolean |
isIgnoreFutureMigrations() |
Ignore future migrations when reading the schema history table.
|
boolean |
isIgnoreIgnoredMigrations() |
Ignore ignored migrations when reading the schema history table.
|
boolean |
isIgnoreMissingMigrations() |
Ignore missing migrations when reading the schema history table.
|
boolean |
isMixed() |
Whether to allow mixing transactional and non-transactional statements within the same migration.
|
boolean |
isOracleSqlplus() |
Whether to Flyway's support for Oracle SQL*Plus commands should be activated.
|
boolean |
isOutOfOrder() |
Allows migrations to be run "out of order".
|
boolean |
isPlaceholderReplacement() |
Checks whether placeholders should be replaced.
|
boolean |
isSkipDefaultCallbacks() |
Whether Flyway should skip the default callbacks.
|
boolean |
isSkipDefaultResolvers() |
Whether Flyway should skip the default resolvers.
|
boolean |
isStream() |
Whether to stream SQL migrations when executing them.
|
boolean |
isValidateOnMigrate() |
Whether to automatically call validate or not when running migrate.
|
int |
migrate() |
Starts the database migration.
|
void |
repair() |
Repairs the Flyway schema history table.
|
void |
setBaselineDescription(String baselineDescription) |
Sets the description to tag an existing schema with when executing baseline.
|
void |
setBaselineOnMigrate(boolean baselineOnMigrate) |
Whether to automatically call baseline when migrate is executed against a non-empty schema with no schema history table.
|
void |
setBaselineVersion(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 |
setBatch(boolean batch) |
Whether to batch SQL statements when executing them.
|
void |
setCallbacks(Callback... callbacks) |
Set the callbacks for lifecycle notifications.
|
void |
setCallbacks(FlywayCallback... callbacks) |
Deprecated.
Flyway.setCallbacks(FlywayCallback) has been deprecated and will be removed in Flyway 6.0. Use Flyway.setCallbacks(Callback) instead.
|
void |
setCallbacksAsClassNames(String... callbacks) |
Set the callbacks for lifecycle notifications.
|
void |
setClassLoader(ClassLoader classLoader) |
Deprecated.
Will be removed in Flyway 6.0. Use
Flyway(java.lang.ClassLoader) instead. |
void |
setCleanDisabled(boolean cleanDisabled) |
Whether to disable clean.
|
void |
setCleanOnValidationError(boolean cleanOnValidationError) |
Whether to automatically call clean or not when a validation error occurs.
|
void |
setDataSource(String url,
String user,
String password,
String... initSqls) |
Sets the datasource to use.
|
void |
setDataSource(DataSource dataSource) |
Sets the datasource to use.
|
void |
setDryRunOutput(OutputStream dryRunOutput) |
Sets the stream where to output the SQL statements of a migration dry run.
|
void |
setDryRunOutputAsFile(File dryRunOutput) |
Sets the file where to output the SQL statements of a migration dry run.
|
void |
setDryRunOutputAsFileName(String dryRunOutputFileName) |
Sets the file where to output the SQL statements of a migration dry run.
|
void |
setEncoding(String encoding) |
Sets the encoding of Sql migrations.
|
void |
setErrorHandlers(ErrorHandler... errorHandlers) |
Handlers for errors and warnings that occur during a migration.
|
void |
setErrorHandlersAsClassNames(String... errorHandlerClassNames) |
Handlers for errors and warnings that occur during a migration.
|
void |
setErrorOverrides(String... errorOverrides) |
Rules for the built-in error handler that lets you override specific SQL states and errors codes from error
to warning or from warning to error.
|
void |
setGroup(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).
|
void |
setIgnoreFutureMigrations(boolean ignoreFutureMigrations) |
Whether to ignore future migrations when reading the schema history table.
|
void |
setIgnoreIgnoredMigrations(boolean ignoreIgnoredMigrations) |
Ignore ignored migrations when reading the schema history table.
|
void |
setIgnoreMissingMigrations(boolean ignoreMissingMigrations) |
Ignore missing migrations when reading the schema history table.
|
void |
setInstalledBy(String installedBy) |
The username that will be recorded in the schema history table as having applied the migration.
|
void |
setLocations(String... locations) |
Sets the locations to scan recursively for migrations.
|
void |
setMixed(boolean mixed) |
Whether to allow mixing transactional and non-transactional statements within the same migration.
|
void |
setOracleSqlplus(boolean oracleSqlplus) |
Whether to Flyway's support for Oracle SQL*Plus commands should be activated.
|
void |
setOutOfOrder(boolean outOfOrder) |
Allows migrations to be run "out of order".
|
void |
setPlaceholderPrefix(String placeholderPrefix) |
Sets the prefix of every placeholder.
|
void |
setPlaceholderReplacement(boolean placeholderReplacement) |
Sets whether placeholders should be replaced.
|
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 |
setRepeatableSqlMigrationPrefix(String repeatableSqlMigrationPrefix) |
Sets the file name prefix for repeatable sql migrations.
|
void |
setResolvers(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 |
setSkipDefaultCallbacks(boolean skipDefaultCallbacks) |
Whether Flyway should skip the default callbacks.
|
void |
setSkipDefaultResolvers(boolean skipDefaultResolvers) |
Whether Flyway should skip the default resolvers.
|
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) |
Deprecated.
sqlMigrationSuffix has been deprecated and will be removed in Flyway 6.0.0. Use sqlMigrationSuffixes instead.
|
void |
setSqlMigrationSuffixes(String... sqlMigrationSuffixes) |
The file name suffixes for SQL migrations.
|
void |
setStream(boolean stream) |
Whether to stream SQL migrations when executing them.
|
void |
setTable(String table) |
Sets the name of the schema schema history table that will be used by Flyway.
|
void |
setTarget(MigrationVersion target) |
Sets the target version up to which Flyway should consider migrations.
|
void |
setTargetAsString(String target) |
Sets the target version up to which Flyway should consider migrations.
|
void |
setUndoSqlMigrationPrefix(String undoSqlMigrationPrefix) |
Sets the file name prefix for undo SQL migrations.
|
void |
setValidateOnMigrate(boolean validateOnMigrate) |
Whether to automatically call validate or not when running migrate.
|
int |
undo() |
Undoes the most recently applied versioned migration.
|
void |
validate() |
Validate applied migrations against resolved ones (on the filesystem or classpath)
to detect accidental changes that may prevent the schema(s) from being recreated exactly.
|
public Flyway()
public Flyway(ClassLoader classLoader)
classLoader
- The ClassLoader to use for loading migrations, resolvers, etc from the classpath. (default: Thread.currentThread().getContextClassLoader() )@Deprecated public Flyway(FlywayConfiguration configuration)
Flyway(Configuration)
instead. Will be removed in Flyway 6.0.configuration
- The configuration to use.public Flyway(Configuration configuration)
configuration
- The configuration to use.public Configuration getConfiguration()
public Location[] getLocations()
Configuration
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.
getLocations
in interface Configuration
public Charset getEncoding()
Configuration
getEncoding
in interface Configuration
public String[] getSchemas()
Configuration
Consequences:
getSchemas
in interface Configuration
public String getTable()
Configuration
Retrieves the name of the schema schema history table that will be used by Flyway.
By default (single-schema mode) the schema history table is placed in the default schema for the connection provided by the datasource.
When the flyway.schemas property is set (multi-schema mode), the schema history table is placed in the first schema of the list.
getTable
in interface Configuration
public MigrationVersion getTarget()
Configuration
current
designates the current version of the schema.getTarget
in interface Configuration
public boolean isPlaceholderReplacement()
Configuration
isPlaceholderReplacement
in interface Configuration
public Map<String,String> getPlaceholders()
Configuration
getPlaceholders
in interface Configuration
public String getPlaceholderPrefix()
Configuration
getPlaceholderPrefix
in interface Configuration
public String getPlaceholderSuffix()
Configuration
getPlaceholderSuffix
in interface Configuration
public String getSqlMigrationPrefix()
Configuration
Versioned SQL migrations have the following file name structure: prefixVERSIONseparatorDESCRIPTIONsuffix , which using the defaults translates to V1.1__My_description.sql
getSqlMigrationPrefix
in interface Configuration
public String getRepeatableSqlMigrationPrefix()
Configuration
Repeatable SQL migrations have the following file name structure: prefixSeparatorDESCRIPTIONsuffix , which using the defaults translates to R__My_description.sql
getRepeatableSqlMigrationPrefix
in interface Configuration
public String getSqlMigrationSeparator()
Configuration
Sql migrations have the following file name structure: prefixVERSIONseparatorDESCRIPTIONsuffix , which using the defaults translates to V1_1__My_description.sql
getSqlMigrationSeparator
in interface Configuration
@Deprecated public String getSqlMigrationSuffix()
public String[] getSqlMigrationSuffixes()
Configuration
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.
getSqlMigrationSuffixes
in interface Configuration
public boolean isIgnoreMissingMigrations()
Configuration
isIgnoreMissingMigrations
in interface Configuration
true
to continue normally and log a warning, false
to fail fast with an exception.
(default: false
)public boolean isIgnoreIgnoredMigrations()
Configuration
isIgnoreIgnoredMigrations
in interface Configuration
true
to continue normally, false
to fail fast with an exception.
(default: false
)public boolean isIgnoreFutureMigrations()
Configuration
isIgnoreFutureMigrations
in interface Configuration
true
to continue normally and log a warning, false
to fail fast with an exception.
(default: true
)public boolean isValidateOnMigrate()
Configuration
isValidateOnMigrate
in interface Configuration
true
if validate should be called. false
if not. (default: true
)public boolean isCleanOnValidationError()
Configuration
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.
Warning ! Do not enable in production !
isCleanOnValidationError
in interface Configuration
true
if clean should be called. false
if not. (default: false
)public boolean isCleanDisabled()
Configuration
This is especially useful for production environments where running clean can be quite a career limiting move.
isCleanDisabled
in interface Configuration
true
to disabled clean. false
to leave it enabled. (default: false
)public MigrationVersion getBaselineVersion()
Configuration
getBaselineVersion
in interface Configuration
public String getBaselineDescription()
Configuration
getBaselineDescription
in interface Configuration
public boolean isBaselineOnMigrate()
Configuration
Whether to automatically call baseline when migrate is executed against a non-empty schema with no schema history table.
This schema will then be initialized with the baselineVersion
before executing the migrations.
Only migrations above baselineVersion
will then be applied.
This is useful for initial Flyway production deployments on projects with an existing DB.
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!
isBaselineOnMigrate
in interface Configuration
true
if baseline should be called on migrate for non-empty schemas, false
if not. (default: false
)public boolean isOutOfOrder()
Configuration
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.
isOutOfOrder
in interface Configuration
true
if outOfOrder migrations should be applied, false
if not. (default: false
)public MigrationResolver[] getResolvers()
Configuration
getResolvers
in interface Configuration
public boolean isSkipDefaultResolvers()
Configuration
isSkipDefaultResolvers
in interface Configuration
public DataSource getDataSource()
Configuration
getDataSource
in interface Configuration
public ClassLoader getClassLoader()
Configuration
getClassLoader
in interface Configuration
public boolean isMixed()
Configuration
isMixed
in interface Configuration
true
if mixed migrations should be allowed. false
if an error should be thrown instead. (default: false
)public String getInstalledBy()
Configuration
getInstalledBy
in interface Configuration
null
for the current database user of the connection. (default: null
).public boolean isGroup()
Configuration
isGroup
in interface Configuration
true
if migrations should be grouped. false
if they should be applied individually instead. (default: false
)public ErrorHandler[] getErrorHandlers()
Configuration
Flyway Pro and Flyway Enterprise only
getErrorHandlers
in interface Configuration
public String[] getErrorOverrides()
Configuration
Each error override has the following format: STATE:12345:W
.
It is a 5 character SQL state, a colon, the SQL error code, a colon and finally the desired
behavior that should override the initial one. The following behaviors are accepted: W
to force a warning
and E
to force an error.
For example, to force Oracle stored procedure compilation issues to produce
errors instead of warnings, the following errorOverride can be used: 99999:17110:E
Flyway Pro and Flyway Enterprise only
getErrorOverrides
in interface Configuration
public OutputStream getDryRunOutput()
Configuration
null
if the SQL statements
are executed against the database directly.
Flyway Pro and Flyway Enterprise only
getDryRunOutput
in interface Configuration
null
if the SQL statements are executed against the database directly.public boolean isStream()
Configuration
Flyway Pro and Flyway Enterprise only
isStream
in interface Configuration
true
to stream SQL migrations. false
to fully loaded them in memory instead. (default: false
)public boolean isBatch()
Configuration
Flyway Pro and Flyway Enterprise only
isBatch
in interface Configuration
true
to batch SQL statements. false
to execute them individually instead. (default: false
)public boolean isOracleSqlplus()
Configuration
Flyway Pro and Flyway Enterprise only
isOracleSqlplus
in interface Configuration
true
to active SQL*Plus support. false
to fail fast instead. (default: false
)public void setDryRunOutput(OutputStream dryRunOutput)
null
to execute the SQL statements
directly against the database. The stream when be closing when Flyway finishes writing the output.
Flyway Pro and Flyway Enterprise only
dryRunOutput
- The output file or null
to execute the SQL statements directly against the database.public void setDryRunOutputAsFile(File dryRunOutput)
null
to execute the SQL statements
directly against the database. If the file specified is in a non-existent directory, Flyway will create all
directories and parent directories as needed.
Flyway Pro and Flyway Enterprise only
dryRunOutput
- The output file or null
to execute the SQL statements directly against the database.public void setDryRunOutputAsFileName(String dryRunOutputFileName)
null
to execute the SQL statements
directly against the database. If the file specified is in a non-existent directory, Flyway will create all
directories and parent directories as needed.
Flyway Pro and Flyway Enterprise only
dryRunOutputFileName
- The name of the output file or null
to execute the SQL statements directly
against the database.public void setErrorHandlers(ErrorHandler... errorHandlers)
Flyway Pro and Flyway Enterprise only
errorHandlers
- The ErrorHandlers or an empty array if the default internal handler should be used instead. (default: none)public void setErrorHandlersAsClassNames(String... errorHandlerClassNames)
Flyway Pro and Flyway Enterprise only
errorHandlerClassNames
- The fully qualified class names of ErrorHandlers or an empty array if the default
internal handler should be used instead. (default: none)public void setErrorOverrides(String... errorOverrides)
Each error override has the following format: STATE:12345:W
.
It is a 5 character SQL state, a colon, the SQL error code, a colon and finally the desired
behavior that should override the initial one. The following behaviors are accepted: W
to force a warning
and E
to force an error.
For example, to force Oracle stored procedure compilation issues to produce
errors instead of warnings, the following errorOverride can be used: 99999:17110:E
Flyway Pro and Flyway Enterprise only
errorOverrides
- The ErrorOverrides or an empty array if none are defined. (default: none)public void setGroup(boolean group)
group
- true
if migrations should be grouped. false
if they should be applied individually instead. (default: false
)public void setInstalledBy(String installedBy)
installedBy
- The username or null
for the current database user of the connection. (default: null
).public void setMixed(boolean mixed)
mixed
- true
if mixed migrations should be allowed. false
if an error should be thrown instead. (default: false
)public void setIgnoreMissingMigrations(boolean ignoreMissingMigrations)
ignoreMissingMigrations
- true
to continue normally and log a warning, false
to fail fast with an exception.
(default: false
)public void setIgnoreIgnoredMigrations(boolean ignoreIgnoredMigrations)
ignoreIgnoredMigrations
- true
to continue normally, false
to fail fast with an exception.
(default: false
)public void setIgnoreFutureMigrations(boolean ignoreFutureMigrations)
ignoreFutureMigrations
- true
to continue normally and log a warning, false
to fail
fast with an exception. (default: true
)public void setValidateOnMigrate(boolean validateOnMigrate)
validateOnMigrate
- true
if validate should be called. false
if not. (default: true
)public void setCleanOnValidationError(boolean cleanOnValidationError)
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.
Warning ! Do not enable in production !
cleanOnValidationError
- true
if clean should be called. false
if not. (default: false
)public void setCleanDisabled(boolean cleanDisabled)
This is especially useful for production environments where running clean can be quite a career limiting move.
cleanDisabled
- true
to disabled clean. false
to leave it enabled. (default: false
)public void setLocations(String... locations)
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.
locations
- Locations to scan recursively for migrations. (default: db/migration)public void setEncoding(String encoding)
encoding
- The encoding of Sql migrations. (default: UTF-8)public void setSchemas(String... schemas)
Consequences:
schemas
- The schemas managed by Flyway. May not be null
. Must contain at least one element.public void setTable(String table)
Sets the name of the schema schema history table that will be used by Flyway.
By default (single-schema mode) the schema history table is placed in the default schema for the connection provided by the datasource.
When the flyway.schemas property is set (multi-schema mode), the schema history table is placed in the first schema of the list.
table
- The name of the schema schema history table that will be used by flyway. (default: flyway_schema_history)public void setTarget(MigrationVersion target)
target
- The target version up to which Flyway should consider migrations. (default: the latest version)public void setTargetAsString(String target)
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 setPlaceholderReplacement(boolean placeholderReplacement)
placeholderReplacement
- Whether placeholders should be replaced. (default: true)public void setPlaceholders(Map<String,String> placeholders)
placeholders
- The map of <placeholder, replacementValue> to apply to sql migration scripts.public void setPlaceholderPrefix(String placeholderPrefix)
placeholderPrefix
- The prefix of every placeholder. (default: ${ )public void setPlaceholderSuffix(String placeholderSuffix)
placeholderSuffix
- The suffix of every placeholder. (default: } )public void setSqlMigrationPrefix(String sqlMigrationPrefix)
Sql migrations have the following file name structure: prefixVERSIONseparatorDESCRIPTIONsuffix , which using the defaults translates to V1_1__My_description.sql
sqlMigrationPrefix
- The file name prefix for sql migrations (default: V)public String getUndoSqlMigrationPrefix()
Configuration
Undo SQL migrations are responsible for undoing the effects of the versioned migration with the same version.
They have the following file name structure: prefixVERSIONseparatorDESCRIPTIONsuffix , which using the defaults translates to U1.1__My_description.sql
Flyway Pro and Flyway Enterprise only
getUndoSqlMigrationPrefix
in interface Configuration
public void setUndoSqlMigrationPrefix(String undoSqlMigrationPrefix)
Undo SQL migrations are responsible for undoing the effects of the versioned migration with the same version.
They have the following file name structure: prefixVERSIONseparatorDESCRIPTIONsuffix , which using the defaults translates to U1.1__My_description.sql
Flyway Pro and Flyway Enterprise only
undoSqlMigrationPrefix
- The file name prefix for undo SQL migrations. (default: U)public void setRepeatableSqlMigrationPrefix(String repeatableSqlMigrationPrefix)
Repeatable sql migrations have the following file name structure: prefixSeparatorDESCRIPTIONsuffix , which using the defaults translates to R__My_description.sql
repeatableSqlMigrationPrefix
- The file name prefix for repeatable sql migrations (default: R)public void setSqlMigrationSeparator(String sqlMigrationSeparator)
Sql migrations have the following file name structure: prefixVERSIONseparatorDESCRIPTIONsuffix , which using the defaults translates to V1_1__My_description.sql
sqlMigrationSeparator
- The file name separator for sql migrations (default: __)@Deprecated public void setSqlMigrationSuffix(String sqlMigrationSuffix)
Sql migrations have the following file name structure: prefixVERSIONseparatorDESCRIPTIONsuffix , which using the defaults translates to V1_1__My_description.sql
sqlMigrationSuffix
- The file name suffix for sql migrations (default: .sql)public void setSqlMigrationSuffixes(String... sqlMigrationSuffixes)
SQL migrations have the following file name structure: prefixVERSIONseparatorDESCRIPTIONsuffix , which using the defaults translates to V1_1__My_description.sql
Multiple suffixes (like .sql,.pkg,.pkb) can be specified for easier compatibility with other tools such as editors with specific file associations.
sqlMigrationSuffixes
- The file name suffixes for SQL migrations.public void setDataSource(DataSource dataSource)
dataSource
- The datasource to use. Must have the necessary privileges to execute ddl.public void setDataSource(String url, String user, String password, String... initSqls)
To use a custom ClassLoader, setClassLoader() must be called prior to calling this method.
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.@Deprecated public void setClassLoader(ClassLoader classLoader)
Flyway(java.lang.ClassLoader)
instead.classLoader
- The ClassLoader to use for loading migrations, resolvers, etc from the classpath. (default: Thread.currentThread().getContextClassLoader() )public void setBaselineVersion(MigrationVersion baselineVersion)
baselineVersion
- The version to tag an existing schema with when executing baseline. (default: 1)public void setBaselineVersionAsString(String baselineVersion)
baselineVersion
- The version to tag an existing schema with when executing baseline. (default: 1)public void setBaselineDescription(String baselineDescription)
baselineDescription
- The description to tag an existing schema with when executing baseline. (default: << Flyway Baseline >>)public void setBaselineOnMigrate(boolean baselineOnMigrate)
Whether to automatically call baseline when migrate is executed against a non-empty schema with no schema history table.
This schema will then be baselined with the baselineVersion
before executing the migrations.
Only migrations above baselineVersion
will then be applied.
This is useful for initial Flyway production deployments on projects with an existing DB.
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!
baselineOnMigrate
- true
if baseline should be called on migrate for non-empty schemas, false
if not. (default: false
)public void setOutOfOrder(boolean outOfOrder)
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.
outOfOrder
- true
if outOfOrder migrations should be applied, false
if not. (default: false
)public Callback[] getCallbacks()
Configuration
getCallbacks
in interface Configuration
public boolean isSkipDefaultCallbacks()
Configuration
isSkipDefaultCallbacks
in interface Configuration
public void setCallbacks(Callback... callbacks)
callbacks
- The callbacks for lifecycle notifications. (default: none)@Deprecated public void setCallbacks(FlywayCallback... callbacks)
callbacks
- The callbacks for lifecycle notifications. (default: none)public void setCallbacksAsClassNames(String... callbacks)
callbacks
- The fully qualified class names of the callbacks for lifecycle notifications. (default: none)public void setSkipDefaultCallbacks(boolean skipDefaultCallbacks)
skipDefaultCallbacks
- Whether default built-in callbacks should be skipped. (default: false)
public void setResolvers(MigrationResolver... resolvers)
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)
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 void setSkipDefaultResolvers(boolean skipDefaultResolvers)
skipDefaultResolvers
- Whether default built-in resolvers should be skipped. (default: false)
public void setStream(boolean stream)
Flyway Pro and Flyway Enterprise only
stream
- true
to stream SQL migrations. false
to fully loaded them in memory instead. (default: false
)public void setBatch(boolean batch)
Flyway Pro and Flyway Enterprise only
batch
- true
to batch SQL statements. false
to execute them individually instead. (default: false
)public void setOracleSqlplus(boolean oracleSqlplus)
Flyway Pro and Flyway Enterprise only
oracleSqlplus
- true
to active SQL*Plus support. false
to fail fast instead. (default: false
)public int migrate() throws FlywayException
Starts the database migration. All pending migrations will be applied in order. Calling migrate on an up-to-date database has no effect.
FlywayException
- when the migration failed.public int undo() throws FlywayException
Undoes the most recently applied versioned migration. If target is specified, Flyway will attempt to undo versioned migrations in the order they were applied until it hits one with a version below the target. If there is no versioned migration to undo, calling undo has no effect.
Flyway Pro and Flyway Enterprise only
FlywayException
- when the undo failed.public void validate() throws FlywayException
Validate applied migrations against resolved ones (on the filesystem or classpath) to detect accidental changes that may prevent the schema(s) from being recreated exactly.
Validation fails if
FlywayException
- when the validation failed.public void clean()
Drops all objects (tables, views, procedures, triggers, ...) in the configured schemas.
The schemas are cleaned in the order specified by the schemas
property.
FlywayException
- when the clean fails.public MigrationInfoService info()
Retrieves the complete information about all the migrations including applied, pending and current migrations with details and status.
FlywayException
- when the info retrieval failed.public void baseline() throws FlywayException
Baselines an existing database, excluding all migrations up to and including baselineVersion.
FlywayException
- when the schema baselining failed.public void repair() throws FlywayException
FlywayException
- when the schema history table repair failed.public void configure(Properties properties)
To use a custom ClassLoader, the Flyway(ClassLoader) constructor must be called prior to calling this method.
properties
- Properties used for configuration.FlywayException
- when the configuration failed.public void configure(Map<String,String> props)
To use a custom ClassLoader, it must be passed to the Flyway constructor prior to calling this method.
props
- Properties used for configuration.FlywayException
- when the configuration failed.Copyright © 2018. All rights reserved.