SBT Task: flywayValidate

Validate applied migrations against resolved ones (on the filesystem or classpath) to detect accidental changes that may prevent the schema(s) from being recreated exactly.

Validation fails if

  • differences in migration names, types or checksums are found
  • versions have been applied that aren't resolved locally anymore
  • versions have been resolved that haven't been applied yet

Usage

> sbt flywayValidate

Configuration

Parameter Required Default Description
flywayUrl YES The jdbc url to use to connect to the database
flywayDriver NO Auto-detected based on url The fully qualified classname of the jdbc driver to use to connect to the database
flywayUser NO The user to use to connect to the database
flywayPassword NO The password to use to connect to the database
flywaySchemas NO default schema of the connection Case-sensitive list of schemas managed by Flyway.
The first schema will be the one containing the metadata table.
flywayTable NO schema_version The name of Flyway's metadata table.
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.
flywayLocations NO filesystem:src/main/resources/db/migration Locations to scan recursively for migrations. 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.
flywaySqlMigrationPrefix NO V The file name prefix for Sql migrations
flywayRepeatableSqlMigrationPrefix NO R The file name prefix for repeatable Sql migrations
flywaySqlMigrationSeparator NO __ The file name separator for Sql migrations
flywaySqlMigrationSuffix NO .sql The file name suffix for Sql migrations
flywayEncoding NO UTF-8 The encoding of Sql migrations
flywayPlaceholderReplacement NO true Whether placeholders should be replaced
flywayPlaceholders NO Placeholders to replace in Sql migrations
flywayPlaceholderPrefix NO ${ The prefix of every placeholder
flywayPlaceholderSuffix NO } The suffix of every placeholder
flywayResolvers NO Fully qualified class names of custom MigrationResolver implementations to be used in addition to the built-in ones for resolving Migrations to apply.
flywaySkipDefaultResolvers NO false Whether default built-in resolvers (sql, jdbc and spring-jdbc) should be skipped. If true, only custom resolvers are used.
flywayCallbacks NO Fully qualified class names of FlywayCallback implementations to use to hook into the Flyway lifecycle.
flywaySkipDefaultCallbacks NO false Whether default built-in callbacks (sql) should be skipped. If true, only custom callbacks are used.
flywayTarget NO latest version The target version up to which Flyway should consider migrations. Migrations with a higher version number will be ignored. The special value current designates the current version of the schema.
flywayOutOfOrder NO false 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.

flywayCleanOnValidationError NO false 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 !
flywayIgnoreMissingMigrations NO false Ignore missing migrations when reading the metadata table. These are migrations that were performed by an older deployment of the application that are no longer available in this version. For example: we have migrations available on the classpath with versions 1.0 and 3.0. The metadata table indicates that a migration with version 2.0 (unknown to us) has also been applied. Instead of bombing out (fail fast) with an exception, a warning is logged and Flyway continues normally. This is useful for situations where one must be able to deploy a newer version of the application even though it doesn't contain migrations included with an older one anymore.
flywayIgnoreFutureMigrations NO true Ignore 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 applied. Instead of bombing out (fail fast) with an exception, a warning is logged and Flyway continues normally. This is useful for situations where one must be able to redeploy an older version of the application after the database has been migrated by a newer one.

Sample configuration

flywayDriver := "org.hsqldb.jdbcDriver"

flywayUrl := "jdbc:hsqldb:file:target/flyway_sample;shutdown=true"

flywayUser := "SA"

flywayPassword := "mySecretPwd"

flywaySchemas := Seq("schema1", "schema2", "schema3")

flywayTable := "schema_history"

flywayLocations := Seq("classpath:migrations1", "migrations2", "filesystem:/sql-migrations")

flywaySqlMigrationPrefix := "Migration-"

flywayRepeatableSqlMigrationPrefix := "RRR"

flywaySqlMigrationSeparator := "__"

flywaySqlMigrationSuffix := "-OK.sql"

flywayEncoding := "ISO-8859-1"

flywayPlaceholderReplacement := true

flywayPlaceholders := Map(
  "aplaceholder" -> "value",
  "otherplaceholder" -> "value123"
)

flywayPlaceholderPrefix := "#["

flywayPlaceholderSuffix := "]"

flywayResolvers := Seq("com.mycompany.CustomResolver", "com.mycompany.AnotherResolver")

flywaySkipDefaultResolvers := false

flywayCallbacks := Seq("com.mycompany.CustomCallback", "com.mycompany.AnotherCallback")

flywaySkipDefaultCallbacks := false

flywayTarget := "1.1"

flywayOutOfOrder := false

flywayCleanOnValidationError := false

flywayIgnoreMissingMigrations := false

flywayIgnoreFutureMigrations := false

Sample output

> sbt flywayValidate

[info] Validated 5 migrations (execution time 00:00.030s)

SBT: baseline