Context
I was troubleshooting the error that occurred when applying changeset to my development database on Microsoft SQL Server (MSSQL).
Initial Error
liquibase.exception.LiquibaseException: Unexpected error running Liquibase: Cannot find parser that supports testDBChangelog.xsd
Tech Stack
- Miccrosoft SQL Server 2019 Developer Edition
- Liquibase v4.12.0
- Windows
XML Changeset file
I use the following database changelog XML definition file (named testDBChangelog.xsd), where I included my SQL script through the includeFile
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"
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-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-4.6.xsd
http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.6.xsd">
<includeFile file="script/test-changelog.sql">
</databaseChangeLog>
Resolution
Overall, I discovered some unaccesible links as well as other interesting errors. Let's walk through the process!
Invalid file extension
I initially named my database changelog with XML Schema Definition (XSD) file extension. This might just be how Liquibase works on Windows or the underlying mechanism only supports XML file extension. I simply rename the file extension from XSD to XML. With that, Liquibase can proceed with the initial validation through liquibase validate
.
Unaccessible links
I only discovered this as I was curious what the URLs entail. I discovered that the some links within the databaseChangeLog
tag face a 403 Forbidden Error
from Nginx. This may mean that the administrator of the server has restricted directory traversal since I could still download the individual XML and XSD files.
To that end, I removed the following URLs from the xsi:schemaLocation
tag
Clean up
I decided to remove the xmlns:pro
as I am not using Liquibase Pro license. My final XML Changeset file is:
<?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"
xsi:schemaLocation="
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd
http://www.liquibase.org/xml/ns/pro/liquibase-pro-4.6.xsd
http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.6.xsd">
<includeFile file="script/test-changelog.sql">
</databaseChangeLog>
Additional notes
- Note that the
xsi:schemaLocation
must have even number of URI's. If not, Liquibase would throw the following errorCaused by: org.xml.sax.SAXParseException; lineNumber: 8; columnNumber: 68; SchemaLocation: schemaLocation value = 'http://www.liquibase.org/xml/ns/dbchangelog-ext%20http://www.liquibase.org/xml/ns/dbchangelog%20http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.11.xsd' must have even number of URI's.
- The
xmlns
is XML namespace. The namespace unqiuely quatifies the element names in order to differentiate and avoid conflicts between elements with the same name on the Web.- This may be why Liquibase does not seem to throw error while retaining it in th changelog definition file.
- Your mileage may vary depending on the type of database your are using.
That's all, folks. Hope this spare you from some headaches, cheers!