flyway outOfOrder没有按预期工作

时间:2014-04-30 13:04:37

标签: flyway

我正在尝试使用maven在"生产支持"上应用outOfOrder迁移。分支(即V3.1)。 3.1分支有12个迁移3.1.0.1到3.1.0.12。前11个已经应用,在我的开发环境中,我已经应用了下一个版本3.3中的两个迁移。信息如下:

+----------------+----------------------------+---------------------+---------+
| 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  |
+----------------+----------------------------+---------------------+---------+

我在V3.1分支的mvn build输出文件夹中运行以下命令:      mvn flyway:migrate -Dflyway.outOfOrder = true -P

我得到以下输出:

[错误]无法在项目mdmws上执行目标org.flywaydb:flyway-maven-plugin:3.0:migrate(default-cli):org.flywaydb.core.api.FlywayException:验证失败。发现应用的迁移与可用迁移之间存在差异:类路径中检测到的已应用迁移丢失:3.3.0.1 - > [帮助1]

似乎想要在同一个classpath target / db / migrations文件夹中找到已经应用于数据库的3.3迁移,但当然这些文件存在于更高版本的分支中。要么我缺少一些配置设置,要么我不理解outOfOrder的工作方式。我不想将这些文件从V3.3分支拉回到V3.1分支。

有人可以帮忙解释一下吗?

我的pom从父pom继承以下内容,大部分配置值都从配置文件中传入:

      <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>

2 个答案:

答案 0 :(得分:1)

validateOnMigrate设为false,您应该没问题。默认情况下,它将检查已解决和已应用的迁移是否匹配。在您的具体情况下,这将无效,因此您必须禁用它。

答案 1 :(得分:1)

这是我的解决方案。我在Java代码中配置了flyway。是的,我设置 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();
    }
}