Search code examples
hibernatequarkusliquibasequarkus-panacheliquibase-maven-plugin

Generate Liquibase diff changelog using Liquibase maven plugin in Quarkus


I am trying to use the Liquibase Maven plugin in Quarkus to generate a diff changelog based on my entities in my entity package. I noticed that it requires a referenceUrl in the liquibase.properties file as a reference for comparison.

In Spring framework, it is possible to achieve this by setting the reference URL to something like hibernate:spring:path-to-package?dialect=org.hibernate.dialect.PostgreSQLDialect. However, I could not find a workaround for it in Quarkus.

Is it even possible to achieve this in Quarkus, or should I write the changelog file manually?


Solution

  • Answer by @peterhuba is incorrect. Apparently you need to do a lot more in Quarkus as you need to add spring data, spring jpa and spring envers dependency in liquibaseRuntime phase.

    There is no direct way of doing this, but answer is it's tricky but yes you can achieve it. It's not very neat but close to a working solution.

    You can also check certain discussions in Quarkus Github as well as Liquibase-hibernate issues here and here

    In my ecosystem I use gradle.

    configurations {
        compileOnly {
            extendsFrom annotationProcessor
        }
        liquibase
        liquibaseRuntime.extendsFrom runtime
    }
    
    ext {
        diffChangeLogVersion = "CHANGE-0002"
        rollbackTagVersion = "CHANGE-0002"
        diffChangeLogFile = "src/main/resources/XXXX/db-changelog-${diffChangeLogVersion}.oracle.sql"
        entitiesPackage =  XXX.XXX.XXX.XXX"
        hibernateGenericDialect = "org.hibernate.dialect.OracleDialect"
        springCoreVersion = "6.1.2"
        springDataVersion = "3.2.1"
    }
    
    dependencies {
        // Liquibase
        implementation "io.quarkus:quarkus-liquibase"
        liquibaseRuntime "org.liquibase.ext:liquibase-hibernate6:4.30.0"
        //liquibaseRuntime "org.liquibase:liquibase-groovy-dsl:3.0.2"
        liquibaseRuntime "info.picocli:picocli:4.7.5"
        liquibaseRuntime "com.oracle.database.jdbc:ojdbc11-production:23.2.0.0"
        liquibaseRuntime "javax.xml.bind:jaxb-api:2.3.1"
        liquibaseRuntime "ch.qos.logback:logback-core:1.2.9"
        liquibaseRuntime "ch.qos.logback:logback-classic:1.2.9"
    
        liquibaseRuntime "org.springframework:spring-core:${springCoreVersion}"
        liquibaseRuntime "org.springframework.data:spring-data-jpa:${springDataVersion}"
        liquibaseRuntime "org.springframework.data:spring-data-envers:${springDataVersion}"
        liquibaseRuntime sourceSets.main.output
    }
    
    task deleteDiffChangeLog(type: Delete) {
        delete diffChangeLogFile
    }
    
    task liquibaseEntitiesToDbDiffChangelog(type: JavaExec) {
        dependsOn deleteDiffChangeLog
        group = "liquibase"
        classpath sourceSets.main.runtimeClasspath
        classpath configurations.liquibaseRuntime
        mainClass = "liquibase.integration.commandline.LiquibaseCommandLine"
        args "--logLevel=FINE"
        args "--changeLogFile=${diffChangeLogFile}"
        args "--url=${dbURL}"
        args "--username=${dbUser}"
        args "--password=${dbPassword}"
        args "--defaultSchemaName=${dbSchema}"
        args "--driver=${dbDriver}"
        args "--referenceUrl=hibernate:spring:${entitiesPackage}?dialect=${hibernateGenericDialect}"
        args "diffChangeLog"
    }