Order of changelog execution

I have included multiple changelogs in a folder via the “includeAll”. In what order does liquibase execute the changelogs?

I need to have control on the order in which they are executed. Can somebody help on this?

Files are executed in alphabetical order.

You can use preconditions to indirectly order the execution of the changesets. You just have to execute the liquibase update multiple times until no open changesets are left. (in your cd pipeline you could do that with a simple loop)

for example:

--liquibase formatted sql
--changeset Test:1 stripComments:false
--preconditions onFail:CONTINUE onerror:CONTINUE onUpdateSql:FAIL
--precondition-sql-check expectedResult:1 SELECT COUNT(distinct [name]) FROM [sys].[objects] WHERE [name] = 'test_table'
CREATE OR ALTER VIEW dbo.vw_Test as 
          SELECT * FROM test_table

--changeset Test:2 stripComments:false 
CREATE TABLE test_table (
           id int primary key,
           c1 varchar(100)

If you run the liquibase update for the first time for this changelog, it will only execute the changeset, which creates the table. If you run it for the second time, it will create the view. This approach also works for multiple files.

Another option would be, to apply labels to every changeset. For example you could apply a schema label to every schema and a table label to every table. Then if you execute the update command you use the label-filter option to execute every schema changeset bevor every table changeset.


--changeset Test:2 stripComments:false label:table
CREATE TABLE liq.test_table (
           id int primary key,
           c1 varchar(100)

--changeset Test:2 stripComments:false label:schema

#create all the schema objects
liquibase update --label-filter schema
#create all the table objects
liquibase update --label-filter table