MongoDB data migration tool for Spring Boot projects
- Support Spring Boot lifecycle
- Changelogs are regular spring beans
- Support MongoDB transactions
- Support ReactiveMongoTemplate
<dependency>
<groupId>com.github.kuliginstepan</groupId>
<artifactId>mongration</artifactId>
<version>version</version>
</dependency>compile("com.github.kuliginstepan:mongration:version")or
implementation 'com.github.kuliginstepan:mongration:version'mongration.enabled– enable or disable mongration. Default totruemongration.changelogs-collection– collection for saving changesets. Defaults tomongration_changelogsmongration.mode– mode for executing changesets. Defaults toAUTO, means that mongration will try to analyze changesets to choose proper mode. Possible modes areIMPERATIVE,REACTIVE
To mark class as a changelog you need to annotate it with @Changelog. This annotation makes class regular spring bean.
@Changelog has property id, which is a simple class name by default.
To mark method as a changeset you need to annotate it with @Changeset. By default changeset's id is a method name.
Changelog collection has compound unique index @CompoundIndex(def = "{'changeset': 1, 'changelog': 1}", unique = true)
to check if changeset executed or not.
You can inject all beans available in bean factory as a changeset's method arguments.
Imperative changeset method must have void return type and reactive changeset method must returns Mono<Void>.
If you configured MongoDB and Spring to enable transaction support, changesets may be executed in transactions.
Spring Mongo Data 2.2 provides a way to disable automation indexes creation. It's recommended to set spring.data.mongodb.auto-index-creation to false. Mongration creates indexes for all persistent entities after execution changesets.
Mongration provides actuator endpoint mongration, which lists all executed changesets.
- drop changelog table
- remove all executed changesets