I would like to truncate all data from an application before it goes to production I was looking into the documentation and didn't find anything about truncating tables using liquibase. so I was wondering if anybody else solved something similar
To remove all data from an existing table, use the SQL TRUNCATE TABLE order. You can also use the DROP TABLE command to delete an entire table. But Truncate will remove the entire table structure from the database, and you will need to recreate the table if you want to store any data.
To remove all rows from a large table and leave the table structure, use TRUNCATE TABLE . It's faster than DELETE . To remove an entire table, including its structure and data, use DROP TABLE .
TRUNCATE TABLE removes all rows from a table, but the table structure and its columns, constraints, indexes, and so on remain. To remove the table definition in addition to its data, use the DROP TABLE statement.
You can use native SQL. It isn't liquibase constructs as such, and not DB agnostic, but I suspect truncate commands should be supported by any DB platform that liquibase supports. Of course, be careful of Foreign Key references when truncating any table, and make sure you truncate in the right order.
For example:
<changeSet author="eric.b" id="10288-201-5">
<comment>Clear any existing legacy data in the tables</comment>
<sql splitStatements="true">
TRUNCATE TABLE ADDRESS;
TRUNCATE TABLE PHONE;
TRUNCATE TABLE USERS;
</sql>
</changeSet>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With