简体   繁体   中英

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

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM