I've tried using Mongock for DB migrations and it's a really good tool. It activates when main application is launched. Recently I found out that there is Mongock CLI, and it suits better for my aims. Unfortunately, I fail to make it work. I took my previous project as template, mvn clean package
it, jar file is successfully created in target
folder. I follow instructions in documentation, but get an error.
Maybe I launch it incorrectly or I'm missing some code. That's what I do in console:
cd D:\Programs\mongock-cli-5.0.26
(path to mongock cli) and
./mongock migrate all -aj D:\Java Projects\mongock\target\cinema.jar
(path to intellij idea project, which contains the jar)
It generates this file:
#!/bin/sh
#Generated cli script
java -jar mongock-cli-5.0.26.jar \
--cli-spring-jar lib/mongock-cli-springboot-5.0.26.jar \
--cli-core-jar lib/mongock-cli-core-5.0.26.jar \
--mongock-core-jar lib/mongock-runner-core-5.1.0.jar \
"$@" \
\
As I understand, I should copy it to console. I removed backslashes (it doesn't work if they stay), and that's the string I've got: java -jar mongock-cli-5.0.26.jar --cli-spring-jar lib/mongock-cli-springboot-5.0.26.jar --cli-core-jar lib/mongock-cli-core-5.0.26.jar --mongock-core-jar lib/mongock-runner-core-5.1.0.jar
and I added migrate all
to the end of this string.
I run it in console and get an error:
i.m.cli.wrapper.launcher.LauncherDefault : launching Mongock CLI runner with default launcher java.lang.NullPointerException: Cannot invoke "io.mongock.runner.core.builder.RunnerBuilder.buildRunner(io.mongock.runner.core.executor.operation.Operation)" because "this.builder" is null at io.mongock.cli.core.commands.migrate.MigrateCommand.all(MigrateCommand.java:38)
Do you have any ideas how to solve it? Should I include @Bean RunnerBuilder
? It was't specified in docs, so I guess my mistake is in something else.
I also tried to run a bash file with that generated code (I'm using Windows): bash script.sh
, but nothing happened. Cursor just moves to the next line and no changes applied in DB.