提问者:小点点

Flyway H2和MySql升级后不匹配


我陷入了深深的泥潭:(

我想把gradle从4升级到6。这让我升级了spring,最终升级了flyway和H2。

现在,不幸的是,我在测试中遇到了飞行路线错误。

以下是一些信息:

 api "org.springframework.boot:spring-boot-starter-json:2.2.2.RELEASE"
api "org.springframework.boot:spring-boot-starter-web:2.2.2.RELEASE"
    api "org.springframework.boot:spring-boot-starter-data-jpa:2.2.2.RELEASE"
testImplementation("org.springframework.boot:spring-boot-starter-test:2.2.2.RELEASE") {
    exclude (group: 'com.h2database', module: 'h2')
}

api("mysql:mysql-connector-java:5.1.38")
implementation 'org.flywaydb:flyway-core:6.4.2'
testImplementation("com.h2database:h2:1.4.199") {
  force = true
}

在升级之前,一切正常。现在我收到了关于另一个版本(尽管我使用的是推荐的)版本的奇怪警告,以及大量或错误。:

 WARN  o.f.c.i.d.b.Database:53 - Flyway upgrade recommended: H2 1.4.200 is newer than this version of Flyway and support has not been tested. The latest supported version of H2 is 1.4.199.

ERROR o.f.c.i.c.DbMigrate:57 - Migration of schema "PUBLIC" to version 9 - fixCheckingAccountIndex failed! Please restore backups and roll back database and code!


SQL State  : 42S22
Error Code : 42122
Message    : Column "INDEX" not found; SQL statement:
ALTER TABLE table1 DROP INDEX ACC_INDEX [42122-200]
Location   : db/migration/V9__fixAccountIndex.sql 
Line       : 1
Statement  : ALTER TABLE checking_account DROP INDEX BTA_CHECKING_ACC_INDEX

测试属性:

spring.jpa.hibernate.ddl-auto=none
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:test;MODE=MySQL;DB_CLOSE_ON_EXIT=FALSE;AUTO_RECONNECT=TRUE;INIT=create schema if not exists \\"public\"\\; SET SCHEMA public;
spring.datasource.username=root
spring.datasource.password=root

当我正常运行应用程序时,没有测试,一切正常。

有什么想法吗?

谢谢和问候,

编辑

我一直在试图理解为什么我得到了H2的200版本。

在我的depndecy树上:

gradle -q dependencies | grep h2
+--- com.h2database:h2:1.4.199 (n)
|    |    |         +--- com.h2database:h2:1.4.193 -> 1.4.200
+--- com.h2database:h2:1.4.199 -> 1.4.200
|    |    |         +--- com.h2database:h2:1.4.193 -> 1.4.200
+--- com.h2database:h2:1.4.199 -> 1.4.200
|    |    |         +--- com.h2database:h2:1.4.193 -> 1.4.200
+--- com.h2database:h2:1.4.199 -> 1.4.200
|    |    |         +--- com.h2database:h2:1.4.193 -> 1.4.200
+--- com.h2database:h2:1.4.199 -> 1.4.200

出于某种原因,它使用了较新的verison。

编辑2020-05-26

按照要求,这里是升级到spring 2.3.0后的错误

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flyway' defined in com...SpringTestConfiguration: Invocation of init method failed; nested exception is org.flywaydb.core.internal.command.DbMigrate$FlywayMigrateException: 
Migration V9__IndexFix.sql failed
------------------------------------------------
SQL State  : 42S22
Error Code : 42122
Message    : Column "INDEX" not found; SQL statement:
ALTER TABLE table1 DROP INDEX ACC_INDEX [42122-200]
Location   : db/migration/V9__IndexFix.sql (.../resources/db/migration/V9__IndexFix.sql)
Line       : 1
Statement  : ALTER TABLE table1 DROP INDEX ACC_INDEX

升级后,我在这篇帖子中抱怨的兼容性警告消失了

仍然是这个h2错误。在旧版本上它有效。当前版本:

组织。flywaydb:flyway core:6.4.1(虽然在gradle我放了6.4.2)com。h2数据库:h2:1.4.200


共1个答案

匿名用户

将您的Spring Boot依赖项更新为2.3.0。发布。

2.2。X在旧flyway版本(6.0.8)和不受支持的新H2版本(1.4.200)之间存在依赖不匹配。
Flyway 6.1.0支持H2 1.4.200。

即使您指定了一个更新的Flyway版本,我认为它也会像指定的H2版本一样被忽略。

编辑:
或者,您可以在Gradle中强制特定版本,如下所示:

allprojects {
    configurations.all {
        resolutionStrategy {
            dependencySubstitution {
                substitute module('com.h2database:h2') with module('com.h2database:h2:1.4.199')
            }
        }
    }
}