Rollback to previous changeset

the feature implemented to rollback to a different/previous changeset is working only if the referenced changeset and the changelog are present in the same folder level, is there a way that we can overcome this?

I need that rollback changeset and changelog to be present in a different folder. I use SQL formatted changelogs.

–rollback changeSetId:create-table-demo changeSetAuthor:atzawada changeSetPath:src/main/resources/testCreate.sql

@atzawada can you help me with this please, if you can?
my rollback changeset and changelog are in a different folder or a sub directory to the actual changeset where the rollback is referenced from.

I got it to work, whether the changsets were in the same file, or in different files.

Here’s my “different files” example:

db-changelog1.sql:

--liquibase formatted sql

--changeset BOB:create_functionv1 endDelimiter:/ runOnChange:true
    create or replace function test_func return date is
      v_dummy1 date;
    begin
      select sysdate into v_dummy1 from dual;
      return v_dummy1;
    end test_func;
    /  

--rollback drop function test_func;

db-changelog2.sql:

--liquibase formatted sql

--changeset BOB:create_functionv2 endDelimiter:/ runOnChange:true
    create or replace function test_func return date is
      v_dummy1 date;
    begin
      select sysdate-1 into v_dummy1 from dual;
      return v_dummy1;
    end test_func;
    /  

--rollback changeSetId:create_functionv1 changeSetAuthor:BOB changeSetPath:db-changelog1.sql

Both files are in the same folder.

Thank you @daryldoak , but I want it to be in a different folder not the same folder. Is that not possible?

I did not test that.

I’d try using a relative path to the current file.

Tried that, but it does not seem to be working. I will look if I can find a work around for it. Having rollback script in the same folder will make our repository messy.

I got it to work in different folders.

The file reference in changeSetPath is relative to the root directory.

I put the changelog2.sql into a folder, but left the changeSetPath the same, and it worked.

Thank you @daryldoak let me try try that

1 Like

Hey @daryldoak , I can’t seem to get it work. I tried all possible ways, It seems to work only when both changelogs are in the same folder level. Could you please show me how you did it?

db-changelog-master.xml:

  <include file="folder1/db-changelog1.sql"  relativeToChangelogFile="true"/>
  <include file="folder2/db-changelog2.sql"  relativeToChangelogFile="true"/>

folder1/db-changelog1.sql:

--liquibase formatted sql

--changeset BOB:create_functionv1 endDelimiter:/ runOnChange:true
    create or replace function test_func return date is
      v_dummy1 date;
    begin
      select sysdate into v_dummy1 from dual;
      return v_dummy1;
    end test_func;
    /  

--rollback drop function test_func;

folder2/db-changelog2.sql:

--liquibase formatted sql

--changeset BOB:create_functionv2 endDelimiter:/ runOnChange:true
    create or replace function test_func return date is
      v_dummy1 date;
    begin
      select sysdate-1 into v_dummy1 from dual;
      return v_dummy1;
    end test_func;
    /  

--rollback changeSetId:create_functionv1 changeSetAuthor:BOB changeSetPath:folder1/db-changelog1.sql

Thanks @daryldoak , I found what I was doing wrong:

This is how my master-changelog looked earlier:

  <include file="folder2/db-changelog2.sql"  relativeToChangelogFile="true"/>
  <include file="folder1/db-changelog1.sql"  relativeToChangelogFile="true"/>

The mistake I did was the file I was referring in the changSetPath was placed after the original changelog. which kept throwing the changeset not found error.

Changing my Changelog.xml to below, resolved the error:

  <include file="folder1/db-changelog1.sql"  relativeToChangelogFile="true"/>
 <include file="folder2/db-changelog2.sql"  relativeToChangelogFile="true"/>
1 Like