升级后 Flyway H2 和 MySql 不匹配
Flyway H2 and MySql mismatch after upgrading
我深陷泥潭:(
我想将 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 版本。
在我的依赖树上:
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
出于某种原因,它使用了较新的版本。
编辑 2020-05-26
这里要求的是升级到spring2.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
我在此post抱怨的兼容性警告在升级后消失了
还是这个h2错误。在旧版本上它有效。
当前版本:
org.flywaydb:flyway-core:6.4.1(尽管在 gradle 中我输入了 6.4.2)
com.h2 数据库:h2:1.4.200
将 Spring 引导依赖项更新为 2.3。0.RELEASE。
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')
}
}
}
}
我深陷泥潭:(
我想将 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 版本。
在我的依赖树上:
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
出于某种原因,它使用了较新的版本。
编辑 2020-05-26
这里要求的是升级到spring2.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
我在此post抱怨的兼容性警告在升级后消失了
还是这个h2错误。在旧版本上它有效。 当前版本:
org.flywaydb:flyway-core:6.4.1(尽管在 gradle 中我输入了 6.4.2) com.h2 数据库:h2:1.4.200
将 Spring 引导依赖项更新为 2.3。0.RELEASE。
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')
}
}
}
}