Mongock Standalone未执行更改日志。

huangapple go评论65阅读模式
英文:

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>

主类中的驱动程序代码:

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

更改日志类:

package co.my.test.persistence.changelog;

//imports

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

    @ChangeSet(order = "001", id = "test", author = "Igor Flakiewicz")
    public void test() {
        // 此方法永远不会被执行,sout不会发生,断点也不会被触及
        System.out.println("请工作!");
        // 迁移代码
    }

}
英文:

I have the following configuration in my project but for some reason the change-log is never executed.
Any ideas on what I'm missing?

I can successfully use the mongo client and perform CRUD actions, it's just the MongockStandalone that's not working.

pom.xml

&lt;dependency&gt;
    &lt;groupId&gt;com.github.cloudyrock.mongock&lt;/groupId&gt;
    &lt;artifactId&gt;mongock-standalone&lt;/artifactId&gt;
    &lt;version&gt;4.1.14&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;com.github.cloudyrock.mongock&lt;/groupId&gt;
    &lt;artifactId&gt;mongodb-v3-driver&lt;/artifactId&gt;
    &lt;version&gt;4.1.14&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;org.mongodb&lt;/groupId&gt;
    &lt;artifactId&gt;mongo-java-driver&lt;/artifactId&gt;
    &lt;version&gt;3.11.0&lt;/version&gt;
&lt;/dependency&gt;

Driver code in main class:

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

Changelog class:

package co.my.test.persistence.changelog;

//imports

@ChangeLog(order = &quot;001&quot;)
public class Changelog001 {

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

}

答案1

得分: 4

可能你正在按照Mongock文档中的快速入门指南操作。多亏了这个票,我们在文档中发现了一个错误。
在使用以下代码构建运行程序之后:

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();
英文:

Probably you're following the quick start in Mongock's documentation. Thanks to this ticket we have identified a bug in our documentation.
After building the runner with the following code:

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

You need to execute the method execute()

So the correct code you should be using is something like:

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

huangapple
  • 本文由 发表于 2020年8月28日 23:43:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/63636993.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定