Where is I should define scheme validation rules using mongock as migration tool?
In official library examples it's placed in the @BeforeExecution
section. Why?
Asked
Active
Viewed 103 times
1 Answers
1
From the official documentation:
@Execution
: The main migration method(Mandatory).@BeforeExecution
: Optional method that will be executed before the actual migration, meaning this that it won't be part of the transactional and executed in non-transactional context. It's useful to perform DDL operations in database where they are not allowed inside a transaction, like MongoDB, or as preparation for the actual migration.
So you should include your DDL changes in @BeforeExecution
method.
For more details about ChangeUnit
please check the documentation at this link.

Mongock team
- 1,188
- 5
- 9
-
I always thought that migrations change DDL in the first place, because this approach looks strange for me. – Hett Nov 08 '22 at 05:25
-
1In general, @BeforeExecution is used for anything that won't be part of the transaction(for MongoDB DDL changes can't be part of the transaction), other DB engines, like postgres, allow DDL operations inside the transactions. – Mongock team Nov 08 '22 at 06:34