Applies to:
- Liquibase Secure (Pro)
Summary:
For MongoDB databases, changelogs need to be formatted in a specific way to deploy to the database. Therefore, the changelog can only be an XML file, and the changeset syntax can only be the change types from Liquibase. The complete workflow can be found in Using Liquibase with MongoDB.
Because the XML changelog needs to be structured, it is recommended to use multiple files to prevent a single file from becoming too long.
How to:
Create a main XML changelog file, using either the include or includeAll tag, and set it to another XML changelog file.
main_changelog.xml
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 http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd"
<includefile="create_collection.xml"></includefile="create_collection.xml">
Create another XML file that has the changesets inside of the XML changelog.
create_collection.xml
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 http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd"
{ validator:
{ $jsonSchema:
{ bsonType: "object", required: ["name", "address"], properties: { name: { bsonType: "string", description: "The Name" }, address: { bsonType: "string", description: "The Address" } }
}
}, validationAction: "warn", validationLevel: "strict" }
When you deploy main_changelog.xml to the targeted Mongo database, it will apply the collection changeset created to the database. As many files as needed can be included, but they all need to be wrapped in the XML headers for Liquibase.
Comments
0 comments
Article is closed for comments.