How can we use xinclude in Liquibase XML changlelog?

209 views Asked by At

I am trying to include another xml file which is a fragement of XML file into my changelog. Whenever I execute my changelog in liquibase it gets executed successfully (without any parsing error) but no table is created in the database.

I am not sure we can use xInclude in liquibsae, but I think it should be possible as we are using xml underneath in liquibase. Plus I coulndt find any example of xinclude in liquibase and in offical documentation.

Changelog.xml

<?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"
                       xmlns:xi="http://www.w3c.org/2001/Xinclude">

    <changeSet id="id-1234"
        author="umarTahir">

        <comment>creates table: employee</comment>
        <xi:include
            href="employee.xml" parse="xml"
         xpointer="title"/>

        <rollback>
            <dropTable schemaName="employee_test" tableName="employee" />
        </rollback>
    </changeSet>

</databaseChangeLog>

employee.xml

<createTable tableName="employee" xml:id="title">
    <column name="employee_id" type="UUID">
        <constraints primaryKey="true"
            primaryKeyName="employee_pkey" />
    </column>
    <column name="first_name" type="TEXT" />
    <column name="middle_name" type="TEXT" />
    <column name="last_name" type="TEXT" />
    <column name="email" type="TEXT" />
    <column name="n_created_by" type="TEXT" />
    <column name="n_created" type="TIMESTAMP WITHOUT TIME ZONE" />
    <column name="n_last_modified_by" type="TEXT" />
    <column name="n_last_modified"
        type="TIMESTAMP WITHOUT TIME ZONE" />
</createTable>
1

There are 1 answers

4
htshame On

Correct me if I'm wrong, but as far as I understand, liquibase parses changeLogs based on dbchangelog-{version}.xsd.

<xi:inlude> is being ignored. In fact, even if you type <xi:foo-bar> the changeLog still will be parsed successfully, but <xi:...> will be ignored.

So, I'd suggest to use <include> tag to include content from other changeLog files or use <sqlFile> to include sql files.