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 current schema.
 void configure(java.util.Properties properties)
          Configures Flyway with these properties.
 java.util.List<MetaDataTableRow> history()
          Returns the history (all applied migrations) of the database.
 void init(SchemaVersion initialVersion, java.lang.String description)
          Creates and initializes the Flyway metadata table.
 int migrate()
          Starts the database migration.
 void setBaseDir(java.lang.String baseDir)
          Sets the base directory on the classpath where the Sql migrations are located.
 void setBasePackage(java.lang.String basePackage)
          Sets the base package where the migrations are located.
 void setDataSource(javax.sql.DataSource dataSource)
          Sets the datasource to use.
 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 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 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 ValidationMode for checksum 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

setIgnoreFailedFutureMigration

public void setIgnoreFailedFutureMigration(boolean ignoreFailedFutureMigration)
Ignores failed future migrations when reading the metadata table. These are migrations that we 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 ValidationMode for checksum validation.

Parameters:
validationMode - The ValidationMode for checksum validation

setValidationErrorMode

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

Parameters:
validationErrorMode - The error mode for validation

setBasePackage

public void setBasePackage(java.lang.String basePackage)
Sets the base package where the migrations are located.

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

setBaseDir

public void setBaseDir(java.lang.String baseDir)
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: sql/location)

setEncoding

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

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

setTable

public void setTable(java.lang.String table)
Sets the name of the schema metadata table that will be used by flyway.

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 - A map of 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.

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. Uses validation type ALL if NONE is set.

Throws:
FlywayException - thrown when the validation failed.

clean

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


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(SchemaVersion initialVersion,
                 java.lang.String description)
          throws FlywayException
Creates and initializes the Flyway metadata table.

Parameters:
initialVersion - (Optional) The initial version to put in the metadata table. Only migrations with a version number higher than this one will be considered for this database.
description - (Optional) The description of the initial version.
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 © 2010. All Rights Reserved.