Applies to:
- Liquibase Pro
Summary:
For Mongo databases, changelogs need to be formatted in a specific way to deploy to the Mongo database. Therefore, the changelog can only be an XML file, and the changesets syntax only can be the change types from Liquibase. The complete workflow can be found on Using Liquibase with MongoDB.
Because of how the XML changelog needs to be structured, it is recommended to use multiple files to prevent a single XML file from getting too long.
How to:
Create a main XML changelog file and use 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 created collection changeset to the database. There can be as many files as needed, but they all need to be wrapped in the XML headers for Liquibase.
Comments
0 comments
Article is closed for comments.