0

I have quite large legacy multi module Java Spring boot project which connects to one MySql database and two Mongo databases (lets say codebook and report).
I'm trying to setup Mongock to be able to do Mongo database migrations. I need it on only one Mongodb database (report).
I added Mongock dependencies and configuration class (MongockApplicationRunner, MongoTransactionManager) to report database.
When I run the application it gives me exception: Scan package for changeLogs is not set: use appropriate setter (exception from RunnerBuilderBase class).

I debugged it and found that Mongock is trying to set configuration for codebook database.
I created another Mongock configuration, this time for codebook database. Run the application. Mongock loads my new configuration for codebook, but then tries to set another configuration for codebook database which failes because of config.getChangeLogsScanPackage().isEmpty().

It seems that Mongock is always setting some default configuration on codebook database.
When I debug it Mongock loads first codebook configuration from my mongockApplicationRunner (line .buildApplicationRunner();). The second codebook configuration comes from MongockContextBase.applicationRunner and that configuration has empty MongockSpringConfiguration.migrationScanPackage.

Why is this default configuration appearing and how to stop it from loading?
My Spring boot is 2.2.13.RELEASE and Mongock is 5.0.24.

salerokada
  • 334
  • 3
  • 7
  • What are you trying to do with the "/" in @Qualifier(value = "reportMongoTemplate"/"codeBookMongoTemplate")? – Mongock team Aug 03 '22 at 12:50
  • That is just an example how would other qualifier look like. First would be named "reportMongock", second "codeBookMongock". Same for parameters: MongoTemplate for first mongockApplicationRunner runner would have qualifier "reportMongoTemplate" and for second runner MongoTemplate would be "codeBookMongoTemplate". – salerokada Aug 03 '22 at 12:56

2 Answers2

1

After a lot of wasted time I found that besides Mongock configuration on report database I was also doing autoconfiguration (@EnableMongock).
I had annotation @EnableMongock on my MongockConfig class. Since codebook mongo template had @Primary annotation autocofiguration was loading that database and there were no properties to set changelog directory inside application.properties so ChangeLogsScanPackages were empty.
Simple solution, I just removed @EnableMongock annotation and it started working.

Don't mix autoconfiguration (@EnableMongock) with creating mongockApplicationRunner and transactionManager or you will end up with problem like me.

salerokada
  • 334
  • 3
  • 7
  • 1
    We were trying to reproduce without success. Our mistake was that we assumed you weren't annotating your app with `@EnableMongock`. This annotation is to delegate the work of building the Mongock runner to Mongock itself. As you were doing that job, that annotation was only not needed, was actually conflicting – Mongock team Aug 07 '22 at 10:37
  • Thanks for support @MongockTeam. Yeah, you have to start from assumption that people (me) won't do the most obvious things. :( – salerokada Aug 08 '22 at 11:33
0

When using @EnableMongock within your spring boot application, you must define the configuration to let Mongock scan the migrations as below:

mongock:
  migration-scan-package:
    - com.ma.project.migrations

In case you want to keep the Mongock without running migrations, you can configure it to be disabled as below:

mongock:
  enabled: off
Yassine CHABLI
  • 3,459
  • 2
  • 23
  • 43