我希望仅在表存在时才使用 Liquibase 在 MySQL 中删除表。
我无法弄清楚如何检查 Liquibase 中是否存在表。
我希望仅在表存在时才使用 Liquibase 在 MySQL 中删除表。
我无法弄清楚如何检查 Liquibase 中是否存在表。
你应该使用
<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
下面是使用 Liquibase 删除表的 Groovy 版本,使用preConditions
该表存在的 chack。
changeSet(author: "author", id: "some_id_value") {
preConditions(onFail: "MARK_RAN"){
tableExists(tableName: "table_name")
}
dropTable(tableName: "table_name")
}