0

I have a question about performing downgrade together with Mongock. I got Java Spring application integrated with mongock and let's suppose that I upgraded my application from v1 to v2. During the upgrade migration script "001" was executed and data is migrated so I can see in "mongockChangeLog" collection new entry.

After one day client said that there is critical bug and want to downgrade application to v1. The problem is that client added some "devices" with new "type" (supported in v2) which is of course not supported in v1. Now, during the downgrade I want to delete entries with new "type" and I don't know how to do that. I see that mongock supports method with annotation "RollbackExecution" but as I understand from documentation it will be fired in different scenarios.

Do you have any ideas where I should put rollback logic that will delete all devices with new type?

Going further - during the downgrade - should I delete in this case entry from "mongockChangeLog" or there is better solution ?

Pat Ko
  • 149
  • 4
  • 17

1 Answers1

1

What you probably need here is to undo your changeLog, so whatever your changeLog did, just rever it.

You basically would run mongock in undo mode, telling up to what changeId is you want to go to.

As you can read in the documentation, RollbackExecution is used in two scenarios, for manual rollback(when transactions are not available) and in recovery operations, like undo.

Luckily we have that in place(plus other operations), which can be performed with the CLI. It's part of the professional suite, which is currently in beta and for free.

If you are interested you can send an email to here and we can provide access to it.

Sebu
  • 4,671
  • 5
  • 16
  • 29
Mongock team
  • 1,188
  • 5
  • 9
  • I could not find examples in the documentation from the undo. Could you provide some links where one can find examples as well? – Edu Aug 25 '22 at 09:34
  • Sure, please find a few useful links here: - Documentation: https://docs.mongock.io/v5/cli/operations/index.html#undo-up-to-change-pro --> with an example of how to use Undo with the CLI And some examples in the mongock repo: - https://github.com/mongock/mongock-examples/blob/master/mongodb/springboot-quickstart/src/main/java/io/mongock/examples/changeunits/ClientUpdaterChangeUnit.java - https://github.com/mongock/mongock-examples/blob/master/mongodb/springboot-quickstart/src/main/java/io/mongock/examples/changeunits/ClientInitializerChangeUnit.java – Mongock team Aug 27 '22 at 15:38