9

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

2 Answers 2

11

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

Sign up to request clarification or add additional context in comments.

Comments

5

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.

2 Comments

it's a solution that I thought but, as you've said, there no guarantee that will be run last...
@gudepier That's the closest you can get to automate this. After all you can't prevent anyone from running the SQL script manually anyway. But using the include mechanism you can at least ensure that your standard deployment process does everything in the right order

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.