Better Migration - Make migrations easy!
This is a simple tool to migrate data. It features some key features:
- Easy to write migrations: just implement the function
- Out of the box auto-save current version (into a simple text file)
- Out of the box locking mechanism to ensure only one migration is running
- Customizable version saving and locking mechanism
npm install --save better-migration
Usage
var migration = ;
The idea behind this tool is simple:
1. Write a migration script
migrationversion'1.0.0' { // Your migration script, call cb() when done. // cb(err) will abort the migration. ;}
2. Start the migration
This will run your migration scripts one at a time until it reaches the latest version.
migrationstart { // If the error is set, the script failed, and you should probably not continue. // Your data is updated to the latest semver version (in this case is 1.0.0)}
When you need to migrate again, just call migration.set with the new version number, and restart.
Advanced usage
By default, we save the current version into a file, ./version
. You may change this:
var migration = ;
Optionally, you may set your own functions for setting the version/lock:
// Set the function to get the versionmigration { ;}; // Set the function to set the versionmigration { ; // Call when saved} // Set the function to obtain a lock for migration.migration { // After you acquire the lock, you must return a release function // so that we can release the lock after the migration is complete. }
Contributions welcome!
Credits
This library was initially made by the awesome team of engineers at Diamond.
If you haven't already, make sure you install Diamond!