【问题标题】:H2 and flyway crush on tests after upgrade from gradle 4 to 6从 gradle 4 升级到 6 后,H2 和 flyway 在测试中崩溃
【发布时间】:2020-09-13 02:28:48
【问题描述】:

我正在从 gradle 4 升级到 6。 这迫使我升级了很多东西,比如 spring、h2、mySql 连接器等。

现在我遇到了这个问题: 在运行时,使用 MySQL 一切正常。 但在测试中,我得到:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flyway' defined in com.bluerbn.wallet.infra.SpringTestConfiguration: Invocation of init method failed; nested exception is org.flywaydb.core.internal.command.DbMigrate$FlywayMigrateException: 
Migration V9__fixIndex.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__fixIndex.sql (/Users/.../resources/db/migration/V9__fixIndex.sql)
Line       : 1
Statement  : ALTER TABLE table1 DROP INDEX ACC_INDEX

这是升级前运行良好的旧脚本。

版本:

  • 弹簧靴:2.3.0
  • org.flywaydb:flyway-core:6.4.1(虽然在gradle中我放了6.4.2)
  • com.h2database:h2:1.4.200
  • mysql:mysql-connector-java:8.0.18

有什么想法吗?

【问题讨论】:

    标签: spring-boot h2 flyway


    【解决方案1】:

    H2 因为版本 1.4.200 只在 MySQL 兼容模式下允许 MySQL 风格的 ALTER TABLE tableName DROP INDEX indexName。在 1.4.199 和更早的版本中,这个无效的(用于 H2)命令在所有模式下都被错误地接受了。

    您需要将 ;MODE=MySQL 附加到 H2 的 JDBC URL。

    【讨论】:

    • spring.datasource.url=jdbc:h2:mem:test;MODE=MySQL;DB_CLOSE_ON_EXIT=FALSE;AUTO_RECONNECT=TRUE;INIT=如果不存在则创建模式 \\"public\\"\\; SET SCHEMA 公开;这是我的网址
    • 这个异常明显说明H2没有运行在MySQL兼容模式下。如果您没有@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) 或类似的东西(AFAIK,此注释已弃用),Spring 将忽略您的测试配置。
    • 顺便说一句,"public" 与默认设置下的public 不同,您可能希望使用;DATABASE_TO_LOWER=TRUE 而不是这样的INIT 命令。
    猜你喜欢
    • 1970-01-01
    • 2020-09-11
    • 1970-01-01
    • 2019-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-04
    相关资源
    最近更新 更多