4
votes

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.

1
When reporting an issue, always include three things: 1. This is what I did. 2. This is what I expected to happen. 3. This is what actually happened. I am unclear on all three of these points in this question. I think you may be confused on what rollbacks are for - they are typically added as a 'sub-change' of a changeset to indicate how to "undo" the change. Having a rollback that creates a table seems very strange. A better example is that you might have a changeset that creates a table, and then a rollback in that changeset that drops the table.SteveDonie
Thanks I’ll update the question.Keaz
I might be going on a limb here but isnt create table a DDL which cannot be rolled back? did you try any other statement in the rollback clause other than the create tableAnas

1 Answers

5
votes

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.