首页 文章

即使h2在MySQL模式下运行,Liquibase也会将h2检测为数据库[Spring boot]

提问于
浏览
1

我试图使用liquibase和h2(在mysql模式下)运行我的Spring Boot应用程序的测试 . Liquibase更改日志是MySQL特定的,因此我认为在启用liquibase和MySQL模式下使用h2进行测试可以解决问题 .

问题是Liquibase没有将数据库检测为MySQL而是检测为H2 . 因此,在执行迁移时,它使用错误的数据类型CLOB而不是TEXT,后来导致hibernate验证器失败 .

我需要知道是否有任何方法强制liquibase使用MySQL特定的迁移,无论应用程序实际连接到哪个数据库 . 不知道liquibase如何计算数据库,但我猜测使用驱动程序名称或db url可能?

如果有人有任何替代解决方案,请提出建议!

spring:
  profiles:
    active: test   
 datasource:
   url: jdbc:h2:mem:ebdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;MODE=MySQL
   username: sa
   password:
   driver-class-name: org.h2.Driver
 jpa:
   database-platform: org.hibernate.dialect.MySQL5Dialect
   database: MYSQL
   hibernate:
      ddl-auto: validate
liquibase:
  change-log: classpath:liquibase/liquibase-changeLog.xml
  enabled: true

1 回答

  • 0

    如果我已正确理解您的问题,您可以将 dbms="mysqldbms="h2" 属性添加到 changeSet 中:

    <changeSet id="theId" author="theAuthor" dbms="mysql">

    这样, liquibase 仅在您连接到 mysql 数据库时才会执行此 changeSet .

    Or 您可以添加 dbms 签入 preConditions

    <preConditions onFail="MARK_RAN">
        <dbms type="h2"/>
    </preConditions>
    

相关问题