Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flyway outOfOrder is not working as expected

Tags:

flyway

I am trying to apply an outOfOrder migration using maven on a "production support" branch (i.e. V3.1). The 3.1 branch has 12 migrations 3.1.0.1 through 3.1.0.12. The first 11 have been applied and in my development environment I have two migrations from the next release 3.3 already applied. the info looks like this:

+----------------+----------------------------+---------------------+---------+
| Version        | Description                | Installed on        | State   |
+----------------+----------------------------+---------------------+---------+
| 1              | >          | 2013-08-16 16:35:22 | Success |
| 3.1.0.1        | CCI DDL                    | 2013-08-16 16:41:04 | Success |
| 3.1.0.2        | Update 1                   | 2013-08-19 12:17:43 | Success |
| 3.1.0.3        | Add SVT ITEM HISTORY       | 2013-08-21 16:24:28 | Success |
| 3.1.0.4        | Drop Col Event Key From ED | 2013-08-27 14:15:36 | Success |
| 3.1.0.5        | Add Job Begin Time COL     | 2013-10-10 14:59:14 | Success |
| 3.1.0.6        | Update SVT Column Lengths  | 2013-10-23 10:25:33 | Success |
| 3.1.0.7        | Add Seq Number to EDC ECRF | 2013-12-03 14:59:31 | Success |
| 3.1.0.8        | Set EDC ECRF ITEM Seq Numb | 2013-12-03 15:27:08 | Success |
| 3.1.0.9        | Add Table EDC USV FORM     | 2013-12-03 15:37:47 | Success |
| 3.1.0.10       | Add Table SVT USV FORM MAP | 2013-12-03 15:52:24 | Success |
| 3.1.0.11       | Add Tables SUBJECT VISIT Q | 2014-04-29 17:09:13 | OutOrde |
| 3.1.0.12       | Add Table BOGUS ERIC TEST  |                     | Ignored |
| 3.3.0.1        | Insert iMedidata CRS Info  | 2014-04-24 10:50:38 | Future  |
| 3.3.0.2        | Insert Study OBJECT TYPE   | 2014-04-24 11:14:37 | Future  |
+----------------+----------------------------+---------------------+---------+

I run the following command in my mvn build output folder in the V3.1 branch: mvn flyway:migrate -Dflyway.outOfOrder=true -P

and I get the following output:

[ERROR] Failed to execute goal org.flywaydb:flyway-maven-plugin:3.0:migrate (default-cli) on project mdmws: org.flywaydb.core.api.FlywayException: Validate failed. Found differences between applied migrations and available migrations: Detected applied migration missing on the classpath: 3.3.0.1 -> [Help 1]

It seems to want to find the 3.3 migrations that have already been applied to the database in the same classpath target/db/migrations folder, but of course these files exist in a later release branch. Either I am missing some configuration setting or I do not understand the way the outOfOrder works. I do not want to pull these files back from the V3.3 branch to the V3.1 branch.

Can somebody please help explain?

My pom inherits the following from a parent pom and most of the configuration values are passed in from the profile:

      <groupId>org.flywaydb</groupId>
      <artifactId>flyway-maven-plugin</artifactId>
      <version>3.0</version>

    <configuration>
      <driver>${flyway.driver}</driver>
      <url>${flyway.url}</url>
      <user>${flyway.user}</user>
      <password>${flyway.password}</password>
      <outOfOrder>${flyway.outOfOrder}</outOfOrder>
    </configuration>
    <dependencies>
      <dependency>
        <groupId>com.oracle.ojdbc</groupId>
        <artifactId>ojdbc6</artifactId>
        <version>11.2.0.3</version>
      </dependency>
    </dependencies>
  </plugin>
like image 439
ericwood Avatar asked Apr 30 '14 13:04

ericwood


People also ask

What is Flyway outOfOrder?

flyway.outOfOrder=true. This makes it possible to run migrations created out of order. This is useful, for example, if two developers create non-conflicting migrations at the same time and want to migrate their local development databases after pulling down each others changes from version control.

How do I test Flyway migration?

Run Flyway migration tests Once you've pushed all your scripts to GitHub, you can now manually run the migration test workflow by navigating to the Actions tab in GitHub and clicking on 'Database migration test', then 'Run workflow'.

How do you skip Flyway migration?

The hotfix migration can be deployed with Flyway with skipExecutingMigrations=true . The schema history table will be updated with the new migration, but the script itself won't be executed again. skipExecutingMigrations can be used with with cherryPick to skip specific migrations.

Does Flyway support rollbacks?

A rollback script can become a Flyway undo script, once the migration script is successfully committed, but a Flyway undo script cannot be used for a rollback unless you modify it heavily.


2 Answers

Set validateOnMigrate to false and you should be OK. By default it will check whether the resolved and the applied migrations match. In your specific situation this won't work, so you have to disable it.

like image 177
Axel Fontaine Avatar answered Sep 19 '22 09:09

Axel Fontaine


That's my solution. I configured flyway in Java code. Yes, I set validateOnMigrate - false.

@Bean(name = "flyway")
@Lazy(false)
public Flyway buildConfiguredFlyway() {
    Flyway flyway = configure();
    if (!validate(flyway)) {
        migrate(flyway);
    }
    return flyway;
}

private Flyway configure() {
    Flyway flyway = new Flyway();
    flyway.setDataSource(datasource);
    flyway.setBaselineOnMigrate(true);//Create meta-data table if it did not exist.
    flyway.setValidateOnMigrate(false);

    return flyway;
}

private boolean validate(Flyway flyway) {
    try {
        flyway.validate();
        return true;
    } catch (FlywayException o) {
        return false;
    }
}

private void migrate(Flyway flyway) {
    try {
        int result = flyway.migrate();
        LOGGER.info("Number of DB mirgations successfully applied: " + result);
    } catch (FlywayException e) {
        LOGGER.error(e.getMessage(), e);
        ((ConfigurableApplicationContext) applicationContext).stop();
    }
}
like image 23
Yan Khonski Avatar answered Sep 19 '22 09:09

Yan Khonski