seppevs / migrate-mongo

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

adding migration changes programmatically #247

Open veeramarni opened 4 years ago

veeramarni commented 4 years ago

Is your feature request related to a problem? Please describe.

Instead of passing migration definition as file, if we can provide that as object like below will be very helpful.

Describe the solution you'd like A clear and concise description of what you want to happen.

var migrationDef = {
    id: "RenameProperty",
    up: function (done) {
        var coll = this.db.collection("GeneralSettings");
        coll.updateMany({}, {$rename: {"nmae": "name"}}, done);
    },
    down: function (done) {
        var coll = this.db.collection("GeneralSettings");
        coll.updateMany({}, {$rename: {"name": "nmae"}}, done);
    }
};

migrator.add(migrationDef);

migrator.rollback(function (error, results) {
    if (error)
        console.error(error);
    migrator.dispose(function () {
        console.log("DISCONNECTED!");
    });
    console.log(results);
});