liquibase - 如何从 Java 应用的变更日志中获取前提条件?
问题描述
如果表存在,我正在尝试使用 PreConditions 跳过 CreateTable 变更集和 MARK_RAN。由于 Liquibase 在尝试在 MYSQL(在 AWS Aurora 中)中创建现有表时记录了表存在错误,因此似乎忽略了前提条件。
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.10.xsd">
<changeSet author="xxx" id="1231">
<preConditions onFail="MARK_RAN">
<not>
<tableExists tableName="tenant"/>
</not>
</preConditions>
<createTable tableName="tenant">
<column autoIncrement="true" name="tenantId" type="int(11)">
<constraints primaryKey="true" nullable="false"
unique="false" />
</column>
...
正在使用以下 Java 代码应用更改日志:
final Database dataBase = DatabaseFactory.getInstance()
.findCorrectDatabaseImplementation(new JdbcConnection(connection));
final Liquibase liquiBase = new liquibase.Liquibase(CHANGE_LOG_FILE, RESOURCE_ACCESSOR, dataBase);
liquiBase.update(CONTEXTS, LABEL_EXPRESSION);
错误:
Response: {"errorMessage":"Failed to connect to Liquibase due to Migration failed for change set db.changelog-1.1.xml::1231::xxx:\n Reason: liquibase.exception.DatabaseException: Table 'tenant' already exists [Failed SQL: CREATE TABLE xxx_global.tenant (tenantId INT AUTO_INCREMENT NOT NULL, region VARCHAR(255) NULL, tenantName VARCHAR(255) NULL, CONSTRAINT PK_TENANT PRIMARY KEY (tenantId))]"}
我唯一的其他想法是尝试在 CreateTable 变更集上使用自定义上下文进行全新安装
解决方案
我发现了这个问题,这不是 Liquibase 问题。包含调用 Liquibase 的 Lambda 代码的 AWS 堆栈未更新。我删除并重新创建了堆栈,它开始工作。
推荐阅读
- java - 将波斯语中的数值作为字符串类型更改为拉丁语
- javascript - 返回事件的承诺
- reactjs - 有或没有构造函数的反应初始化状态
- ios14 - 如何在 iOS14 上检测 5G(NR)?
- java - Kotlin:“公共”属性公开其“本地”类型参数
- react-native - 如何在反应原生中自定义反应导航底部选项卡?
- oauth - 使用 Github OAuth 时无需服务器的客户端身份验证
- pine-script - 在 TradingView pine v4 中做指标
- c# - Xamarin 示例项目缺少依赖项,但文件存在
- node.js - 使用 npm 为 nodejs 安装外部模块时无法读取未定义的属性“解析”