Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Liquibase Rollback Spring boot

I have a microservice built using spring boot. I integrated the Liquibase and it execute all changeSets except rollbacks. Below is the sample liquibase xml file.

<changeSet id="6" author="Kasun">
        <insert tableName="user">
            <column name="firstNale" value="Kasun" ></column>
            <column name="lastName" value="Ranasinghe" ></column>
        </insert>
    </changeSet>
    <changeSet id="7" author="Kasun">
        <rollback changeSetAuthor="Kasun"  >
            <createTable tableName="user" />
        </rollback>
    </changeSet>

When I run the spring boot app it doesn’t execute the rollback. But in the database changes is updated as executed.

like image 426
Keaz Avatar asked Apr 03 '18 15:04

Keaz


People also ask

How do I roll back Liquibase in spring boot?

To roll back any changes, create the liquibase. rollback-file file in Spring Boot and generate a rollback script for changes associated with changesets: -- rollback drop table test_table; Note: You can also use tags for the rollback.

Does Liquibase support rollback?

Liquibase provides commands to allow you to undo changes you have made to your database, either automatically or with a custom rollback command. The intention of a rollback script is to return the database to a previous specified point in time. Note: Rollback support is available in command line, Ant, and Maven.

How does Liquibase work with spring boot?

Extract it and open in your IDE. Note: Liquibase supports a variety of commands. For now, Spring Boot integrates the update , future-rollback-sql , drop-all , update-testing-rollback , and clear-checksums commands. Spring Boot offers a subset of the Liquibase configuration options.


1 Answers

In your example changeSet id="7" has no actual change. it's just a rollback statement which is logically incorrect as no table is being dropped as part of the changeset. You can refer to Rolling Back ChangeSets docs on how to write rollbacks.

Rollbacks are supposed to be executed when you migrate the schema to lower version e.g. after downgrading the Spring Boot application version. This is not something which is done out of the box by Spring Boot which only applies the missing changesets using the regular Liquibase update operation.

There is a liquibase.rollback-file property in Spring Boot which can be used to write a rollback SQL script. You'd have to run this SQL by hand when you are rolling back the schema. You can try Maven Liquibase Plugin to automate it.

like image 175
Karol Dowbecki Avatar answered Sep 28 '22 02:09

Karol Dowbecki