seppevs / migrate-mongo

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

Add checksum for migration file #210

Open hyahyaoui opened 4 years ago

hyahyaoui commented 4 years ago

Hello i'm discovering the project and i figured out that checksum of migration file is not computed. I can update an already executed migration file without any problem. It would be nice if a checksum can be applied for the content of the file and it's name Thank you

seppevs commented 4 years ago

Hi. I'm trying to understand the added value of your feature request. So I have a few questions for you:

  1. Why are you updating a migration file?
  2. What should migrate-mongo do when it detects that the checksum is different?

Thank you for your feedback!

seppevs commented 4 years ago

Are you suggesting the same as #141?

MaikeMota commented 4 years ago

I can see two use case to this feature, one, is the described at the #141 , the other one is to prevent the edition of a previous migration file.

Maybe adding the options to decide what to do when an already applied migration checksum changes, the migrate-mongo have to rerun and update the checksum, ignore it, or halt the process.

So it can cover the two scenarios and is possible to set the 'ignore' option as default for those that already use the migrate-mongo and expect that to function as is today (simply ignoring file changes).

SailingYYC commented 4 years ago

I made comment to this here: https://github.com/seppevs/migrate-mongo/issues/225#issuecomment-673104002

Answers to @seppevs Q's:

  1. Existing migrations, once PR'd and installed in any persisted environment should not be edited again. Unfortunately, at times people don't always do the right things, find an error, make a quick fix to an existing migration, "it works on my machine". If this migration is already released, the change is not applied, the next developer creates a new migration based on the current state of the repo, "it works on my machine", but blows up in Prod.

  2. Other tools we use on SQL DB's, calc the SHA of each migration file and compare it with the SHA stored in a metadata table for the migrations, if there is a mismatch for any of the previously applied migrations, the migration is immediately halted. This effectively prevents any new migration from running, possibly corrupting data because of an inconsistent state.