在我的项目中,我们有一个基本实体,其他实体从扩展而来
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;
}
每次运行diffChangelog
时,它都会创建新的变更集addDefaultValue
,即使这些变更集已经在表创建中设置
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.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
使用liquibasegradle插件v.2.1.1
Liquibase版本
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'
为什么要创建这些变更集,有什么方法可以避免生成它们吗?
这很可能是hibernate实现中的一个错误。您可以通过运行diff
操作来判断liquibase所看到的差异。diff命令会告诉你什么是不同的,而diffChangeLog会接受这些差异,并试图找出如何解决它们。
这可能是它错误地看待差异的问题,也可能是没有正确解决所看到的差异的问题。
你最好在https://github.com/liquibase/liquibase-hibernate/issues包括diff
为您报告的差异。