1

I'm trying to set up the liquibase gradle plugin to generate my changelogs automatically. I have managed to run the plugin and obtain a changelog but the log being generated contains several problems.

The main problem that I'm having is that the generated changelog is asking the DB to delete the hibernate sequence table.

The relevant setup part of my build.gradle file is the following:

dependencies{
    //liquibase
    liquibaseRuntime 'org.liquibase:liquibase-core:3.8.1'
    liquibaseRuntime 'com.vaadin:vaadin-spring-boot-starter'
    liquibaseRuntime 'org.mariadb.jdbc:mariadb-java-client:'+mariaDbClient
    liquibaseRuntime 'mysql:mysql-connector-java:8.0.19'
    liquibaseRuntime 'org.liquibase.ext:liquibase-hibernate5:3.8' 
    liquibaseRuntime 'org.springframework.boot:spring-boot-starter'
    liquibaseRuntime 'org.springframework.boot:spring-boot-starter-security'
    liquibaseRuntime 'org.springframework.boot:spring-boot-starter-data-jpa'
    liquibaseRuntime sourceSets.main.output
}

diff.dependsOn compileJava
diffChangeLog.dependsOn compileJava
generateChangelog.dependsOn compileJava

configurations {
  liquibaseRuntime.extendsFrom runtime
}

liquibase {
  activities {
    diffMain {
      changeLogFile 'src/main/resources/db/liquibase-changelog-gen.xml'
      url 'jdbc:mysql://localhost:3306/ideasapps?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy'
      username 'xxx'
      password 'xxx'
      referenceUrl 'hibernate:spring:a.b.c?dialect=org.hibernate.dialect.MariaDBDialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy'
    }
  }
}

I'm using a mariaDB database that is compatible with the MySQL driver I have setup. I had to use the MySQL connector because there is a bug with the MariaDB one and the hibernate liquibase plugin (CORE-3457). The MySQL one runs. Also, I had to specify the naming strategy because the default one wasn't matching the strategy spring uses.

When I run gradlew diff I get this weird part where it doesn't recognize liquibase own tables and the hibernate sequence table:

Unexpected Column(s): 
 ideasapps.databasechangelog.AUTHOR
 ideasapps.databasechangelog.COMMENTS
 ideasapps.databasechangelog.CONTEXTS
 ideasapps.databasechangelog.DATEEXECUTED
 ideasapps.databasechangelog.DEPLOYMENT_ID
 ideasapps.databasechangelog.DESCRIPTION
 ideasapps.databasechangelog.EXECTYPE
 ideasapps.databasechangelog.FILENAME
 ideasapps.databasechangelog.ID
 ideasapps.databasechangeloglock.ID
 ideasapps.databasechangelog.LABELS
 ideasapps.databasechangelog.LIQUIBASE
 ideasapps.databasechangeloglock.LOCKED
 ideasapps.databasechangeloglock.LOCKEDBY
 ideasapps.databasechangeloglock.LOCKGRANTED
 ideasapps.databasechangelog.MD5SUM
 ideasapps.databasechangelog.ORDEREXECUTED
 ideasapps.databasechangelog.TAG
 ideasapps.hibernate_sequence.next_val

It also says that the hibernate sequence is missing:

Missing Sequence(s): 
 hibernate_sequence

Finally, when I run gradlew diffChangelog I'm getting this changeset:

<changeSet author="Orion (generated)" id="1587596582656-67">
    <dropTable tableName="hibernate_sequence"/>
</changeSet>

This breaks the application since it drops the table that hibernate uses to keep track of the current indexes. How to correctly setup this plugin to achieve correct changelog generation?

1 Answers1

0

I didn't found out what was causing the issue but I managed to resolve it by changing the table to a sequence through liquibase:

 <changeSet author="Lucas Carvalhaes" id="xxxxxxx">
    <preConditions onFail="MARK_RAN">
        <tableExists tableName="hibernate_sequence"/>
    </preConditions>

    <dropTable cascadeConstraints="true"
        tableName="hibernate_sequence"/>

    <createSequence
            cycle="false"
            ordered="true"
            sequenceName="hibernate_sequence"
            startValue="34494"/>
</changeSet>

I just used the original table value as the start value of the sequence to preserve my database (since it is a small value this isn't really a problem).