/mongration

MongoDB data migration tool for Spring Boot projects

Primary LanguageJavaApache License 2.0Apache-2.0

CircleCI Codacy Badge codecov Maven Central Licence

Mongration

MongoDB data migration tool for Spring Boot projects

Key features

  • Support Spring Boot lifecycle
  • Changelogs are regular spring beans
  • Support MongoDB transactions
  • Support ReactiveMongoTemplate

Getting started

Add a dependency

Maven

<dependency>
  <groupId>com.github.kuliginstepan</groupId>
  <artifactId>mongration</artifactId>
  <version>version</version>
</dependency>

Gradle

compile("com.github.kuliginstepan:mongration:version")

or

implementation 'com.github.kuliginstepan:mongration:version'

Configuration properties

  • mongration.enabled – enable or disable mongration. Default to true
  • mongration.changelogs-collection – collection for saving changesets. Defaults to mongration_changelogs
  • mongration.mode – mode for executing changesets. Defaults to AUTO, means that mongration will try to analyze changesets to choose proper mode. Possible modes are IMPERATIVE, REACTIVE

Changelog

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.

Changeset

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.

Indexes

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.

Spring Boot Actuator

Mongration provides actuator endpoint mongration, which lists all executed changesets.

Migration from old versions

  • drop changelog table
  • remove all executed changesets