Skip to content

Latest commit

 

History

History
426 lines (413 loc) · 17.8 KB

migrate.md

File metadata and controls

426 lines (413 loc) · 17.8 KB
layout pill subtitle
gradle
migrate
gradle flywayMigrate

Gradle Task: flywayMigrate

Migrates the schema to the latest version. Flyway will create the schema history table automatically if it doesn't exist.

migrate

Usage

> gradle flywayMigrate

Configuration

{% include cfg/connectRetries.html %} {% include cfg/initSql.html %} {% include cfg/locations-maven-gradle.html %}
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
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 in the list will be automatically set as the default one during the migration. It will also be the one containing the schema history table.
table NO flyway_schema_history The name of Flyway's schema history table.
By default (single-schema mode) the schema history 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 schema history table is placed in the first schema of the list.
sqlMigrationPrefix NO V

The file name prefix for versioned SQL migrations.

Versioned SQL migrations have the following file name structure: prefixVERSIONseparatorDESCRIPTIONsuffix , which using the defaults translates to V1.1__My_description.sql
undoSqlMigrationPrefix {% include pro.html %} NO U

The file name prefix for undo SQL migrations.

Undo SQL migrations are responsible for undoing the effects of the versioned migration with the same version.

They have the following file name structure: prefixVERSIONseparatorDESCRIPTIONsuffix , which using the defaults translates to U1.1__My_description.sql
repeatableSqlMigrationPrefix NO R

The file name prefix for repeatable SQL migrations.

Repeatable SQL migrations have the following file name structure: prefixSeparatorDESCRIPTIONsuffix , which using the defaults translates to R__My_description.sql
sqlMigrationSeparator NO __ The file name separator for Sql migrations
sqlMigrationSuffixes NO .sql

The file name suffixes for SQL migrations.

SQL migrations have the following file name structure: prefixVERSIONseparatorDESCRIPTIONsuffix , which using the defaults translates to V1_1__My_description.sql

Multiple suffixes (like .sql,.pkg,.pkb) can be specified for easier compatibility with other tools such as editors with specific file associations.
stream {% include pro.html %} NO false Whether to stream SQL migrations when executing them. Streaming doesn't load the entire migration in memory at once. Instead each statement is loaded individually. This is particularly useful for very large SQL migrations composed of multiple MB or even GB of reference data, as this dramatically reduces Flyway's memory consumption.
batch {% include pro.html %} NO false Whether to batch SQL statements when executing them. Batching can save up to 99 percent of network roundtrips by sending up to 100 statements at once over the network to the database, instead of sending each statement individually. This is particularly useful for very large SQL migrations composed of multiple MB or even GB of reference data, as this can dramatically reduce the network overhead. This is supported for INSERT, UPDATE, DELETE, MERGE and UPSERT statements. All other statements are automatically executed without batching.
mixed NO false Whether to allow mixing transactional and non-transactional statements within the same migration
group NO false Whether to group all pending migrations together in the same transaction when applying them (only recommended for databases with support for DDL transactions)
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 Callback 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 run migrations. Migrations with a higher version number will not be applied. The string 'current' will be interpreted as MigrationVersion.CURRENT, a placeholder for the latest version that has been applied to the database.
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.

validateOnMigrate NO true Whether to automatically call validate or not when running migrate.
For each sql migration a CRC32 checksum is calculated when the sql script is executed. The validate mechanism checks if the sql migration in the classpath still has the same checksum as the sql migration already executed in the database.
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 schema history 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 schema history 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. Note that if the most recently applied migration is removed, Flyway has no way to know it is missing and will mark it as future instead.
ignoreIgnoredMigrations NO false Ignore ignored migrations when reading the schema history table. These are migrations that were added in between already migrated migrations in this version. For example: we have migrations available on the classpath with versions from 1.0 to 3.0. The schema history table indicates that version 1 was finished on 1.0.15, and the next one was 2.0.0. But with the next release a new migration was added to version 1: 1.0.16. Such scenario is ignored by migrate command, but by default is rejected by validate. When ignoreIgnoredMigrations is enabled, such case will not be reported by validate command. This is useful for situations where one must be able to deliver complete set of migrations in a delivery package for multiple versions of the product, and allows for further development of older versions.
ignoreFutureMigrations NO true Ignore future migrations when reading the schema history 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 schema history 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.
cleanDisabled NO false Whether to disable clean. This is especially useful for production environments where running clean can be quite a career limiting move.
baselineOnMigrate NO false Whether to automatically call baseline when migrate is executed against a non-empty schema with no metadata table. This schema will then be baselined with the baselineVersion before executing the migrations. Only migrations above baselineVersion will then be applied.
        <p>This is useful for initial Flyway production deployments on projects with an existing DB.</p>

        <p>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!</p>
    </td>
</tr>
<tr>
    <td>baselineVersion</td>
    <td>NO</td>
    <td>1</td>
    <td>The version to tag an existing schema with when executing baseline</td>
</tr>
<tr>
    <td>baselineDescription</td>
    <td>NO</td>
    <td>
        <nobr>&lt;&lt; Flyway Baseline &gt;&gt;</nobr>
    </td>
    <td>The description to tag an existing schema with when executing baseline</td>
</tr>
<tr>
    <td>installedBy</td>
    <td>NO</td>
    <td><i>Current database user</i></td>
    <td>The username that will be recorded in the schema history table as having applied the migration</td>
</tr>
<tr id="errorOverrides">
    <td>errorOverrides {% include pro.html %}</td>
    <td>NO</td>
    <td><i>none</i></td>
    <td><p>Rules for the built-in error handling that lets you override specific SQL states and errors codes from error
         to warning or from warning to error.</p>
         <p>Each error override has the following format: <code>STATE:12345:W</code>.
         It is a 5 character SQL state, a colon, the SQL error code, a colon and finally the desired
         behavior that should override the initial one. The following behaviors are accepted: <code>W</code> to force a warning
         and <code>E</code> to force an error.</p>
         <p>For example, to force Oracle stored procedure compilation issues to produce
         errors instead of warnings, the following errorOverride can be used: <code>99999:17110:E</code></p>
         </td>
</tr>
<tr id="dryRunOutput">
    <td>dryRunOutput {% include pro.html %}</td>
    <td>NO</td>
    <td><i>Execute directly against the database</i></td>
    <td>The file where to output the SQL statements of a migration dry run. If the file specified is in a non-existent
        directory, Flyway will create all directories and parent directories as needed.
        Omit to use the default mode of executing the SQL statements directly against the database.</td>
</tr>
<tr id="oracleSqlplus">
    <td>oracleSqlplus {% include pro.html %}</td>
    <td>NO</td>
    <td>false</td>
    <td>Whether to Flyway's support for Oracle SQL*Plus commands should be activated.</td>
</tr>
{% include cfg/licenseKey.html %}
</tbody>

Sample configuration

flyway {
    driver = 'org.hsqldb.jdbcDriver'
    url = 'jdbc:hsqldb:file:/db/flyway_sample;shutdown=true'
    user = 'SA'
    password = 'mySecretPwd'
    connectRetries = 10
    initSql = 'SET ROLE \'myuser\''
    schemas = ['schema1', 'schema2', 'schema3']
    table = 'schema_history'
    locations = ['classpath:migrations', 'classpath:db/pkg', 'filesystem:/sql-migrations']
    sqlMigrationPrefix = 'Migration-'
    undoSqlMigrationPrefix = 'downgrade'
    repeatableSqlMigrationPrefix = 'RRR'
    sqlMigrationSeparator = '__'
    sqlMigrationSuffixes = ['.sql', '.pkg', '.pkb']
    stream = true
    batch = true
    encoding = 'ISO-8859-1'
    placeholderReplacement = true
    placeholders = [
        'aplaceholder' : 'value',
        'otherplaceholder' : 'value123'
    ]
    placeholderPrefix = '#['
    placeholderSuffix = ']'
    resolvers = ['com.mycompany.proj.CustomResolver', 'com.mycompany.proj.AnotherResolver']
    skipDefaultResolvers = false
    callbacks = ['com.mycompany.proj.CustomCallback', 'com.mycompany.proj.AnotherCallback']
    skipDefaultCallbacks = false
    target = '1.1'
    outOfOrder = false
    validateOnMigrate = true
    cleanOnValidationError = false
    mixed = false
    group = false
    ignoreMissingMigrations = false
    ignoreIgnoredMigrations = false
    ignoreFutureMigrations = false
    cleanDisabled = false
    baselineOnMigrate = false
    baselineVersion = 5
    baselineDescription = "Let's go!"
    installedBy = "my-user"
    errorOverrides = ['99999:17110:E', '42001:42001:W']
    dryRunOutput = '/my/sql/dryrun-outputfile.sql'
    oracleSqlplus = true 
}

Sample output

> gradle flywayMigrate -i

Current schema version: 0 Migrating to version 1 Migrating to version 1.1 Migrating to version 1.2 Migrating to version 1.3 Successfully applied 4 migrations (execution time 00:00.091s).

Important Note

When using Spring JDBC migrations, you must declare a dependency on org.springframework:spring-jdbc:${springVersion} in Gradle's buildScript block to avoid being hit with a java.lang.LinkageError.

Gradle: clean