LiquiBase diff & diffChangeLog doesn't detect changes

2.7k Views Asked by At

I'm trying to generate a changeset with the changes I made in my @Entitys

I have the following gradle setup. I'm using these plugins liquibase-gradle-plugin liquibase-hibernate

dependencies {
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-data-rest')
    compile('org.springframework.boot:spring-boot-starter-hateoas')
    compile('org.springframework.boot:spring-boot-starter-jooq')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.springframework.boot:spring-boot-starter-mail')
    compile('com.github.waffle:waffle-spring-boot-starter:1.9.0')
    compile('com.oracle.jdbc:ojdbc8:12.2.0.1')
    runtime('org.springframework.boot:spring-boot-devtools')
    compileOnly('org.projectlombok:lombok')
    apt('org.projectlombok:lombok:1.18.2')
    liquibaseRuntime('org.liquibase:liquibase-core:3.6.2')
    liquibaseRuntime('org.liquibase:liquibase-groovy-dsl:2.0.1')
    liquibaseRuntime('org.liquibase.ext:liquibase-hibernate5:3.6')
    liquibaseRuntime('com.oracle.jdbc:ojdbc8:12.2.0.1')
    liquibaseRuntime('org.springframework.boot:spring-boot-starter-data-jpa')
    liquibaseRuntime sourceSets.main.output
    providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
    testCompile('org.springframework.boot:spring-boot-starter-test')
    testCompile('org.springframework.restdocs:spring-restdocs-mockmvc')
}

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

liquibase {
  activities {
    main {
      changeLogFile 'main.groovy'
      referenceUrl 'jdbc:oracle:thin:@localhost:1521:XE'
      referenceUsername 'user'
      referencePassword 'pass'
      url 'hibernate:spring:com.example' +
                   '?dialect=org.hibernate.dialect.Oracle10gDialect' +
                   '&hibernate.enhanced_id=true'
    }
  }
  runList = 'main'
}

Steps

  1. .\gradlew diffChangeLog
  2. .\gradlew update
  3. Observe the initial database have been correctly created
  4. Observe the DATABASECHANGELOG table have been correctly populated
  5. Add a property to an @Entity
  6. .\gradlew diffChangeLog
  7. Note that no new changeset have been added to the main.groovy file. Instead the existing changeset for the entity have been altered. Rendering everything completely useless!

What am I doing wrong?

2

There are 2 best solutions below

3
On

Liquibase does not generate schema from @entity but from changeset files.

You have to let hibernate/jpa/else generate the schema and then use diffChangeLog command. This allows you to generate a changeset file.

It could be easier to add your modifications in the changeset file, in parallel of annotation in your code.

3
On

Reading the wiki you should use gradle diff to generate a changeset file. Use gradle diffChangeLog only for the first master xml.