com.googlecode.flyway.core
Class Flyway

java.lang.Object
  extended by com.googlecode.flyway.core.Flyway

public class Flyway
extends Object

This is the centre point of Flyway, and for most users, the only class they will ever have to deal with.

It is THE public API from which all important Flyway functions such as clean, validate and migrate can be called.


Constructor Summary
Flyway()
          Creates a new instance of Flyway.
 
Method Summary
 void clean()
          Drops all objects (tables, views, procedures, triggers, ...) in the configured schemas.
 void configure(Properties properties)
          Configures Flyway with these properties.
 String getBaseDir()
          Deprecated. Uses getLocations instead. Will be removed in Flyway 3.0.
 String getBasePackage()
          Deprecated. Uses getLocations instead. Will be removed in Flyway 3.0.
 DataSource getDataSource()
          Retrieves the dataSource to use to access the database.
 String getEncoding()
          Retrieves the encoding of Sql migrations.
 String getInitialDescription()
          Retrieves the description of the initial version.
 MigrationVersion getInitialVersion()
          Retrieves the initial version to put in the database.
 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 setBaseDir(String baseDir)
          Deprecated. Use setLocations instead. Will be removed in Flyway 3.0.
 void setBasePackage(String basePackage)
          Deprecated. Use setLocations instead. Will be removed in Flyway 3.0.
 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 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 setInitialDescription(String initialDescription)
          The description of the initial version.
 void setInitialVersion(MigrationVersion initialVersion)
          The initial version to put in the database.
 void setInitialVersion(com.googlecode.flyway.core.migration.SchemaVersion initialVersion)
          Deprecated. Use setInitialVersion(MigrationVersion) instead. Will be removed in Flyway 3.0.
 void setInitialVersion(String initialVersion)
          The initial version to put in the database.
 void setInitOnMigrate(boolean initOnMigrate)
           Whether to automatically call init when migrate is executed against a non-empty schema with no metadata table.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Flyway

public Flyway()
Creates a new instance of Flyway. This is your starting point.

Method Detail

getLocations

public String[] getLocations()
Retrieves locations on the classpath to scan recursively for migrations. Locations may contain both sql and java-based migrations.

Returns:
Locations on the classpath to scan recursively for migrations. Locations may contain both sql and java-based migrations. (default: db/migration)

getBasePackage

@Deprecated
public String getBasePackage()
Deprecated. Uses getLocations instead. Will be removed in Flyway 3.0.

Retrieves the base package where the Java migrations are located.

Returns:
The base package where the Java migrations are located. (default: db.migration)

getBaseDir

@Deprecated
public String getBaseDir()
Deprecated. Uses getLocations instead. Will be removed in Flyway 3.0.

Retrieves the base directory on the classpath where the Sql migrations are located.

Returns:
The base directory on the classpath where the Sql migrations are located. (default: db/migration)

getEncoding

public String getEncoding()
Retrieves the encoding of Sql migrations.

Returns:
The encoding of Sql migrations. (default: UTF-8)

getSchemas

public String[] getSchemas()
Retrieves the schemas managed by Flyway. The first schema in the list will be automatically set as the default one during the migration. It will also be the one containing the metadata table. These schema names are case-sensitive.

Returns:
The schemas managed by Flyway. (default: The default schema for the datasource connection)

getTable

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.

Returns:
The name of the schema metadata table that will be used by flyway. (default: schema_version)

getTarget

public MigrationVersion getTarget()
Retrieves the target version up to which Flyway should run migrations. Migrations with a higher version number will not be applied.

Returns:
The target version up to which Flyway should run migrations. Migrations with a higher version number will not be applied. (default: the latest version)

getPlaceholders

public Map<String,String> getPlaceholders()
Retrieves the map of <placeholder, replacementValue> to apply to sql migration scripts.

Returns:
The map of <placeholder, replacementValue> to apply to sql migration scripts.

getPlaceholderPrefix

public String getPlaceholderPrefix()
Retrieves the prefix of every placeholder.

Returns:
The prefix of every placeholder. (default: ${ )

getPlaceholderSuffix

public String getPlaceholderSuffix()
Retrieves the suffix of every placeholder.

Returns:
The suffix of every placeholder. (default: } )

getSqlMigrationPrefix

public String getSqlMigrationPrefix()
Retrieves the file name prefix for sql migrations.

Returns:
The file name prefix for sql migrations. (default: V)

getSqlMigrationSuffix

public String getSqlMigrationSuffix()
Retrieves the file name suffix for sql migrations.

Returns:
The file name suffix for sql migrations. (default: .sql)

isIgnoreFailedFutureMigration

public boolean isIgnoreFailedFutureMigration()
Whether to ignore failed future migrations when reading the metadata table. These are migrations that were performed by a newer deployment of the application that are not yet available in this version. For example: we have migrations available on the classpath up to version 3.0. The metadata table indicates that a migration to version 4.0 (unknown to us) has already been attempted and failed. Instead of bombing out (fail fast) with an exception, a warning is logged and Flyway terminates normally. This is useful for situations where a database rollback is not an option. An older version of the application can then be redeployed, even though a newer one failed due to a bad migration.

Returns:
true to terminate normally and log a warning, false to fail fast with an exception. (default: false)

getValidationMode

@Deprecated
public com.googlecode.flyway.core.validation.ValidationMode getValidationMode()
Deprecated. Use isValidateOnMigrate instead. Will be removed in Flyway 3.0.

Retrieves the mode for validation. Only used for migrate. When using validate validationMode is always ALL.

Returns:
The mode for validation. (default: NONE)

getValidationErrorMode

@Deprecated
public com.googlecode.flyway.core.validation.ValidationErrorMode getValidationErrorMode()
Deprecated. Use isCleanOnValidationError instead. Will be removed in Flyway 3.0.

Retrieves the error mode for validation.

Returns:
The error mode for validation. (default: FAIL)

isValidateOnMigrate

public boolean isValidateOnMigrate()
Whether to automatically call validate or not when running migrate.

Returns:
true if validate should be called. false if not. (default: false)

isCleanOnValidationError

public boolean isCleanOnValidationError()
Whether to automatically call clean or not when a validation error occurs.

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 !

Returns:
true if clean should be called. false if not. (default: false)

getInitialVersion

public MigrationVersion getInitialVersion()
Retrieves the initial version to put in the database. Only used for init.

Returns:
The initial version to put in the database. (default: 0)

getInitialDescription

public String getInitialDescription()
Retrieves the description of the initial version. Only used for init.

Returns:
The description of the initial version. (default: << Flyway Init >>)

isDisableInitCheck

@Deprecated
public boolean isDisableInitCheck()
Deprecated. Use initOnMigrate instead. Will be removed in Flyway 3.0.

Flag to disable the check that a non-empty schema has been properly initialized with init. This check ensures Flyway does not migrate or clean the wrong database in case of a configuration mistake. Be careful when disabling this!

Returns:
true if the check is disabled. false if it is active. (default: false)

isInitOnMigrate

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!

Returns:
true if init should be called on migrate for non-empty schemas, false if not. (default: false)

isOutOfOrder

public boolean isOutOfOrder()
Allows migrations to be run "out of order".

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.

Returns:
true if outOfOrder migrations should be applied, false if not. (default: false)

getDataSource

public DataSource getDataSource()
Retrieves the dataSource to use to access the database. Must have the necessary privileges to execute ddl.

Returns:
The dataSource to use to access the database. Must have the necessary privileges to execute ddl.

setIgnoreFailedFutureMigration

public void setIgnoreFailedFutureMigration(boolean ignoreFailedFutureMigration)
Ignores failed future migrations when reading the metadata table. These are migrations that were performed by a newer deployment of the application that are not yet available in this version. For example: we have migrations available on the classpath up to version 3.0. The metadata table indicates that a migration to version 4.0 (unknown to us) has already been attempted and failed. Instead of bombing out (fail fast) with an exception, a warning is logged and Flyway terminates normally. This is useful for situations where a database rollback is not an option. An older version of the application can then be redeployed, even though a newer one failed due to a bad migration.

Parameters:
ignoreFailedFutureMigration - true to terminate normally and log a warning, false to fail fast with an exception. (default: false)

setValidationMode

@Deprecated
public void setValidationMode(com.googlecode.flyway.core.validation.ValidationMode validationMode)
Deprecated. Use setValidateOnMigrate instead. Will be removed in Flyway 3.0.

Sets the mode for validation. Only used for migrate. When using validate validationMode is always ALL.

Parameters:
validationMode - The mode for validation. (default: NONE)

setValidationErrorMode

@Deprecated
public void setValidationErrorMode(com.googlecode.flyway.core.validation.ValidationErrorMode validationErrorMode)
Deprecated. Use setCleanOnValidationError instead. Will be removed in Flyway 3.0.

Sets the error mode for validation.

Parameters:
validationErrorMode - The error mode for validation. (default: FAIL)

setValidateOnMigrate

public void setValidateOnMigrate(boolean validateOnMigrate)
Whether to automatically call validate or not when running migrate.

Parameters:
validateOnMigrate - true if validate should be called. false if not. (default: false)

setCleanOnValidationError

public void setCleanOnValidationError(boolean cleanOnValidationError)
Whether to automatically call clean or not when a validation error occurs.

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 !

Parameters:
cleanOnValidationError - true if clean should be called. false if not. (default: false)

setLocations

public void setLocations(String... locations)
Sets the locations on the classpath to scan recursively for migrations. Locations may contain both sql and java-based migrations. (default: db.migration)

Parameters:
locations - Locations on the classpath to scan recursively for migrations. Locations may contain both sql and java-based migrations. (default: db/migration)

setBasePackage

@Deprecated
public void setBasePackage(String basePackage)
Deprecated. Use setLocations instead. Will be removed in Flyway 3.0.

Sets the base package where the migrations are located.

Parameters:
basePackage - The base package where the migrations are located. (default: db.migration)

setBaseDir

@Deprecated
public void setBaseDir(String baseDir)
Deprecated. Use setLocations instead. Will be removed in Flyway 3.0.

Sets the base directory on the classpath where the Sql migrations are located.

Parameters:
baseDir - The base directory on the classpath where the Sql migrations are located. (default: db/migration)

setEncoding

public void setEncoding(String encoding)
Sets the encoding of Sql migrations.

Parameters:
encoding - The encoding of Sql migrations. (default: UTF-8)

setSchemas

public void setSchemas(String... schemas)
Sets the schemas managed by Flyway. The first schema in the list will be automatically set as the default one during the migration. It will also be the one containing the metadata table. These schema names are case-sensitive.

Parameters:
schemas - The schemas managed by Flyway. May not be null. Must contain at least one element.

setTable

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.

Parameters:
table - The name of the schema metadata table that will be used by flyway. (default: schema_version)

setTarget

@Deprecated
public void setTarget(com.googlecode.flyway.core.migration.SchemaVersion target)
Deprecated. Use setTarget(MigrationVersion) instead. Will be removed in Flyway 3.0.

Sets the target version up to which Flyway should run migrations. Migrations with a higher version number will not be applied.

Parameters:
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)

setTarget

public void setTarget(MigrationVersion target)
Sets the target version up to which Flyway should run migrations. Migrations with a higher version number will not be applied.

Parameters:
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)

setTarget

public void setTarget(String target)
Sets the target version up to which Flyway should run migrations. Migrations with a higher version number will not be applied.

Parameters:
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)

setPlaceholders

public void setPlaceholders(Map<String,String> placeholders)
Sets the placeholders to replace in sql migration scripts.

Parameters:
placeholders - The map of <placeholder, replacementValue> to apply to sql migration scripts.

setPlaceholderPrefix

public void setPlaceholderPrefix(String placeholderPrefix)
Sets the prefix of every placeholder.

Parameters:
placeholderPrefix - The prefix of every placeholder. (default: ${ )

setPlaceholderSuffix

public void setPlaceholderSuffix(String placeholderSuffix)
Sets the suffix of every placeholder.

Parameters:
placeholderSuffix - The suffix of every placeholder. (default: } )

setSqlMigrationPrefix

public void setSqlMigrationPrefix(String sqlMigrationPrefix)
Sets the file name prefix for sql migrations.

Parameters:
sqlMigrationPrefix - The file name prefix for sql migrations (default: V)

setSqlMigrationSuffix

public void setSqlMigrationSuffix(String sqlMigrationSuffix)
Sets the file name suffix for sql migrations.

Parameters:
sqlMigrationSuffix - The file name suffix for sql migrations (default: .sql)

setDataSource

public void setDataSource(DataSource dataSource)
Sets the datasource to use. Must have the necessary privileges to execute ddl.

Parameters:
dataSource - The datasource to use. Must have the necessary privileges to execute ddl.

setInitialVersion

@Deprecated
public void setInitialVersion(com.googlecode.flyway.core.migration.SchemaVersion initialVersion)
Deprecated. Use setInitialVersion(MigrationVersion) instead. Will be removed in Flyway 3.0.

The initial version to put in the database. Only used for init.

Parameters:
initialVersion - The initial version to put in the database. (default: 0)

setInitialVersion

public void setInitialVersion(MigrationVersion initialVersion)
The initial version to put in the database. Only used for init.

Parameters:
initialVersion - The initial version to put in the database. (default: 0)

setInitialVersion

public void setInitialVersion(String initialVersion)
The initial version to put in the database. Only used for init.

Parameters:
initialVersion - The initial version to put in the database. (default: 0)

setInitialDescription

public void setInitialDescription(String initialDescription)
The description of the initial version. Only used for init.

Parameters:
initialDescription - The description of the initial version. (default: << Flyway Init >>)

setDisableInitCheck

@Deprecated
public void setDisableInitCheck(boolean disableInitCheck)
Deprecated. Use initOnMigrate instead. Will be removed in Flyway 3.0.

Flag to disable the check that a non-empty schema has been properly initialized with init. This check ensures Flyway does not migrate or clean the wrong database in case of a configuration mistake. Be careful when disabling this!

Parameters:
disableInitCheck - true if the check is disabled. false if it is active. (default: false)

setInitOnMigrate

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!

Parameters:
initOnMigrate - true if init should be called on migrate for non-empty schemas, false if not. (default: false)

setOutOfOrder

public void setOutOfOrder(boolean outOfOrder)
Allows migrations to be run "out of order".

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.

Parameters:
outOfOrder - true if outOfOrder migrations should be applied, false if not. (default: false)

migrate

public int migrate()
            throws FlywayException
Starts the database migration. All pending migrations will be applied in order.

Returns:
The number of successfully applied migrations.
Throws:
FlywayException - when the migration failed.

validate

public void validate()
              throws FlywayException
Validate applied migration with classpath migrations to detect accidental changes.

Throws:
FlywayException - when the validation failed.

clean

public void clean()
Drops all objects (tables, views, procedures, triggers, ...) in the configured schemas.

Throws:
FlywayException - when the clean fails.

status

@Deprecated
public com.googlecode.flyway.core.metadatatable.MetaDataTableRow status()
Deprecated. Use flyway.info().current() instead. Will be removed in Flyway 3.0.

Returns the status (current version) of the database.

Returns:
The latest applied migration, or null if no migration has been applied yet.

history

@Deprecated
public List<com.googlecode.flyway.core.metadatatable.MetaDataTableRow> history()
Deprecated. Use flyway.info().applied() instead. Will be removed in Flyway 3.0.

Returns the history (all applied migrations) of the database.

Returns:
All migrations applied to the database, sorted, oldest first. An empty list if none.

info

public MigrationInfoService info()
Retrieves the complete information about all the migrations including applied, pending and current migrations with details and status.

Returns:
All migrations sorted by version, oldest first.
Throws:
FlywayException - when the info retrieval failed.

init

public void init()
          throws FlywayException
Creates and initializes the Flyway metadata table.

Throws:
FlywayException - when the schema initialization failed.

repair

public void repair()
            throws FlywayException
Repairs the Flyway metadata table after a failed migration. User objects left behind must still be cleaned up manually.

Throws:
FlywayException - when the metadata table repair failed.

configure

public void configure(Properties properties)
Configures Flyway with these properties. This overwrites any existing configuration. Property names are documented in the flyway maven plugin.

Parameters:
properties - Properties used for configuration.
Throws:
FlywayException - when the configuration failed.


Copyright © 2012. All Rights Reserved.