liquibase / liquibase-gradle-plugin

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

diffChangelog creates redundant changesets #107

Closed jasperjanuar closed 1 year ago

jasperjanuar commented 1 year ago

In my project we have a base entity, which other entities extend from

public abstract class BaseEntity {
  @Column(updatable = false, nullable = false)
  @GeneratedValue
  @Id
  UUID id;

  @Version private long version;

  @CreationTimestamp
  @Column(nullable = false, updatable = false, columnDefinition = "TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP")
  private LocalDateTime created;

  @UpdateTimestamp
  @Column(nullable = false, updatable = true, columnDefinition = "TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP")
  private LocalDateTime updated;
}

every time diffChangelog is run it creates new changesets addDefaultValue even though these were already set at table creation

databaseChangeLog:
- changeSet:
    id: 1660844241773-1
    author: bob (generated)
    changes:
    - addDefaultValue:
        columnDataType: timestamp WITH TIME ZONE
        columnName: created
        defaultValueComputed: CURRENT_TIMESTAMP
        tableName: foo
- changeSet:
    id: 1660844241773-2
    author: bob (generated)
    changes:
    - addDefaultValue:
        columnDataType: timestamp WITH TIME ZONE
        columnName: created
        defaultValueComputed: CURRENT_TIMESTAMP
        tableName: baz
- changeSet:
    id: 1660844241773-3
    author: bob (generated)
    changes:
    - addDefaultValue:
        columnDataType: timestamp WITH TIME ZONE
        columnName: created
        defaultValueComputed: CURRENT_TIMESTAMP
        tableName: bar

liquibase.properties

liquibase.hub.mode=off
url=jdbc:postgresql://localhost:5432/foo
driver=org.postgresql.Driver
changelogFile=src/main/resources/db/db.changelog-master.yml
referenceDriver=liquibase.ext.hibernate.database.connection.HibernateDriver
referenceUrl=hibernate:spring:com.foo\
  ?dialect=org.hibernate.dialect.PostgreSQL10Dialect\
  &hibernate.physical_naming_strategy=org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy\
  &hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy

Using liquibase-gradle-plugin v. 2.1.1

Liquibase versions

    implementation 'org.liquibase:liquibase-core:4.14.0'
    implementation 'org.liquibase.ext:liquibase-hibernate5:4.14.0'
    liquibaseRuntime 'org.liquibase:liquibase-core:4.14.0'
    liquibaseRuntime 'org.postgresql:postgresql:42.3.6'
    liquibaseRuntime 'info.picocli:picocli:4.6.3'
    runtimeClasspath 'org.yaml:snakeyaml:1.30'
    liquibaseRuntime 'org.liquibase.ext:liquibase-hibernate5:4.14.0'
    liquibaseRuntime 'org.springframework.boot:spring-boot-starter-data-jpa:2.7.2'

Why are these changeset created, and is there any way to avoid them being generated?

stevesaliman commented 1 year ago

I have a strong hunch that this is problem either with Liquibase itself, or more likely, with the Hibernate plugin for Liquibase. The gradle-plugin is just a thin wrapper for the Liquibase CLI, and doesn't do any actual work with the database or Java objects.