public class Flyway extends Object implements FlywayConfiguration
It is THE public API from which all important Flyway functions such as clean, validate and migrate can be called.
Constructor and Description |
---|
Flyway()
Creates a new instance of Flyway.
|
Flyway(ClassLoader classLoader)
Creates a new instance of Flyway.
|
Flyway(FlywayConfiguration configuration)
Creates a new instance of Flyway.
|
Modifier and Type | Method and 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.
|
FlywayCallback[] |
getCallbacks()
Gets the callbacks for lifecycle notifications.
|
ClassLoader |
getClassLoader()
Retrieves the ClassLoader to use for loading migrations, resolvers, etc from the classpath.
|
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.
|
String |
getEncoding()
Retrieves the encoding of Sql migrations.
|
ErrorHandler[] |
getErrorHandlers()
Handlers for errors and warnings that occur during a migration.
|
String |
getInstalledBy()
The username that will be recorded in the schema history table as having applied the migration.
|
String[] |
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()
Retrieves the file name suffix for sql migrations.
|
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 |
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 |
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 |
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 |
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 |
setCallbacks(FlywayCallback... callbacks)
Set the callbacks for lifecycle notifications.
|
void |
setCallbacksAsClassNames(String... callbacks)
Set the callbacks for lifecycle notifications.
|
void |
setClassLoader(ClassLoader classLoader)
Deprecated.
Will be removed in Flyway 6.0. Use
Flyway(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(DataSource dataSource)
Sets the datasource to use.
|
void |
setDataSource(String url,
String user,
String password,
String... initSqls)
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 |
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 |
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 |
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.
Use
setSqlMigrationSuffixes(String...) instead. Will be removed in Flyway 6.0.0. |
void |
setSqlMigrationSuffixes(String... sqlMigrationSuffixes)
The file name suffixes for SQL migrations.
|
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() )public Flyway(FlywayConfiguration configuration)
configuration
- The configuration to use.public String[] getLocations()
FlywayConfiguration
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 FlywayConfiguration
public String getEncoding()
FlywayConfiguration
getEncoding
in interface FlywayConfiguration
public String[] getSchemas()
FlywayConfiguration
Consequences:
getSchemas
in interface FlywayConfiguration
public String getTable()
FlywayConfiguration
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 FlywayConfiguration
public MigrationVersion getTarget()
FlywayConfiguration
current
designates the current version of the schema.getTarget
in interface FlywayConfiguration
public boolean isPlaceholderReplacement()
FlywayConfiguration
isPlaceholderReplacement
in interface FlywayConfiguration
public Map<String,String> getPlaceholders()
FlywayConfiguration
getPlaceholders
in interface FlywayConfiguration
public String getPlaceholderPrefix()
FlywayConfiguration
getPlaceholderPrefix
in interface FlywayConfiguration
public String getPlaceholderSuffix()
FlywayConfiguration
getPlaceholderSuffix
in interface FlywayConfiguration
public String getSqlMigrationPrefix()
FlywayConfiguration
Versioned SQL migrations have the following file name structure: prefixVERSIONseparatorDESCRIPTIONsuffix , which using the defaults translates to V1.1__My_description.sql
getSqlMigrationPrefix
in interface FlywayConfiguration
public String getRepeatableSqlMigrationPrefix()
FlywayConfiguration
Repeatable SQL migrations have the following file name structure: prefixSeparatorDESCRIPTIONsuffix , which using the defaults translates to R__My_description.sql
getRepeatableSqlMigrationPrefix
in interface FlywayConfiguration
public String getSqlMigrationSeparator()
FlywayConfiguration
Sql migrations have the following file name structure: prefixVERSIONseparatorDESCRIPTIONsuffix , which using the defaults translates to V1_1__My_description.sql
getSqlMigrationSeparator
in interface FlywayConfiguration
public String getSqlMigrationSuffix()
FlywayConfiguration
Sql migrations have the following file name structure: prefixVERSIONseparatorDESCRIPTIONsuffix , which using the defaults translates to V1_1__My_description.sql
getSqlMigrationSuffix
in interface FlywayConfiguration
public String[] getSqlMigrationSuffixes()
FlywayConfiguration
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 FlywayConfiguration
public boolean isIgnoreMissingMigrations()
FlywayConfiguration
isIgnoreMissingMigrations
in interface FlywayConfiguration
true
to continue normally and log a warning, false
to fail fast with an exception.
(default: false
)public boolean isIgnoreFutureMigrations()
FlywayConfiguration
isIgnoreFutureMigrations
in interface FlywayConfiguration
true
to continue normally and log a warning, false
to fail fast with an exception.
(default: true
)public boolean isValidateOnMigrate()
FlywayConfiguration
isValidateOnMigrate
in interface FlywayConfiguration
true
if validate should be called. false
if not. (default: true
)public boolean isCleanOnValidationError()
FlywayConfiguration
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 FlywayConfiguration
true
if clean should be called. false
if not. (default: false
)public boolean isCleanDisabled()
FlywayConfiguration
This is especially useful for production environments where running clean can be quite a career limiting move.
isCleanDisabled
in interface FlywayConfiguration
true
to disabled clean. false
to leave it enabled. (default: false
)public MigrationVersion getBaselineVersion()
FlywayConfiguration
getBaselineVersion
in interface FlywayConfiguration
public String getBaselineDescription()
FlywayConfiguration
getBaselineDescription
in interface FlywayConfiguration
public boolean isBaselineOnMigrate()
FlywayConfiguration
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 FlywayConfiguration
true
if baseline should be called on migrate for non-empty schemas, false
if not. (default: false
)public boolean isOutOfOrder()
FlywayConfiguration
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 FlywayConfiguration
true
if outOfOrder migrations should be applied, false
if not. (default: false
)public MigrationResolver[] getResolvers()
FlywayConfiguration
getResolvers
in interface FlywayConfiguration
public boolean isSkipDefaultResolvers()
FlywayConfiguration
isSkipDefaultResolvers
in interface FlywayConfiguration
public DataSource getDataSource()
FlywayConfiguration
getDataSource
in interface FlywayConfiguration
public ClassLoader getClassLoader()
FlywayConfiguration
getClassLoader
in interface FlywayConfiguration
public boolean isMixed()
FlywayConfiguration
isMixed
in interface FlywayConfiguration
true
if mixed migrations should be allowed. false
if an error should be thrown instead. (default: false
)public String getInstalledBy()
FlywayConfiguration
getInstalledBy
in interface FlywayConfiguration
null
for the current database user of the connection. (default: null
).public boolean isGroup()
FlywayConfiguration
isGroup
in interface FlywayConfiguration
true
if migrations should be grouped. false
if they should be applied individually instead. (default: false
)public ErrorHandler[] getErrorHandlers()
FlywayConfiguration
Flyway Pro and Flyway Enterprise only
getErrorHandlers
in interface FlywayConfiguration
public OutputStream getDryRunOutput()
FlywayConfiguration
null
if the SQL statements
are executed against the database directly.
Flyway Pro and Flyway Enterprise only
getDryRunOutput
in interface FlywayConfiguration
null
if the SQL statements are executed against the database directly.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 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 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()
FlywayConfiguration
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 FlywayConfiguration
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)
setSqlMigrationSuffixes(String...)
instead. Will be removed in Flyway 6.0.0.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(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 FlywayCallback[] getCallbacks()
getCallbacks
in interface FlywayConfiguration
public boolean isSkipDefaultCallbacks()
FlywayConfiguration
isSkipDefaultCallbacks
in interface FlywayConfiguration
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 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, setClassLoader() 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 © 2017. All rights reserved.