seppevs / migrate-mongo

A database migration tool for MongoDB in Node
MIT License
931 stars 166 forks source link

Mark all migrations as applied #291

Open sbnedkov opened 3 years ago

sbnedkov commented 3 years ago

Is your feature request related to a problem? Please describe.

Hello and thank you for a great tool.

In our code base we are using multiple MongoDB databases - one for each customer account, some sort of multi-tenancy. I followed the advice found in another issue and wrapped up all migrations in a script that will run migrate-mongo per database and that works well.

One case that we haven't covered is the creation of a new account database. If we treat it as any other database the next time we run an up command it will get all the history applied, but since this might contain non-idempotent migrations this approach has the potential to corrupt data.

Describe the solution you'd like

A solution might be to mark migrations as run without actually running them - do not change the application database, only the changelog collection.

From an user perspetive this might be a mark command/API function in the core project.

Describe alternatives you've considered

Of course we can have an external script insert documents directly in the changelog collection.