【问题标题】:How to use Liquibase-MongoDb-Spring-boot如何使用 Liquibase-MongoDb-Spring-boot
【发布时间】:2020-09-29 14:50:32
【问题描述】:

我检查并发现 liquibase 已针对 Mongo DB 进行了扩展,但我看不到任何将其与 spring-boot 一起使用的示例,任何人都可以建议将 liquibase 与 spring-boot 一起用于 mongodb 的方法。 任何示例都会有所帮助。

【问题讨论】:

标签: mongodb spring-boot liquibase


【解决方案1】:

除了这个 github 存储库:https://github.com/liquibase/liquibase-mongodb,我找不到任何关于 Liquibase 对 MongoDB 的支持的文档。

有一个 - mongock.io,它类似于 Liquibase 的工作方式,并且可以轻松地与 Spring boot 集成。下面是github地址: https://github.com/cloudyrock/mongock

【讨论】:

    【解决方案2】:

    Liquibase doesn't support MongoDB,但是they provide an extension to support MongoDB.你可以看到更多细节here。
    有一些先决条件:-

    请注意,这种方式的语法与我们通常用于其他数据库(如 Postgres 或 SqlServer 数据库)的语法不同。

    <?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 http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.0.xsd
          http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
    
    <changeSet id="1" author="bob">
        <ext:createCollection collectionName="myCollection">
            <ext:options>
            {
            validator: {
                $jsonSchema: {
                    bsonType: "object",
                    required: ["name", "address"],
                    properties: {
                        name: {
                        bsonType: "string",
                        description: "The Name"
                        },
                address: {
                    bsonType: "string",
                    description: "The Address"
                            }
                        }
                    }
                },
                validationAction: "warn",
                validationLevel: "strict"
                }
                </ext:options>
            </ext:createCollection>
        </changeSet>
    </databaseChangeLog>

    【讨论】:

      【解决方案3】:

      建议大家使用mongock等NoSQL支持的数据迁移库。它大部分时间都像 liquibase 一样提供数据迁移。 mongock 提供迁移类而不是 liquibase XML 或 JSON。

      【讨论】:

        猜你喜欢
        • 2018-01-20
        • 1970-01-01
        • 2022-01-26
        • 1970-01-01
        • 2018-11-29
        • 2022-01-12
        • 2018-07-25
        • 2020-11-12
        • 1970-01-01
        相关资源
        最近更新 更多