# Order of changelog execution

**URL:** <https://forum.liquibase.org/t/order-of-changelog-execution/7960>\
**Category:** General Discussion\
**Created:** [March 23, 2023, 6:32am UTC](https://forum.liquibase.org/t/order-of-changelog-execution/7960 "2023-03-23T06:32:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vishalg8454](https://avatars.discourse-cdn.com/v4/letter/v/b9bd4f/32.png) [@vishalg8454](https://forum.liquibase.org/u/vishalg8454)\
**Post date:** [March 23, 2023, 6:32am UTC](https://forum.liquibase.org/t/order-of-changelog-execution/7960/1 "2023-03-23T06:32:47Z")

</div>

Hi,  
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?

---

<div class="post-metadata">

**Author:** ![daryldoak](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.liquibase.org/daryldoak/32/764_2.png) [@daryldoak](https://forum.liquibase.org/u/daryldoak)\
**Post date:** [March 23, 2023, 1:22pm UTC](https://forum.liquibase.org/t/order-of-changelog-execution/7960/2 "2023-03-23T13:22:39Z")

</div>

Files are executed in alphabetical order.

> **[includeAll](https://docs.liquibase.com/change-types/includeall.html?Highlight=includeAll)**
>
> The includeAll tag allows you to specify a directory that contains multiple changelog files. It is used within your root changelog file to call on the directory and include all XML files as changelog files, and all SQL files as individual changes.

---

<div class="post-metadata">

**Author:** ![AlexGruebel](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@AlexGruebel](https://forum.liquibase.org/u/AlexGruebel)\
**Post date:** [March 24, 2023, 3:04pm UTC](https://forum.liquibase.org/t/order-of-changelog-execution/7960/3 "2023-03-24T15:04:28Z")

</div>

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:

```auto
--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.

example:

```auto
--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 SCHEMA liq

```

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

```

---

<div class="post-metadata">

**Author:** ![Helene](https://avatars.discourse-cdn.com/v4/letter/h/7993a0/32.png) [@Helene](https://forum.liquibase.org/u/Helene)\
**Post date:** [December 21, 2023, 8:32am UTC](https://forum.liquibase.org/t/order-of-changelog-execution/7960/4 "2023-12-21T08:32:54Z")

</div>

We have chosen to use a naming convention for the different changelog files to ensure they are executed in the correct order. We simply prefix the filename with 01, 02 etc. This has worked just fine for us.
