Drop MySQL table using Liquibase
15,585
Solution 1
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
Solution 2
Below is the Groovy version of dropping the table with Liquibase using preConditions
chack that the table exists.
changeSet(author: "author", id: "some_id_value") {
preConditions(onFail: "MARK_RAN"){
tableExists(tableName: "table_name")
}
dropTable(tableName: "table_name")
}
Related videos on Youtube
Author by
Arpit
Updated on June 04, 2022Comments
-
Arpit almost 2 years
I am looking to drop a table in MySQL using Liquibase only if the table exists.
I am not able to figure out how to check if a table exists in Liquibase.
-
Stealth Rabbi over 4 yearsSo I'm doing a yaml equivilant to this (I think). It checks the precondition and fails, but still continues
-
Stealth Rabbi over 4 yearsI'm sorry, I had a typo. on-fail vs onFail. What you have is valid. Nonetheless, here is the changeset I used (asking a similar question): stackoverflow.com/a/57572634/680268