Liquibase and its MongoDB extension conveniently packaged in a Docker image that works out of the box.
- Liquibase
- Liquibase official Docker image (without MongoDB extension)
- Liquibase MongoDB extension
First, build the Docker image
$ docker build . --tag "liquibase-mongo:4.29.1"
Then use it as follow.
$ docker run --rm -v \
"`pwd`/example/changelog:/liquibase/changelog" liquibase-mongo:4.29.1 \
--url="mongodb://host.docker.internal:27017/liquibase_test" --changeLogFile=changelog/changelog.xml --logLevel=info update
$ docker run --rm -v \
"`pwd`/example/changelog:/liquibase/changelog" liquibase-mongo:4.29.1 \
--url="mongodb://host.docker.internal:27017/liquibase_test" --logLevel=info tag tagName
$ docker run --rm -v \
"`pwd`/example/changelog:/liquibase/changelog" liquibase-mongo:4.29.1 \
--url="mongodb://host.docker.internal:27017/liquibase_test" --changeLogFile=changelog/changelog.xml --logLevel=info rollbackCount 1
$ docker run --rm -v \
"`pwd`/example/changelog:/liquibase/changelog" liquibase-mongo:4.29.1 \
--url="mongodb://host.docker.internal:27017/liquibase_test" --changeLogFile=changelog/changelog.xml --logLevel=info rollback tagName
Note: Because Liquibase runs inside the Docker container and I am testing it against a local
mongod
running outside docker, I am pointing to it by usinghost.docker.internal:27017
as the host.
- After running
update
You can use Compass to check that the namespaceliquibase_test.myCollection
exists, has an index onname
and some schema validation rules where thename
field is required. You can also use MongoDB for VS Code, connect to your local MongoDB Server and run the verify-update.mongodb playground. - After running
rollbackCount 1
You can use Compass to check that the namespaceliquibase_test.myCollection
exists, has an index onname
and some schema validation rules where thename
andaddress
fields are required. You can also use MongoDB for VS Code, connect to your local MongoDB Server and run the verify-rollback.mongodb playground.
You can run the same playground files from the new MongoDB Shell. For example, to verify the update:
$ mongosh ./example/playgrounds/verify-update.mongodb
- The
generateChangeLog
command is currently not supported for MongoDB. - The
db-doc
command should be supported but in fact it breaks