liquibase / liquibase-gradle-plugin

A Gradle plugin for Liquibase
Other
197 stars 57 forks source link

[spring boot] ./gradlew diffChangeLog isn't updating changelog correctly #47

Closed nelson687se closed 1 year ago

nelson687se commented 5 years ago

When I run ./gradlew diffChangeLog, liquibase detects the changes but when it modifies my changelog.groovy it inserts the new lines with formatting errors or typos. Like a wrong merge conflict fix. For example, after running that command, this is being inserted in changelog.groovy

lumn(name: 'testTable', type: 'INT')
      column(name: 'name', type: 'VARCHAR(255)')
      column(name: 'priority', type: 'INT')
      column(name: 'timezone', type: 'VARCHAR(255)')
      column(name: 'type', type: 'VARCHAR(255)')
    }
  }

instead of Column it says lumn - Also, the whole databaseChangeLog block closes and then, after the closing curly brace, there are more changesets inserted. Which shouldn't be happening. Tried with thegroovy liquibase dsl plugin and also with the yaml version and in both cases the same is happening.

stevesaliman commented 5 years ago

I'm not sure what might be going on. I just tried running gradlew diffChangeLog on one of my projects and it generated a changelog that was over 5,000 lines long without any syntax problems on a Linux system.

My project is not a Spring Boot application, and my urls were standard jdbc urls. Are you using the Liquibase Spring Boot plugin? What do your URLs look like?

nelson687se commented 5 years ago

This is my build.gradle file. There is not liquibase spring boot plugin, as springboot comes with liquibase built in.

    ext {
        springBootVersion = '2.0.5.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath 'org.liquibase.ext:liquibase-hibernate5:3.6'
    }
}

plugins {
    id 'java'
    id 'eclipse'
    id 'org.springframework.boot' version '2.0.5.RELEASE'
    id 'io.spring.dependency-management' version '1.0.6.RELEASE'
    id 'org.liquibase.gradle' version '2.0.1'
}

group = 'com.flashsales.flights'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    compileOnly('org.projectlombok:lombok:1.16.20')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile ("org.springframework.boot:spring-boot-starter-data-jpa")
    compile ('mysql:mysql-connector-java')
    compile('org.liquibase:liquibase-core')
    compile('org.liquibase:liquibase-groovy-dsl:2.0.1')
    runtime('org.springframework.boot:spring-boot-devtools')
    testImplementation('org.springframework.boot:spring-boot-starter-test')
    testCompile(group:'net.bytebuddy', name:'byte-buddy', version:'1.8.22')
    liquibaseRuntime 'org.liquibase:liquibase-core'
    liquibaseRuntime 'org.liquibase:liquibase-groovy-dsl:2.0.1'
    liquibaseRuntime 'mysql:mysql-connector-java'
    liquibaseRuntime 'org.springframework.boot:spring-boot-starter-data-jpa'
    liquibaseRuntime 'org.springframework.boot:spring-boot-starter-web'
    liquibaseRuntime 'org.liquibase.ext:liquibase-hibernate5:3.6'
    liquibaseRuntime sourceSets.main.output
}

liquibase {
  activities {
    main {
      changeLogFile 'src/main/resources/db/changelog/changelog.groovy'
      url 'jdbc:mysql://localhost:3306/fsb?autoReconnect=true'
      referenceUrl 'hibernate:spring:com.company.domain?dialect=org.hibernate.dialect.MySQLDialect'
      username 'root'
      password ''
    }
  }
}

What I do is: I first run: ./gradlew generateChangelog - Then ./gradlew diffChangeLog and everything is fine. I run the app, and it creates the database changes. After that, I make a change in a domain class (deleting or adding a property), and want to generate the changeset for that change so I run again ./gradlew diffChangeLog and this is when the changelog.groovy gets messed up.

stevesaliman commented 5 years ago

My guess is that the hibernate plugin might be interfering somehow. Do you have a sample project that shows the problem that I could use to debug how the plugin reacts?

nelson687se commented 5 years ago

Sure, I've uploaded this: https://github.com/nelson687/springboot-liquibase - I ran ./gradlew generateChangelog and got the empty changelog, then I ran ./gradlew diffChangeLog against an empty database and got the changelog populated. After this, I run the app, and I get the database structure created, now, if I remove a property from TestTable and run ./gradlew diffChangeLog again, this is when I get the issues in the file

stevesaliman commented 5 years ago

A can now reproduce the problem, but I'm not sure what could be causing it. I'm pretty sure the error is in the Liquiabse Groovy DSL. I'll keep working on it.

nelson687se commented 5 years ago

I tried without the Liquibase Groovy DSL and it's also happening the same. Is there no workaround for this then? The only option is to write the changesets manually?

stevesaliman commented 5 years ago

I seem to remember trying it without the DSL and having it do the right thing. I'll have to try it again to be sure.

I would be a bit surprised if the issue did wind up being a plugin issue since the plugin is just a thin wrapper around the main Liquibase method.

At the moment, the only workaround I can think of is to re-run generateChangeLog to recreate the changelog from scratch. However, if it changes the ids of the changesets, that won't help much.

I will work on a fix for this issue as soon as I can. Next weekend is out for me, but I should be able to work on it the following weekend.

stevesaliman commented 5 years ago

I have some good news and some bad news....

The good news is that I've found the source of the bug.

The bad news is that the bug is in Liquibase itself - the diffChangeLog command only supports XML changelogs.

I created CORE-3343 in the Liquibase Jira system to track this problem. There is also an explanation of why this is happening in the Jira.

If you aren't editing changelogs by hand, then the format is less important and you could switch to XML changelogs as a workaround. XML changelogs don't appear to have this problem.

stevesaliman commented 1 year ago

Closing due to inactivity. This can't be fixed without resolving the underlying Liquibase issue, and there hasn't been any movement on that issue in 5 years.