include tag in the master changelog to reference other changelogs.
In Liquibase, you can break up your master changelog into more manageable pieces by creating multiple changelogs to separate your changesets in a way that makes sense for you. For example, you can separate changesets into their own files, according to features, releases, or other logical boundaries. Breaking up your changelogs can make it easier to find and manage complex database schema scripts.
The reason why you would use the
include tag rather than using XML's built-in include functionality is that the parser sees just one large XML document. Liquibase needs to uniquely identify each changeset with an id, author, and file name.
How to use the
Create a master changelog file, if you do not have one already.
The master changelog file works as a configuration file that will hold all the references to all your other changelogs. Your master changelog file must be in an XML, YAML, or JSON format.
Note: At this time, the
<include> tag cannot be used in an SQL formatted master changelog.
<include>tag and file references to your master changelog.
In this example, we are using an XML master changelog with the
<include> tag referencing two SQL changelogs:
Note: Your reference changelog can be SQL, XML, YAML, or JSON file types.
<?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" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd"><include file="com/example/news/news.changelog.sql"/> <include file="com/example/directory/directory.changelog.sql"/> </databaseChangeLog>
include tag runs in a changelog
Liquibase runs all included changelogs in the order they are found. Make sure that the included changelogs are completely independent or that any required changelogs are run first.
In the master changelog example above, the root changelog includes first the changes in
com/example/news/news.changelog.sql and then the changes in
You should define Preconditions in your reference changelogs. Liquibase will evaluate them before running any changesets.
About double inclusion of changelogs
Liquibase does not check for the double inclusion of changelogs in your master file. However, if you include a changelog twice, Liquibase recognizes that the changesets have already been run and will not run them again, even if you use a
About infinite loops in changelogs
Liquibase does not check for looping changelogs in your master file. However, if you create a changelog loop like the following, you will get an infinite loop which will prevent the operation from completing:
news.changelog.xml which includes
Make sure to avoid infinite loops when referencing changelogs. If you create an infinite loop, Liquibase will display the following error, and will continue to loop until the process runs out of memory:
Unexpected error running Liquibase: Unknown reason
||Name of the file you want to import required.||Required|
||File path relative to the changelog file containing the element rather than to the classpath. Default: false||Optional|
Appends a context (using an
Note: Contexts only work with the
Appends a label to all contained changesets.
Note: Labels only work with the