首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何让PreConditions在Java应用的变更日志中工作?

如何让PreConditions在Java应用的变更日志中工作?
EN

Stack Overflow用户
提问于 2020-07-14 00:16:35
回答 1查看 68关注 0票数 1

我尝试使用PreConditions跳过CreateTable变更集和MARK_RAN (如果表存在)。PreConditions似乎被忽略了,因为Liquibase在尝试在MYSQL ( AWS Aurora)中创建现有表时会记录一个表存在错误。

代码语言:javascript
复制
<?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代码应用changelogs:

代码语言:javascript
复制
            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);

错误:

代码语言:javascript
复制
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变更集上使用自定义上下文进行干净的安装

EN

回答 1

Stack Overflow用户

发布于 2020-07-14 07:27:19

我发现了这个问题,它不是Liquibase的问题。包含用于调用Liquibase的Lambda代码的AWS堆栈未更新。我删除并重新创建了堆栈,它开始工作了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62879964

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档