SRoddis/Mongo.Migration

Downward migration always starts at the latest version instead of at the document's current version

Closed this issue · 2 comments

Assume that we have multiple schema versions:

  • 0.0.1
    • First version
  • 0.0.2
    • Arbitrary changes
  • 0.0.3
    • Added new property
  • 0.0.4
    • Removed new property

Also assume that we're doing on the fly migrations, so our db contains documents that could be on any one of these schema versions.

For reasons, I want to migrate everything back to version 0.0.2. If the document is on 0.0.4, then this works as expected. If the document is on 0.0.3, then we still try to migrate down from 0.0.4 instead of starting the downward migration at 0.0.3.
The current behavior is problematic in this scenario because when going from 0.0.4 -> 0.0.3, I'll add a property back to a document that already has it which throws an exception.

My proposed solution is to adjust the MigrateDown method in DocumentMigrationRunner to start the downward migration from the document's current version.

Is that still open? I had a simular issue. I'm only using DatabaseMigrations, no document migrations, but I've ran into the same issue, and fixed it with this PR

We've moved away from using Mongo.Migration, but a quick look at your PR seems like it should resolve my reported issue, so I think it's safe to close this.