1

How does liquibase rollback works with springboot application? Would appreciate your inputs.

Here is what i tried - I am creating TableA and TableB in Oracle within a changeset.

TableB already exists in the database, I expect liquibase to rollback TableA as changeset fails while creating TableB but liquibase creating TableA and failing with the below error and never executes rollback block, which is strange:

Caused by: liquibase.exception.DatabaseException: ORA-00955: name is already used by an existing object

Liquibase Configuration:

<changeSet id="rollback" author="test_user">
<validCheckSum>any</validCheckSum>

    <sqlFile path="db/changelog/changes/DML/ddl.sql"/>
    <sqlFile path="db/changelog/changes/DML/ddl.sql"/>

    <rollback> drop table TABLEA;</rollback>
    <rollback> drop table TABLEB;</rollback>
</changeSet>

ddl.sql

CREATE TABLE TABLEA
    (
        TEST_COL       VARCHAR2(100)
    );

    dml.sql 

    CREATE TABLE TABLEB
    (
        TEST_COL       VARCHAR2(100)
    );
htshame
  • 6,599
  • 5
  • 36
  • 56
bigskull
  • 739
  • 2
  • 13
  • 23

1 Answers1

1

Looks like you have a wrong perception of what the rollback is for. It's not for "reverting one big transaction within a whole changeSet". It's for reinstating some past schema state.

According to Oracle documentation

Oracle Database issues an implicit COMMIT before and after any data definition language (DDL) statement.

So after every create table statement execution, Oracle commits the transaction.

If the error happens during the execution of a changeSet, liquibase can rollback only a failed transaction, which it does.

Check out this thread

Liquibase does not automatically roll back changes made during a deploy if there was an error. Rather, it can roll a database back to a previous schema state when you ask it to. In some cases, it can do that without you explicitly saying how to do the rollback.

It would be better to think of the rollback command in Liquibase as 'undo deploys' rather than a transactional rollback.

Also, check out this liquibase-rollback article on how to use rollbacks.

htshame
  • 6,599
  • 5
  • 36
  • 56