Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add section to cover use of ChangeUnitConstructor #38

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion site/v5/get-started/get-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ public class ClientInitializerChange {

private final MongoTemplate mongoTemplate;
private final ThirPartyService thirdPartyService;

/** This is the constructor to which mongock will inject dependencies **/
@ChangeUnitConstructor
public ClientInitializerChange(MongoTemplate mongoTemplate,
ThirPartyService thirdPartyService) {
this.mongoTemplate = mongoTemplate;
Expand Down Expand Up @@ -146,4 +149,4 @@ APPLIED - ChangeEntry{"id"="client-initializer", "author"="mongock", "class"="Cl

## Examples

For code examples, visit the [resource page](/v5/resources)
For code examples, visit the [resource page](/v5/resources)
14 changes: 14 additions & 0 deletions site/v5/migration/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ A migration is constituted by an ordered list of ChangeUnits. Each of the Change
- On the other hand, in non-transactional environments, Mongock will try to provide an artificial transactional atmosphere by rolling back the failed change manually.
2. In targeted operations, such as `undo`, `upgrade`, etc., the ChangeUnit is the unit of the operation. For example, when performing an `undo` operation, it needs to specify the _ChangeUnitId_ until which all the ChangeUnits are reverted(inclusive).
3. A ChangeUnit has only one migration method, which is marked with the **@Execution** annotation, and a rollback method, annotated with **@RollbackExecution**.
------------------------------------------------------

## ChangeUnit Constructor


Every class marked as `@ChangeUnit` will be marked as a migration class and Mongock will inject dependencies to one of
the valid constructor as followed:

- In a class with more than one valid constructor, It would be recommended with warning to have exactly one of the constructor to be marked with **@ChangeUnitConstructor**.
- If such class doesn't have any constructor with **ChangeUnitConstructor**, Mongock will choose the first for dependency injection, this will become error in version 6.
- A class with only one valid constructor can choose to skip annotating the constructor, but if possible to do so, would be recommended for clarity of code.


------------------------------------------------------

Expand Down Expand Up @@ -81,6 +93,8 @@ public class MyMigrationChangeUnit {

private final MongoTemplate template;

// Note this annotation is Optional here as only one valid constructor exist
@ChangeUnitConstructor
public MyMigrationChangeUnit(MongoTemplate template) {
this.template = template;
}
Expand Down