【发布时间】:2025-11-22 19:50:02
【问题描述】:
我正在将 Liquibase 集成到现有项目中。我使用 CLI 从数据库生成更改日志并执行 changeLogSync。我验证了 databasechangelog 表包含来自生成日志的数据。
当我尝试从 CLI 中生成的更改日志更新数据库时:
liquibase --changeLogFile=changeLog.xml --url="jdbc:postgresql://database_server:port/database --defaultSchemaName=public update
结果为@987654322@。
当我尝试在 Maven 中做同样的事情时它失败了:Failed to execute goal org.liquibase ... Error setting up or running Liquibase: Migaration failed for change set ... Reason: liquibase.exception.DatabaException: ERROR: relation already exists.
请注意,我没有修改 changeLog.xml 文件并且我已经执行了 changeLogSync,因此更新预计不会执行任何操作,但在使用 Maven 时它会尝试创建所有的关系。
Maven 配置具有以下结构:
<configuration>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
<propertyFile>liquibase.properties</propertyFile>
<defaultSchemaName>public</defaultSchemaName>
</configuration>
<executions>
<execution>
<id>update</id>
<phase>pre-integration-test</phase>
<goals>
<goal>updateSQL</goal>
<goal>update</goal>
</goals>
</execution>
</executions>
liquibase.properties 文件包含其余参数,与 CLI 命令中的参数相同。
liquibase 版本:3.4.1 postgresql 版本:9.4-1201-jdbc41
我知道我可以在 changeLog.xml 中使用先决条件来防止创建存在的表,但我认为在设计上最好修复 Maven 配置。
为什么 CLI 和 Maven 执行之间存在差异?对于如何使用 Maven/Liquibase(调试方法)解决此类问题的任何建议,我也将不胜感激。
【问题讨论】:
标签: postgresql maven liquibase