com.googlecode.flyway.core
Class Flyway

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

public class Flyway
extends java.lang.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()
           
 
Method Summary
 void clean()
          Drops all objects (tables, views, procedures, triggers, ...) in the configured schemas.
 void configure(java.util.Properties properties)
          Configures Flyway with these properties.
 java.lang.String getBaseDir()
          Deprecated. Uses getLocations instead. Will be removed in Flyway 2.0.
 java.lang.String getBasePackage()
          Deprecated. Uses getLocations instead. Will be removed in Flyway 2.0.
 javax.sql.DataSource getDataSource()
          Retrieves the dataSource to use to access the database.
 java.lang.String getEncoding()
          Retrieves the encoding of Sql migrations.
 java.lang.String getInitialDescription()
          Retrieves the description of the initial version.
 SchemaVersion getInitialVersion()
          Retrieves the initial version to put in the database.
 java.lang.String[] getLocations()
          Retrieves locations on the classpath to scan recursively for migrations.
 java.lang.String getPlaceholderPrefix()
          Retrieves the prefix of every placeholder.
 java.util.Map<java.lang.String,java.lang.String> getPlaceholders()
          Retrieves the map of <placeholder, replacementValue> to apply to sql migration scripts.
 java.lang.String getPlaceholderSuffix()
          Retrieves the suffix of every placeholder.
 java.lang.String[] getSchemas()
          Retrieves the schemas managed by Flyway.
 java.lang.String getSqlMigrationPrefix()
          Retrieves the file name prefix for sql migrations.
 java.lang.String getSqlMigrationSuffix()
          Retrieves the file name suffix for sql migrations.
 java.lang.String getTable()
          Retrieves the name of the schema metadata table that will be used by Flyway.
 SchemaVersion getTarget()
          Retrieves the target version up to which Flyway should run migrations.
 ValidationErrorMode getValidationErrorMode()
          Retrieves the error mode for validation.
 ValidationMode getValidationMode()
          Retrieves the mode for validation.
 java.util.List<MetaDataTableRow> history()
          Returns the history (all applied migrations) of the database.
 void init()
          Creates and initializes the Flyway metadata table.
 boolean isDisableInitCheck()
          Flag to disable the check that a non-empty schema has been properly initialized with init.
 boolean isIgnoreFailedFutureMigration()
          Retrieves whether to ignore failed future migrations when reading the metadata table.
 int migrate()
          Starts the database migration.
 void setBaseDir(java.lang.String baseDir)
          Deprecated. Use setLocations instead. Will be removed in Flyway 2.0.
 void setBasePackage(java.lang.String basePackage)
          Deprecated. Use setLocations instead. Will be removed in Flyway 2.0.
 void setDataSource(javax.sql.DataSource dataSource)
          Sets the datasource to use.
 void setDisableInitCheck(boolean disableInitCheck)
          Flag to disable the check that a non-empty schema has been properly initialized with init.
 void setEncoding(java.lang.String encoding)
          Sets the encoding of Sql migrations.
 void setIgnoreFailedFutureMigration(boolean ignoreFailedFutureMigration)
          Ignores failed future migrations when reading the metadata table.
 void setInitialDescription(java.lang.String initialDescription)
          The description of the initial version.
 void setInitialVersion(SchemaVersion initialVersion)
          The initial version to put in the database.
 void setLocations(java.lang.String... locations)
          Sets the locations on the classpath to scan recursively for migrations.
 void setPlaceholderPrefix(java.lang.String placeholderPrefix)
          Sets the prefix of every placeholder.
 void setPlaceholders(java.util.Map<java.lang.String,java.lang.String> placeholders)
          Sets the placeholders to replace in sql migration scripts.
 void setPlaceholderSuffix(java.lang.String placeholderSuffix)
          Sets the suffix of every placeholder.
 void setSchemas(java.lang.String... schemas)
          Sets the schemas managed by Flyway.
 void setSqlMigrationPrefix(java.lang.String sqlMigrationPrefix)
          Sets the file name prefix for sql migrations.
 void setSqlMigrationSuffix(java.lang.String sqlMigrationSuffix)
          Sets the file name suffix for sql migrations.
 void setTable(java.lang.String table)
          Sets the name of the schema metadata table that will be used by Flyway.
 void setTarget(SchemaVersion target)
          Sets the target version up to which Flyway should run migrations.
 void setValidationErrorMode(ValidationErrorMode validationErrorMode)
          Sets the error mode for validation.
 void setValidationMode(ValidationMode validationMode)
          Sets the mode for validation.
 MetaDataTableRow status()
          Returns the status (current version) of the database.
 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()
Method Detail

getLocations

public java.lang.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 java.lang.String getBasePackage()
Deprecated. Uses getLocations instead. Will be removed in Flyway 2.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 java.lang.String getBaseDir()
Deprecated. Uses getLocations instead. Will be removed in Flyway 2.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 java.lang.String getEncoding()
Retrieves the encoding of Sql migrations.

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

getSchemas

public java.lang.String[] getSchemas()
Retrieves the schemas managed by Flyway. The first schema in the list will be the one containing the metadata table.

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

getTable

public java.lang.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 SchemaVersion 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 java.util.Map<java.lang.String,java.lang.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 java.lang.String getPlaceholderPrefix()
Retrieves the prefix of every placeholder.

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

getPlaceholderSuffix

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

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

getSqlMigrationPrefix

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

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

getSqlMigrationSuffix

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

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

isIgnoreFailedFutureMigration

public boolean isIgnoreFailedFutureMigration()
Retrieves 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

public ValidationMode getValidationMode()
Retrieves the mode for validation. Only used for migrate. When using validate validationMode is always ALL.

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

getValidationErrorMode

public ValidationErrorMode getValidationErrorMode()
Retrieves the error mode for validation.

Returns:
The error mode for validation.

getInitialVersion

public SchemaVersion 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 java.lang.String getInitialDescription()
Retrieves the description of the initial version. Only used for init.

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

isDisableInitCheck

public boolean isDisableInitCheck()
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)

getDataSource

public javax.sql.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. (default: false)

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

setValidationMode

public void setValidationMode(ValidationMode validationMode)
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

public void setValidationErrorMode(ValidationErrorMode validationErrorMode)
Sets the error mode for validation.

Parameters:
validationErrorMode - The error mode for validation

setLocations

public void setLocations(java.lang.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(java.lang.String basePackage)
Deprecated. Use setLocations instead. Will be removed in Flyway 2.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(java.lang.String baseDir)
Deprecated. Use setLocations instead. Will be removed in Flyway 2.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(java.lang.String encoding)
Sets the encoding of Sql migrations.

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

setSchemas

public void setSchemas(java.lang.String... schemas)
Sets the schemas managed by Flyway. The first schema in the list will be the one containing the metadata table.

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

setTable

public void setTable(java.lang.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

public void setTarget(SchemaVersion 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(java.util.Map<java.lang.String,java.lang.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(java.lang.String placeholderPrefix)
Sets the prefix of every placeholder.

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

setPlaceholderSuffix

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

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

setSqlMigrationPrefix

public void setSqlMigrationPrefix(java.lang.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(java.lang.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(javax.sql.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

public void setInitialVersion(SchemaVersion 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(java.lang.String initialDescription)
The description of the initial version. Only used for init.

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

setDisableInitCheck

public void setDisableInitCheck(boolean disableInitCheck)
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)

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 - Thrown when the migration failed.

validate

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

Throws:
FlywayException - thrown when the validation failed.

clean

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


status

public MetaDataTableRow status()
Returns the status (current version) of the database.

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

history

public java.util.List<MetaDataTableRow> history()
Returns the history (all applied migrations) of the database.

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

init

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

Throws:
FlywayException - when the schema initialization failed.

configure

public void configure(java.util.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.