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?
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.