liquibase / liquibase-hibernate

Liquibase Hibernate Integration
Apache License 2.0
271 stars 154 forks source link

Database diff not considering column length #594

Open nfcunha opened 10 months ago

nfcunha commented 10 months ago

Hi everyone, I've encountered the following issue when running "diffChangelog" command in my project.

Currently, I have the following column in my database table: image

It is a varchar, length 1000.

On the entity source code, the following mapping is done.


public class Expression {

    // stuff

    @Column(name = "glossary", length = 1000)
    private String glossary;

    // stuff

}

With the code above, the initial changelog was created correctly, specifying the length, etc.

However, if I change the "length" attribute to anything else, proceed to clean and build the classpath once again, and run the "diffChangelog" task, the newer changelog generates empty, without the supposed "ALTER TABLE" command.

If I rename the column, the current column is dropped and the new column is created correctly. Looking into past issues, issue #450 supposedly solved it.

I'm using the following configurations/versions. Am I missing something?

liquibase.properties:

referenceUrl=hibernate:spring:com.org.models?dialect=org.hibernate.dialect.PostgreSQLDialect
referenceDriver=liquibase.ext.hibernate.database.connection.HibernateDriver

build.gradle (plugin):

plugins {
    id 'application'
    id 'org.liquibase.gradle' version '2.1.0'
}

build.gradle (dependencies):

// Liquibase
    implementation ('org.liquibase:liquibase-core:4.24.0'){
        exclude group: 'org.yaml', module: 'snakeyaml'
    }
    // https://mvnrepository.com/artifact/org.liquibase.ext/liquibase-hibernate5
    implementation group: 'org.liquibase.ext', name: 'liquibase-hibernate5', version: '4.24.0'
    liquibaseRuntime 'org.liquibase.ext:liquibase-hibernate5:4.24.0'
    liquibaseRuntime 'org.liquibase:liquibase-core:4.24.0'
    liquibaseRuntime 'org.liquibase:liquibase-groovy-dsl:2.1.1'
    liquibaseRuntime 'org.postgresql:postgresql:42.6.0'
    liquibaseRuntime sourceSets.main.output
    liquibaseRuntime 'org.springframework:spring-beans'
    liquibaseRuntime 'org.springframework:spring-jdbc'
    liquibaseRuntime 'org.springframework:spring-context'
    liquibaseRuntime 'org.springframework:spring-orm'
    liquibaseRuntime 'info.picocli:picocli:4.6.1'

build.gradle (config):

final Instant buildTime = Instant.now();
final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyddMMhhmmss")
        .withZone(ZoneId.systemDefault());
final String formattedBuildTime = formatter.format(buildTime);

liquibase {
    activities {
        main {
            changeLogFile "src/main/resources/db/changelogs/${formattedBuildTime}_changelog.sql"
            url "jdbc:postgresql://localhost:5432/my_db?currentSchema=my_schema"
            username "root"
            password "root"
        }
    }
}

Command being used to generate changelog:

gradle clean assemble diffChangelog

Thanks in advance.

filipelautert commented 4 months ago

@tati-qalified are you able to reproduce this one?