A simple generic database migration library
Usage
// Create a migration context. You can use one of the provided contexts for postgres and mongodb or write you own
const context = { /*...*/ }
// Define your migrations
const migrations = [
{
from: NO_VERSION, // Special version for uninitialized databases
to: "v1",
migrate(database) {
database.doStuff() // The actual migration code
}
},
{
from: "v1",
to: "v2",
migrate(database) {
database.doOtherStuff()
}
},
/*...*/
]
// Perform the migration to a specific version
// The optimal migration path will automatically be used
await migrate(context, migrations, "v2")