public class Flyway extends Object
| Constructor and Description |
|---|
Flyway()
Creates a new instance of Flyway.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clean()
Drops all objects (tables, views, procedures, triggers, ...) in the configured schemas.
|
void |
configure(Properties properties)
Configures Flyway with these properties.
|
FlywayCallback[] |
getCallbacks()
Gets the callbacks for lifecycle notifications.
|
ClassLoader |
getClassLoader()
Retrieves the ClassLoader to use for resolving migrations on the classpath.
|
DataSource |
getDataSource()
Retrieves the dataSource to use to access the database.
|
String |
getEncoding()
Retrieves the encoding of Sql migrations.
|
String |
getInitDescription()
Retrieves the description to tag an existing schema with when executing init.
|
MigrationVersion |
getInitVersion()
Retrieves the version to tag an existing schema with when executing init.
|
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.
|
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()
Retrieves the file name prefix for sql migrations.
|
String |
getSqlMigrationSeparator()
Retrieves the file name separator for sql migrations.
|
String |
getSqlMigrationSuffix()
Retrieves the file name suffix for sql migrations.
|
String |
getTable()
Retrieves the name of the schema metadata table that will be used by Flyway.
|
MigrationVersion |
getTarget()
Retrieves the target version up to which Flyway should run migrations.
|
MigrationInfoService |
info()
Retrieves the complete information about all the migrations including applied, pending and current migrations with
details and status.
|
void |
init()
Creates and initializes the Flyway metadata table.
|
boolean |
isCleanOnValidationError()
Whether to automatically call clean or not when a validation error occurs.
|
boolean |
isIgnoreFailedFutureMigration()
Whether to ignore failed future migrations when reading the metadata table.
|
boolean |
isInitOnMigrate()
Whether to automatically call init when migrate is executed against a non-empty schema with no metadata table.
|
boolean |
isOutOfOrder()
Allows migrations to be run "out of order".
|
boolean |
isValidateOnMigrate()
Whether to automatically call validate or not when running migrate.
|
int |
migrate()
Starts the database migration.
|
void |
repair()
Repairs the Flyway metadata table.
|
void |
setCallbacks(FlywayCallback... callbacks)
Set the callbacks for lifecycle notifications.
|
void |
setCallbacks(String... callbacks)
Set the callbacks for lifecycle notifications.
|
void |
setClassLoader(ClassLoader classLoader)
Sets the ClassLoader to use for resolving migrations on the classpath.
|
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 |
setInitDescription(String initDescription)
Sets the description to tag an existing schema with when executing init.
|
void |
setInitOnMigrate(boolean initOnMigrate)
Whether to automatically call init when migrate is executed against a non-empty schema with no metadata table.
|
void |
setInitVersion(MigrationVersion initVersion)
Sets the version to tag an existing schema with when executing init.
|
void |
setInitVersion(String initVersion)
Sets the version to tag an existing schema with when executing init.
|
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(MigrationResolver... resolvers)
Sets custom MigrationResolvers to be used in addition to the built-in ones for resolving Migrations to apply.
|
void |
setResolvers(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)
Sets the name of the schema metadata table that will be used by Flyway.
|
void |
setTarget(MigrationVersion target)
Sets the target version up to which Flyway should run migrations.
|
void |
setTarget(String target)
Sets the target version up to which Flyway should run migrations.
|
void |
setValidateOnMigrate(boolean validateOnMigrate)
Whether to automatically call validate or not when running migrate.
|
void |
validate()
Validate applied migration with classpath migrations to detect accidental changes.
|
public Flyway()
public String[] getLocations()
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.
public String getEncoding()
public String[] getSchemas()
Consequences:
public String getTable()
Retrieves the name of the schema metadata table that will be used by Flyway.
By default (single-schema mode) the metadata 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 metadata table is placed in the first schema of the list.
public MigrationVersion getTarget()
public Map<String,String> getPlaceholders()
public String getPlaceholderPrefix()
public String getPlaceholderSuffix()
public String getSqlMigrationPrefix()
Sql migrations have the following file name structure: prefixVERSIONseparatorDESCRIPTIONsuffix , which using the defaults translates to V1_1__My_description.sql
public String getSqlMigrationSeparator()
Sql migrations have the following file name structure: prefixVERSIONseparatorDESCRIPTIONsuffix , which using the defaults translates to V1_1__My_description.sql
public String getSqlMigrationSuffix()
Sql migrations have the following file name structure: prefixVERSIONseparatorDESCRIPTIONsuffix , which using the defaults translates to V1_1__My_description.sql
public boolean isIgnoreFailedFutureMigration()
true to terminate normally and log a warning, false to fail fast with an exception.
(default: false)public boolean isValidateOnMigrate()
true if validate should be called. false if not. (default: true)public boolean isCleanOnValidationError()
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 !
true if clean should be called. false if not. (default: false)public MigrationVersion getInitVersion()
public String getInitDescription()
public boolean isInitOnMigrate()
Whether to automatically call init when migrate is executed against a non-empty schema with no metadata table.
This schema will then be initialized with the initialVersion before executing the migrations.
Only migrations above initialVersion 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!
true if init should be called on migrate for non-empty schemas, false if not. (default: false)public boolean isOutOfOrder()
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.
true if outOfOrder migrations should be applied, false if not. (default: false)public MigrationResolver[] getResolvers()
public DataSource getDataSource()
public ClassLoader getClassLoader()
public void setIgnoreFailedFutureMigration(boolean ignoreFailedFutureMigration)
ignoreFailedFutureMigration - true to terminate normally and log a warning, false to fail
fast with an exception. (default: false)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 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 metadata table that will be used by Flyway.
By default (single-schema mode) the metadata 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 metadata table is placed in the first schema of the list.
table - The name of the schema metadata table that will be used by flyway. (default: schema_version)public void setTarget(MigrationVersion target)
target - The target version up to which Flyway should run migrations. Migrations with a higher version
number will not be applied. (default: the latest version)public void setTarget(String target)
target - The target version up to which Flyway should run migrations. Migrations with a higher version
number will not be applied. (default: the latest version)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 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: __)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 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.public void setClassLoader(ClassLoader classLoader)
classLoader - The ClassLoader to use for resolving migrations on the classpath. (default: Thread.currentThread().getContextClassLoader() )public void setInitVersion(MigrationVersion initVersion)
initVersion - The version to tag an existing schema with when executing init. (default: 1)public void setInitVersion(String initVersion)
initVersion - The version to tag an existing schema with when executing init. (default: 1)public void setInitDescription(String initDescription)
initDescription - The description to tag an existing schema with when executing init. (default: << Flyway Init >>)public void setInitOnMigrate(boolean initOnMigrate)
Whether to automatically call init when migrate is executed against a non-empty schema with no metadata table.
This schema will then be initialized with the initialVersion before executing the migrations.
Only migrations above initialVersion 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!
initOnMigrate - true if init 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()
public void setCallbacks(FlywayCallback... callbacks)
callbacks - The callbacks for lifecycle notifications. (default: none)public void setCallbacks(String... callbacks)
callbacks - The fully qualified class names of the callbacks for lifecycle notifications. (default: none)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 setResolvers(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 int migrate()
throws FlywayException
FlywayException - when the migration failed.public void validate()
throws FlywayException
FlywayException - when the validation failed.public void clean()
schemas property.FlywayException - when the clean fails.public MigrationInfoService info()
FlywayException - when the info retrieval failed.public void init()
throws FlywayException
FlywayException - when the schema initialization failed.public void repair()
throws FlywayException
FlywayException - when the metadata 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.Copyright © 2014. All rights reserved.