Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dropping hibernate sequence table on generated changelog #68

Open
lucasmontec opened this issue Apr 23, 2020 · 1 comment
Open

dropping hibernate sequence table on generated changelog #68

lucasmontec opened this issue Apr 23, 2020 · 1 comment

Comments

@lucasmontec
Copy link

lucasmontec commented Apr 23, 2020

Hello!
I'm actually not sure if this is a liquibase issue, gradle plugin issue, or just a setup issue. After fiddling with this for about a day I couldn't figure out what was happening. Because if that I decided to create an issue here. I have a stackoverflow running with this problem if any of you guys would like the reputation: https://stackoverflow.com/questions/61376885/liquibase-gradle-plugin-is-dropping-hibernate-sequence-table-on-generated-change

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>
@lucasmontec
Copy link
Author

I couldn't figure out what was causing this but I solved it by changing the table to a sequence anyway:

 <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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant