I am simply trying to make some modifications to my postgres function. The liquibase logs report "Stored Procedure created", and show the changeSet id as expected, but when I check the database objects the function still has the old code.
I’ve tried dropping it in a sql block first, but this does not work. It complains that I have to first drop all the tables dependent on it. Also tried playing with the runOnChange/ runAlways flags to no avail.
log snippet
2023-10-12 16:34:10.808 INFO 29604 — [ main] liquibase.changelog : Stored procedure created
2023-10-12 16:34:10.811 INFO 29604 — [ main] liquibase.changelog : ChangeSet
db/changelog/service/triggers/TRIGGER_AUDIT.xml::AUDIT_TRIGGER_2::ran
successfully in 10ms
redacted code
<changeSet author="me" id="AUDIT_TRIGGER_1">
<createProcedure dbms="postgresql">
create or replace function audit_trigger() RETURNS trigger
language plpgsql
AS
$audit_trigger$
begin
// CODE
end;
$audit_trigger$
</createProcedure>
<changeSet author="me" id="AUDIT_TRIGGER_2">
<createProcedure dbms="postgresql">
create or replace function audit_trigger() RETURNS trigger
language plpgsql
AS
$audit_trigger$
begin
// NEW CODE
end;
$audit_trigger$
</createProcedure>
2
Answers
My changesets are just fine, it was my client (intellij) not refreshing the function contents which threw me. Tried with another client and I could see the changes had gotten applied.
You can create an SQL changelog for stored procedures and functions and include this in your main XML change log file. Please see the below for a sample procedure.
Please note splitStatements and runOnChange tags are important. rollback tag in the bottom you can either add empty or a valid rollback statement.
To include in the main file, use the below tag
It works for me all the time! Hope this helps.