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.
|
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.
|
String |
getInitialDescription()
Deprecated.
Use getInitDescription() instead. Will be removed in Flyway 3.0.
|
MigrationVersion |
getInitialVersion()
Deprecated.
Use getInitVersion() instead. Will be removed in Flyway 3.0.
|
MigrationVersion |
getInitVersion()
Retrieves the version to tag an existing schema with when executing init.
|
String[] |
getLocations()
Retrieves locations on the classpath 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[] |
getSchemas()
Retrieves the schemas managed by Flyway.
|
String |
getSqlMigrationPrefix()
Retrieves the file name prefix 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.
|
com.googlecode.flyway.core.validation.ValidationErrorMode |
getValidationErrorMode()
Deprecated.
Use isCleanOnValidationError instead. Will be removed in Flyway 3.0.
|
com.googlecode.flyway.core.validation.ValidationMode |
getValidationMode()
Deprecated.
Use isValidateOnMigrate instead. Will be removed in Flyway 3.0.
|
List<com.googlecode.flyway.core.metadatatable.MetaDataTableRow> |
history()
Deprecated.
Use flyway.info().applied() instead. Will be removed in Flyway 3.0.
|
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 |
isDisableInitCheck()
Deprecated.
Use initOnMigrate instead. Will be removed in Flyway 3.0.
|
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 after a failed migration.
|
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)
Sets the datasource to use.
|
void |
setDisableInitCheck(boolean disableInitCheck)
Deprecated.
Use initOnMigrate instead. Will be removed in Flyway 3.0.
|
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 |
setInitialDescription(String initialDescription)
Deprecated.
Use setInitDescription(String) instead. Will be removed in Flyway 3.0.
|
void |
setInitialVersion(MigrationVersion initialVersion)
Deprecated.
Use setInitVersion(MigrationVersion) instead. Will be removed in Flyway 3.0.
|
void |
setInitialVersion(com.googlecode.flyway.core.migration.SchemaVersion initialVersion)
Deprecated.
Use setInitVersion(MigrationVersion) instead. Will be removed in Flyway 3.0.
|
void |
setInitialVersion(String initialVersion)
Deprecated.
Use setInitVersion(String) instead. Will be removed in Flyway 3.0.
|
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 on the classpath 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 |
setSchemas(String... schemas)
Sets the schemas managed by Flyway.
|
void |
setSqlMigrationPrefix(String sqlMigrationPrefix)
Sets the file name prefix 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(com.googlecode.flyway.core.migration.SchemaVersion target)
Deprecated.
Use setTarget(MigrationVersion) instead. Will be removed in Flyway 3.0.
|
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 |
setValidationErrorMode(com.googlecode.flyway.core.validation.ValidationErrorMode validationErrorMode)
Deprecated.
Use setCleanOnValidationError instead. Will be removed in Flyway 3.0.
|
void |
setValidationMode(com.googlecode.flyway.core.validation.ValidationMode validationMode)
Deprecated.
Use setValidateOnMigrate instead. Will be removed in Flyway 3.0.
|
com.googlecode.flyway.core.metadatatable.MetaDataTableRow |
status()
Deprecated.
Use flyway.info().current() instead. Will be removed in Flyway 3.0.
|
void |
validate()
Validate applied migration with classpath migrations to detect accidental changes.
|
public Flyway()
public String[] getLocations()
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()
public String getSqlMigrationSuffix()
public boolean isIgnoreFailedFutureMigration()
true to terminate normally and log a warning, false to fail fast with an exception.
(default: false)@Deprecated public com.googlecode.flyway.core.validation.ValidationMode getValidationMode()
@Deprecated public com.googlecode.flyway.core.validation.ValidationErrorMode getValidationErrorMode()
public boolean isValidateOnMigrate()
true if validate should be called. false if not. (default: false)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)@Deprecated public MigrationVersion getInitialVersion()
@Deprecated public String getInitialDescription()
public MigrationVersion getInitVersion()
public String getInitDescription()
@Deprecated public boolean isDisableInitCheck()
true if the check is disabled. false if it is active. (default: false)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 DataSource getDataSource()
public void setIgnoreFailedFutureMigration(boolean ignoreFailedFutureMigration)
ignoreFailedFutureMigration - true to terminate normally and log a warning, false to fail
fast with an exception. (default: false)@Deprecated public void setValidationMode(com.googlecode.flyway.core.validation.ValidationMode validationMode)
validationMode - The mode for validation. (default: NONE)@Deprecated public void setValidationErrorMode(com.googlecode.flyway.core.validation.ValidationErrorMode validationErrorMode)
validationErrorMode - The error mode for validation. (default: FAIL)public void setValidateOnMigrate(boolean validateOnMigrate)
validateOnMigrate - true if validate should be called. false if not. (default: false)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)
locations - Locations on the classpath to scan recursively for migrations. Locations may contain both sql
and java-based 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)@Deprecated public void setTarget(com.googlecode.flyway.core.migration.SchemaVersion 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(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)
sqlMigrationPrefix - The file name prefix for sql migrations (default: V)public void setSqlMigrationSuffix(String sqlMigrationSuffix)
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)
url - The JDBC URL of the database.user - The user of the database.password - The password of the database.@Deprecated public void setInitialVersion(com.googlecode.flyway.core.migration.SchemaVersion initialVersion)
initialVersion - The version to tag an existing schema with when executing init. (default: 1)@Deprecated public void setInitialVersion(MigrationVersion initialVersion)
initialVersion - The version to tag an existing schema with when executing init. (default: 1)@Deprecated public void setInitialVersion(String initialVersion)
initialVersion - The version to tag an existing schema with when executing init. (default: 1)@Deprecated public void setInitialDescription(String initialDescription)
initialDescription - The description to tag an existing schema with when executing init. (default: << Flyway Init >>)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 >>)@Deprecated public void setDisableInitCheck(boolean disableInitCheck)
disableInitCheck - true if the check is disabled. false if it is active. (default: false)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 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.@Deprecated public com.googlecode.flyway.core.metadatatable.MetaDataTableRow status()
null if no migration has been applied yet.@Deprecated public List<com.googlecode.flyway.core.metadatatable.MetaDataTableRow> history()
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)
properties - Properties used for configuration.FlywayException - when the configuration failed.Copyright © 2013. All rights reserved.