Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Liquibase: how to run always a changeset as the last update operation

Tags:

liquibase

I'm using Liquibase on my project and need always to execute a procedure after each Liquibase updates...

Currently, the changeSet looks like this:

<changeSet id="liquibase-0" author="liquibase" runAlways="true">
   <sqlFile relativeToChangelogFile="true" path="procedure/owner-changer.sql"/>
</changeSet>

How can I do ensure that this changeSet will be run as the last update operation?

Thks

like image 971
gudepier Avatar asked Feb 05 '15 15:02

gudepier


2 Answers

Since Liquibase 3.5.0 there's new runOrder attribute available with two possible values: first and last. Example for running changeSet as last one:

<changeSet id="123" author="author0" runAlways="true" runOrder="last">
    <sql> ... </sql>
</changeSet>

It isn't yet described in the documentation. Release notes: http://www.liquibase.org/2016/04/liquibase-3-5-0-released.html

like image 81
mav Avatar answered Oct 13 '22 09:10

mav


I would do this by splitting the changeset into two files: one that contains your "regular" changesets and the other only this single changeset. Then create a new "master" changeset that includes both, in the correct order:

<databaseChangeLog>

  <include file="standard_changes.xml" relativeToChangelogFile="true"/>
  <include file="change_owner.xml" relativeToChangelogFile="true"/>

</databaseChangeLog>

change_owner.xml only contains that single changeset you have shown in your question.

This does not guarantee that it's always run last, because you could still run both change set manually in a different order, but if you always run master.xml then you can be sure that the "change owner" is executed last.

Theoretically you could give the "master" changelog the same name as your current file. But as the filename is part of the "signature" of changeset, I wouldn't do that if you have already deployed changes through the existing file.

like image 39
a_horse_with_no_name Avatar answered Oct 13 '22 10:10

a_horse_with_no_name