Drop MySQL table using Liquibase

Arpit picture Arpit · May 20, 2017 · Viewed 12.1k times · Source

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.

Answer

Lemmy picture Lemmy · May 23, 2017

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