7

我希望仅在表存在时才使用 Liquibase 在 MySQL 中删除表。

我无法弄清楚如何检查 Liquibase 中是否存在表。

4

2 回答 2

15

你应该使用

<changeSet author="liquibase-docs" id="dropTable-example">
    <preConditions onFail="MARK_RAN"><tableExists schemaName="schemaName" tableName="tableName"/></preConditions>
    <dropTable cascadeConstraints="true"
            catalogName="cat"
            schemaName="public"
            tableName="person"/>
</changeSet>

此外,您可以查看此链接以获取更多<preConditions>选项: http ://www.liquibase.org/documentation/preconditions.html

于 2017-05-23T20:06:49.000 回答
1

下面是使用 Liquibase 删除表的 Groovy 版本,使用preConditions该表存在的 chack。

changeSet(author: "author", id: "some_id_value") {
    preConditions(onFail: "MARK_RAN"){
        tableExists(tableName: "table_name")
    }

    dropTable(tableName: "table_name")
}
于 2020-09-02T12:40:15.550 回答