Liquibase® version 3.8.5 is now available! Get it for free.
2018 XML Announcement
News All Previous Posts >>

Subscribe for email updates

- and/or -

Include Tag

The include tag allows you to break up your change-logs into more manageable pieces. To easily include multiple files, use the includeAll tag.

<?xml version="1.0" encoding="UTF-8"?>

<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.8.xsd">
    <include file="com/example/news/news.changelog.xml"/>
    <include file="com/example/directory/directory.changelog.xml"/>
</databaseChangeLog>

As projects grow, the number of changeSets in a changeLog can grow unwieldy. To help ease this problem, and to make management of changes easier, databaseChangeLogs can be included to create a tree of change-logs. In the example above, the root change log includes first the changes in com/example/news/news.changelog.xml then the changes in com/example/directory/directory.changelog.xml.

Included change-logs are run in the order they are found so care does need to be taken to make sure that the included changelogs are either completely independent, or that any required changelogs are run first.

Any preconditions defined at the changelog level in sub changelog files will be evaluated before any changesets are ran.

The reason to use the <include> tag rather than using XML’s built-in include functionality is that with the built-in functionality the parser sees just one big XML document. Liquibase needs to uniquely identify each changeset with the id, the author, and the file name. By using the <include> and <includeAll> tags Liquibase makes it so you only have to ensure that the id/author combinations are unique within each file, not across all change logs.

Available Attributes

AttributeDescription
fileName of the file to import required
relativeToChangelogFileIs the file path relative to the changelog file containing the element rather than to the classpath. Defaults to "false" since 1.9
contextAppend context (using AND) to all contained changeSets since 3.5

Implementation Notes

Currently there is no checking for looping changelogs or double inclusion of changelogs.

If you include a changelog twice, you shouldn’t run into problems because the second time around, Liquibase will know that the changeSets have been run and won’t run them again (even if there is a runAlways tag).

If you create a changeLog loop (root.changelog.xml includes news.changelog.xml which includes root.changelog.xml) you will get an infinite loop. Checks for loops is a feature on our list of enhancements, but is currently not implemented.