Want to deploy your JVM, Node.js and Go apps effortlessly to AWS? Try our service Boxfuse

Maven Goal: Validate

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
validate

Default Phase

  • pre-integration-test

Usage

> mvn flyway:validate

Configuration

Parameter Required Default Description
url YES The jdbc url to use to connect to the database
driver NO Auto-detected based on url The fully qualified classname of the jdbc driver to use to connect to the database
serverId NO flyway-db The id of the server in the Maven settings.xml file to load the credentials from.

This is an alternative to passing the credentials in directly through properties.
user NO The user to use to connect to the database
password NO The password to use to connect to the database
schemas 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.
table 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.
locations 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.
sqlMigrationPrefix NO V The file name prefix for Sql migrations
repeatableSqlMigrationPrefix NO R The file name prefix for repeatable Sql migrations
sqlMigrationSeparator NO __ The file name separator for Sql migrations
sqlMigrationSuffix NO .sql The file name suffix for Sql migrations
encoding NO UTF-8 The encoding of Sql migrations
placeholderReplacement NO true Whether placeholders should be replaced
placeholders NO Placeholders to replace in Sql migrations
placeholderPrefix NO ${ The prefix of every placeholder
placeholderSuffix NO } The suffix of every placeholder
resolvers NO Fully qualified class names of custom MigrationResolver implementations to be used in addition to the built-in ones for resolving Migrations to apply.
skipDefaultResolvers NO false Whether default built-in resolvers (sql, jdbc and spring-jdbc) should be skipped. If true, only custom resolvers are used.
callbacks NO Fully qualified class names of FlywayCallback implementations to use to hook into the Flyway lifecycle.
skipDefaultCallbacks NO false Whether default built-in callbacks (sql) should be skipped. If true, only custom callbacks are used.
target 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.
outOfOrder 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.

cleanOnValidationError 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 !
ignoreMissingMigrations 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.
ignoreFutureMigrations 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.
skip NO false Skips the execution of the plugin for this module
configFile NO flyway.properties Properties file from which to load the Flyway configuration. The names of the individual properties match the ones you would use as Maven or System properties. The encoding of the file must be the same as the encoding defined with the flyway.encoding property, which is UTF-8 by default. Relative paths are relative to the POM.

Sample configuration

<configuration>
    <driver>org.hsqldb.jdbcDriver</driver>
    <url>jdbc:hsqldb:file:${project.build.directory}/db/flyway_sample;shutdown=true</url>
    <user>SA</user>
    <password>mySecretPwd</password>
    <schemas>
        <schema>schema1</schema>
        <schema>schema2</schema>
        <schema>schema3</schema>
    </schemas>
    <table>schema_history</table>
    <locations>
        <location>classpath:migrations1</location>
        <location>migrations2</location>
        <location>filesystem:/sql-migrations</location>
    </locations>
    <sqlMigrationPrefix>Migration-</sqlMigrationPrefix>
    <repeatableSqlMigrationPrefix>RRR</repeatableSqlMigrationPrefix>
    <sqlMigrationSeparator>__</sqlMigrationSeparator>
    <sqlMigrationSuffix>-OK.sql</sqlMigrationSuffix>
    <encoding>ISO-8859-1</encoding>
    <placeholderReplacement>true</placeholderReplacement>
    <placeholders>
        <aplaceholder>value</aplaceholder>
        <otherplaceholder>value123</otherplaceholder>
    </placeholders>
    <placeholderPrefix>#[</placeholderPrefix>
    <placeholderSuffix>]</placeholderSuffix>
    <resolvers>
        <resolver>com.mycompany.project.CustomResolver</resolver>
        <resolver>com.mycompany.project.AnotherResolver</resolver>
    </resolvers>
    <skipDefaultResolvers>false</skipDefaultResolvers>
    <callbacks>
        <callback>com.mycompany.project.CustomCallback</callback>
        <callback>com.mycompany.project.AnotherCallback</callback>
    </callbacks>
    <skipDefaultCallbacks>false</skipDefaultCallbacks>
    <target>1.1</target>
    <outOfOrder>false</outOfOrder>
    <cleanOnValidationError>false</cleanOnValidationError>
    <ignoreMissingMigrations>false</ignoreMissingMigrations>
    <ignoreFutureMigrations>false</ignoreFutureMigrations>
    <skip>false</skip>
    <configFile>myConfig.properties</configFile>
</configuration>

Sample output

> mvn flyway:validate

[INFO] [flyway:validate {execution: default-cli}]
[INFO] Validated 5 migrations (execution time 00:00.030s)

Maven: baseline