Rollback does not work

Hello! I want to have the ability to rollback to the previous version of database objects (for ex PostgreSQL function)
But it doesn’t work. Where is my mistake?

<?xml version="1.0" encoding="UTF-8"?>  
<databaseChangeLog  
  xmlns="http://www.liquibase.org/xml/ns/dbchangelog"  
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  xmlns:pro="http://www.liquibase.org/xml/ns/pro"  
  xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.2.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-4.2.xsd">  


<changeSet id="10" author="bob"> 
    <sql>
	create or replace function myfunc() returns void as 'begin raise info ''version_10''; return;end;' language plpgsql;
	</sql>  
</changeSet>


<changeSet id="11" author="bob">  
    <sql>
	create or replace function myfunc() returns void as 'begin raise info ''version_11''; return;end;' language plpgsql;
	</sql>  
    <rollback changeSetId="10" changeSetAuthor="bob"/> 
</changeSet>

</databaseChangeLog>

Hi @msoracle

What error do you get when you execute this changeset?

There is no error, but the rollback section is not executed.
rollback-count-sql 1 does not show SQL for previous version, only shows SQL for deleting from databasechangelog
and I see in the database version _11, not version_10 after liquibase rollback-count 1

I have the same scenario in my Liquibase test files. There are a couple of differences in mine though:

  1. Oracle, not postgres.
  2. I have “endDelimiter” set in each changeset.

My rollback scenario works as expected, rolling-back the stored procedure to prior version.

Create the test_proc stored procedure create or replace procedure test_proc is v_dummy1 date; v_dummy2 date; begin --This is select 1 select sysdate into v_dummy1 from dual; --This is select 2 select sysdate-1 into v_dummy2 from dual; end test_proc; / Create v2 of the test_proc stored procedure create or replace procedure test_proc is v_dummy1 date; v_dummy2 date; begin --This is select 1 select sysdate into v_dummy1 from dual; --This is select 2 select sysdate-1 into v_dummy2 from dual; --This is select 3 select sysdate-2 into v_dummy2 from dual; end test_proc; /

Great! You gave me an idea, I added splitStatements="false" and it worked as expected!
Thank you!

1 Like