Liquibase: Keep changes from script but remove the changelog in changelog table

931 Views Asked by At

I am using liquibase for applying database changes. I have below changeset and below are the entries in changelog:

Changeset:

<changeSet author="me" id="1">
   <addColumn tableName="order">
       <column name="isBlocked" type="boolean"> 
   </addColumn>
</changeSet>
<changeSet author="me" id="2">
    <addColumn tableName="order">
       <column name="shouldDecline" type="boolean"> 
   </addColumn>
</changeSet>

In DB :

Changelog table:

-------------------------
ID | AUTHOR | AND SO ON |
-------------------------
 1 | me     | AND SO ON |
 2 | me     | AND SO ON |
-------------------------

Order Table:

--------------------------------------------
ID | isBlocked | shouldDecline | AND SO ON |
--------------------------------------------
 1 | true      | false         | AND SO ON |
 2 | true      | false         | AND SO ON |
--------------------------------------------

Now I want to keep the changes in Order table, but I want to remove ID#2 from changelog table. So basically I want to keep the changes from the changeSet but I want to delete the entry in changeSet and maintain only ID#1 in change but Order table should have shouldDecline column. Anyway to achieve this?

from documentation there is rollback but it wil also revert the changes from the script which I dont want. Any suggestions on this?

2

There are 2 best solutions below

0
On

Feel free to remove unnecessary rows from databasechangelog table with a delete SQL statement using change id. As a result, the DDL stays applied to the database, but the log record of it is deleted. But you should know, that changelog it's a main feature of liquibase, and if you need to remove records from the changelog, maybe you don't need liquibase at all. Manually editing the changelog it's convenient for the dev and test environment, but it is strictly not recommended in production.

0
On

There is no way to remove a changeset from the databasechangelog table without removing the actual change from the database.

I would question why you want to do this.