Backwards migration in mongodb

Hi,

To help me in tracking down a bug in rockat.chat.electron (Issue #1919). I need to roll back my test server from 3.10.4 to 3.7.1. Unfortunately when I do this the 3.7.1 server throws a database migration error. “Can’t find migration version 213”.

When look at the migrations table in the database there is only one entry and that is 213.

Has anyone got any ideas on how I get round this one?

Also, are the migration functions (forward/back) in the source tree somewhere. If so where?

Thanks,

Roger

hi @rogerjames99

unfortunately downgrade migrations is not possible with current model we use in rocket.chat.

that single record you found is to tell rocket.chat what was the last migration ran, so if the service going up doesn’t have the source code for that migration, the start up will halt as you have experienced.

you could just change that record to the last migration existing in the version you want to downgrade, which for version 3.7.1 is migration 206 (as you can see here Rocket.Chat/index.js at 3.7.1 · RocketChat/Rocket.Chat · GitHub)

BUT you have to bare in mind that all other migrations already ran (207-213) have changed the database in some way… so the data model on 3.7.1 might not be compatible with 3.7.1 anymore. doing this is not recommended unless you know what you are doing. I just wanted to make sure you understand the reasons and the risks.

Thanks Diego.

Good clear explanation.

I will give it a go. I want to make some foward progress on #1919.

Roger