飞路失控无法正常工作 [英] flyway outOfOrder is not working as expected
问题描述
我正在尝试使用Maven在生产支持"分支(即V3.1)上应用无序迁移.3.1分支具有从3.1.0.1到3.1.0.12的12个迁移.前11个已经应用,在我的开发环境中,我已经从下一个版本3.3中进行了两次迁移.信息看起来像这样:
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 |
+----------------+----------------------------+---------------------+---------+
我在V3.1分支的mvn build输出文件夹中运行以下命令: mvn flyway:迁移-Dflyway.outOfOrder = true -P
I run the following command in my mvn build output folder in the V3.1 branch: 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分支.
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?
我的pom从父pom继承了以下内容,并且大多数配置值都是从配置文件传递的:
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>
推荐答案
这是我的解决方案.我用Java代码配置了flyway.是的,我设置了 validateOnMigrate -否.
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();
}
}
这篇关于飞路失控无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!