Mongock Standalone 不执行变更日志

Mongock Standalone not executing changelogs

我的项目中有以下配置,但由于某种原因从未执行更改日志。
关于我遗漏的任何想法?

我可以成功使用 mongo 客户端并执行 CRUD 操作,只是 MongockStandalone 不工作。

pom.xml

<dependency>
    <groupId>com.github.cloudyrock.mongock</groupId>
    <artifactId>mongock-standalone</artifactId>
    <version>4.1.14</version>
</dependency>
<dependency>
    <groupId>com.github.cloudyrock.mongock</groupId>
    <artifactId>mongodb-v3-driver</artifactId>
    <version>4.1.14</version>
</dependency>
<dependency>
    <groupId>org.mongodb</groupId>
    <artifactId>mongo-java-driver</artifactId>
    <version>3.11.0</version>
</dependency>

主程序中的驱动程序代码 class:

MongockStandalone.builder()
                 .setDriver(MongoCore3Driver.withDefaultLock(mongoClient, "demo"))
                 .addChangeLogsScanPackage("co.my.test.persistence.changelog")
                 .buildRunner();

变更日志class:

package co.my.test.persistence.changelog;

//imports

@ChangeLog(order = "001")
public class Changelog001 {

    @ChangeSet(order = "001", id = "test", author = "Igor Flakiewicz")
    public void test() {
        // this method is never executed, the sout doesn't occur and breakpoints are not reached
        System.out.println("PLEASE WORK!");
        // migration code
    }

}

您可能正在关注 quick start in Mongock's documentation。感谢这张票,我们在我们的文档中发现了一个错误。 使用以下代码构建运行器后:

MongockStandalone.builder()
             .setDriver(MongoCore3Driver.withDefaultLock(mongoClient, "demo"))
             .addChangeLogsScanPackage("co.my.test.persistence.changelog")
             .buildRunner();

您需要执行方法execute()

因此您应该使用的正确代码如下:

MongockStandalone.builder()
             .setDriver(MongoCore3Driver.withDefaultLock(mongoClient, "demo"))
             .addChangeLogsScanPackage("co.my.test.persistence.changelog")
             .buildRunner()
             .execute();