[英]Drop MySQL table using Liquibase
I am looking to drop a table in MySQL using Liquibase only if the table exists.我希望仅在表存在时才使用 Liquibase 在 MySQL 中删除表。
I am not able to figure out how to check if a table exists in Liquibase.我无法弄清楚如何检查 Liquibase 中是否存在表。
You should use你应该使用
<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>
Also, you can check this link for more <preConditions>
options: http://www.liquibase.org/documentation/preconditions.html此外,您可以查看此链接以获取更多
<preConditions>
选项: http : //www.liquibase.org/documentation/preconditions.html
Below is the Groovy version of dropping the table with Liquibase using preConditions
chack that the table exists.下面是使用表存在的
preConditions
chack 使用preConditions
删除表的 Groovy 版本。
changeSet(author: "author", id: "some_id_value") {
preConditions(onFail: "MARK_RAN"){
tableExists(tableName: "table_name")
}
dropTable(tableName: "table_name")
}
Here is a YAML snippet for dropping a table if exists这是一个 YAML 片段,用于删除表(如果存在)
- changeSet:
id: drop-my-table-if-exists
author: the-author
comment: drop my_table if exists
preConditions:
- onFail: MARK_RAN
- tableExists:
tableName: my_table
changes:
- dropTable:
tableName: my_table
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.