简体   繁体   中英

Liquibase detects h2 as database even when h2 runs in MySQL mode [Spring boot]

I am trying to run the tests of my Spring Boot application using liquibase and h2 (in mysql mode). The Liquibase changelogs are MySQL specific so I was thinking that testing with liquibase enabled and h2 in MySQL mode would do the trick.

Problem is that Liquibase is not detecting the database as MySQL but as H2. So when performing migration it uses wrong data types eg CLOB instead of TEXT which later causes the hibernate validator to fail.

I need to know if there is any way to force liquibase to use MySQL specific migrations regardless of the database the application is actually connecting to. Not sure how liquibase figures out the database but I'm guessing using driver name or db url maybe?

If anyone has any alternative solutions, ideas please do suggest!

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

If I've understood your question correctly, you may add the dbms="mysql or dbms="h2" attribute to your changeSet as such:

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

This way, liquibase will execute this changeSet only if you're connected to mysql database.

Or you can add dbms check in preConditions :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM