mongock

Mongock - Removing outdated ChangeUnit after migration is done (runAlways = false)


I have a ChangeUnit for deleting one collection in my database. The migration has already been done and such change will no longer be required. I am wondering if I can delete the class and get rid of obsolete code.

I know change log will be saved in the db but I do not know if that would cause any complication (change log persisted in db, class removed from code). What do you think?

I tested this locally but still wanted to hear thoughts on this.


Solution

  • In general that is not a recommended practice. ChangeUnits should be inmutables.

    There are two potential problems that come to my mind that you should be aware of:

    1. Inconsistency across environments: This systems is designed to be reproduced in any environment from scratch, so you can reach the same state in any environment by applying exactly the same steps. If you remove one of the steps you take the risk of not reaching exactly the same final state.
    2. Undo operation: If you decide to execute the undo operation until that changeUnit, the system will probably undo all the changeUnits, as it won't be able to find the stopper changeUnit.

    As long as you have those potential issues under control, you should be fine, although, I want to emphasise that this is not a recommended practice