Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR introduces an automatic rollback feature that when enabled, migrate-mongo tracks all write operations during migration up execution and stores inverse operations that can undo the changes, allowing the migration down to be done with minimal coding.
This feature is not intended to completely replace manual migration down scripts. Instead, it serves as a productivity tool that enables developers to:
When to use auto-rollback:
When to write manual down() scripts:
Auto-rollback is designed to complement your workflow, not replace careful migration planning.
How it works?
When auto rollback feature is enabled:
During Migration Execution: Each collection operation is intercepted and wrapped to:
autoRollbackCollectionNamecollection with ordering metadataOn Migration Down: during
migration.down()if script callsawait db.autoRollback();:Operation Mapping:
insertOne→deleteOne(using inserted ID)insertMany→deleteMany(using inserted IDs)updateOne/updateMany→replaceOne(restoring complete original document)replaceOne→replaceOne(restoring complete original document)deleteOne/deleteMany→insertOne(restoring deleted documents)Configuration in migrate-mongo.js
Example