-1

Our project have multiple modules. We created databasechangelog file for each module. Liquibase was execute these files by alphabetical order not module dependency order. For example

Project
 |
 Module1
 |
 | - domain
 |   | - foo1
 |  
 | - Changelogfile1.xml  
 Module2
 |
 | - domain
 |   | - foo2
 |   
 | - Changelogfil2.xml
 Module3
 |
 | - domain
 |   | - foo3
 | 
 | - Changelogfile3.xml

My master.xml file look like below

...
<includeAll path="classpath*:${path}/x.x.x"/>
...
  1. Changelogfile1.xml contain foo1 table creation changeset information and its constraints definition changeset
...
<changeSet author="****" id="1">
 <createTable tableName="foo1">
    <column name="id" type="BIGINT">
    ...
     <column name="foo2_id" type="INT">
     ...
  </createTable>
</changeSet>
....
<addForeignKeyConstraint baseColumnNames="foo2_id" baseTableName="foo1"
constraintName="name" deferrable="false" initiallyDeferred="false" 
referencedColumnNames="id" referencedTableName="foo2"/>
....
...
  1. Changelogfile2.xml contain foo2 table creation changeset information and its constraints definition changeset
...
<changeSet author="****" id="1">
 <createTable tableName="foo2">
    <column name="id" type="BIGINT">
     ...
     ...
     ...
  </createTable>
</changeSet>
  1. Changelogfile3.xml contain foo3 table creation changeset information and its constraints definition changeset
  2. Here Module1 is depends on Module2. Table foo1 have OnetoOne relationship with foo2 table

Liquibase was execute change log file by below order

  1. Changelogfile1
  2. Changelogfile2
  3. Changelogfile3

I will expect liquibase should execute below order

  1. Changelogfile2
  2. Changelogfile1
  3. Changelogfile3

Is there any options to liquibase will execute database changelog file by its dependency order?

Madasamy
  • 29
  • 2
  • 7

2 Answers2

0

No, Liquibase does not have the ability to determine the 'correct' ordering of changesets. It depends on the user putting them in the correct order.

There are several techniques for doing this. Many people just have a single changelog.xml that contains all of the changesets. Others will have a single master changelog file that includes other changelogs, and then they will use a file naming convention where the first 3 or 4 characters are a number, like 0001_add_customer_table.xml and then 0002_add_customer_table_constraints.xml. If using a convention like that, you may want to use 'skip numbering' where you start with 0010, then 0020, 0030, etc., so that in the (hopefully) rare case where you need to insert a changeset in between two other changesets, you will have room to add 0015, for example.

SteveDonie
  • 8,700
  • 3
  • 43
  • 43
0

it happens when includeAll is used, to avoid such issues,I added all the files separate include with the order I want, which solved the issue.

<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.2.xsd">

<include file="db/changelog/changes/version/db.changelog.test-v1.sql"/>
<include file="db/changelog/changes/version/db.changelog.test-v2.sql"/>
<include file="db/changelog/changes/version/db.changelog.test-v3.sql"/>
<include file="db/changelog/changes/version/db.changelog.test-v4.sql"/>
<include file="db/changelog/changes/version/db.changelog.test-v5.sql"/>
<include file="db/changelog/changes/version/db.changelog.test-v6.sql"/>
<include file="db/changelog/changes/version/db.changelog.test-v7.sql"/>
<include file="db/changelog/changes/version/db.changelog.test-v8.sql"/>
<include file="db/changelog/changes/version/db.changelog.test-v9.sql"/>
<include file="db/changelog/changes/version/db.changelog.test-v10.sql"/>
<include file="db/changelog/changes/version/db.changelog.test-v11.sql"/>
<include file="db/changelog/changes/version/db.changelog.test-v12.sql"/>
<include file="db/changelog/changes/version/db.changelog.test-v13.sql"/>
<include file="db/changelog/changes/version/db.changelog.test-v14.sql"/>
<include file="db/changelog/changes/version/db.changelog.test-v15.sql"/>
<include file="db/changelog/changes/version/db.changelog.test-v16.sql"/>
Thomson Ignesious
  • 689
  • 1
  • 8
  • 25