升级后的Flyway H2和MySql不匹配。

问题描述 投票:0回答:1

我让自己陷入了深深的泥潭 :(

我想把gradle从4升级到6.这导致我升级了spring,最后升级了flyway和H2。

现在,不幸的是,我在测试中得到了flyway错误。

下面是一些信息。

 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关于另一个版本(虽然我使用推荐的)版本,和很多或错误.....:

 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

test -properties:

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

因为某些原因,它使用了新的版本。

EDIT 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错误,在老版本上可以用,当前版本。

org.flywaydb:flyway-core:6.4.1(虽然在gradle中我放了6.4.2)com.h2database:h2:1.4.200。

spring-boot h2 flyway
1个回答
1
投票

更新你的Spring Boot依赖关系到2.3.0.RELEASE。

2.2.X在旧的flyway版本(6.0.8)和不支持的新H2版本(1.4.200)之间存在依赖关系不匹配的问题。H2 1.4.200的支持是在Flyway 6.1.0时出现的。

即使你指定了一个较新的Flyway版本--我认为它和指定的H2版本一样会被忽略。

编辑:或者你可以像这样在Gradle中强制执行特定的版本。

allprojects {
    configurations.all {
        resolutionStrategy {
            dependencySubstitution {
                substitute module('com.h2database:h2') with module('com.h2database:h2:1.4.199')
            }
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.