seppevs / migrate-mongo

A database migration tool for MongoDB in Node
MIT License
927 stars 163 forks source link

Automatic rollback support #287

Open Lolobstant opened 3 years ago

Lolobstant commented 3 years ago

Is your feature request related to a problem? Please describe. It would be great to have a way to run down operation automatically when a rollback occurs.

Describe the solution you'd like Maybe a way to bump a runtime version number in package.json when creating a migration file, and saving in the change log which runtime version the script was run? Then when a rollback occurs, all script with a runtime version over the current runtime are down.

It could actually be used to make up and down operations automatically with a simple run command for exemple, which would "just" have to run migration files under current runtime version and down migration files over it.

Describe alternatives you've considered

Additional context Add any other context or screenshots about the feature request here.

ftreguer commented 3 years ago

Hello, I don't know if it's exactly what you mean, but had a similar issue, so I've implemented the rollback of a group of migration scripts and proposed it in a pull request. The code is here: https://github.com/seppevs/migrate-mongo/pull/331 If you have any feedback, or improvements, we can discuss :)

YousefMMS commented 3 years ago

I would propose maybe something similar here. When the command migration run for instance do the necessary up's & dows's based on the available migrations applied in the db and in the codebase. This Is useful when the app required to do a rollback to an older state where a migration down should be executed. The migration run should figure out that there is an extra migration in the database and it should be rollbacked (down).