@Target(value=TYPE) @Retention(value=RUNTIME) public @interface ChangeUnit
The main difference is that classes annotated with @ChangeUnit can only have one changeSet method, annotated with @Execution and optionally another changeSet annotated with @BeforeExecution, which is run before the actual change is executed, this means, for example, that the method annotated with @BeforeExecution will be out of the native transaction linked to the changeLog, however, Mongock will try to revert the changes applied by the method @BeforeExecution by executing the method annotated with @RollbackBeforeExecution
The concept is basically the same, a class that wraps the logic of the migration
Classes annotated with @ChangeUnit must have the following: - One(and only one) one valid constructor annotated with @ChangeUnitConstructor(mandatory if more than one constructor exist after version 6) - One(and only one) method annotated with @Execution(mandatory) - One(and only one) method annotated with @RollbackExecution(mandatory) - At most, one method annotated with @BeforeExecution(optional) - If contains a method annotated with @BeforeExecution, one(and only one) method annotated with @RollbackBeforeExecution(mandatory if @BeforeExecution present)
Please follow one of the recommended approaches depending on your use case: - For existing changeLogs/changeSets created prior version 5: leave them untouched (use with the deprecated annotation)
- For new changeLogs/changeSets created from version 5: Annotated you class migration class with the annotation @ChangeUnit
| Modifier and Type | Required Element and Description |
|---|---|
String |
id
Change unit's id.
|
String |
order
Sequence that provide correct order for change unit execution.
|
| Modifier and Type | Optional Element and Description |
|---|---|
String |
author
Author of the changeset.
|
boolean |
failFast
If true, will make the entire migration to break if the change unit produce an exception or the validation doesn't
success.
|
boolean |
runAlways
Executes the change set on every Mongock's execution, even if it has been run before.
|
String |
systemVersion
Specifies the software systemVersion on which the change unit is to be applied.
|
boolean |
transactional
If true, Mongock will try to run the changeUnit in a native transaction, if possible.
|
public abstract String order
Equivalent to field `order` in ChangeSet annotation and ChangeLog, as now there is only one "changeSet", annotated with @Execution
ChangeSetpublic abstract boolean failFast
Equivalent to field `failFast` in ChangeSet annotation
ChangeSetpublic abstract boolean runAlways
Equivalent to field `runAlways` in ChangeSet annotation
ChangeSetCopyright © 2025. All rights reserved.