不要怂,就是干,撸起袖子干!

Commit 21286f12 by freezy

Added execute() for direct migration per file.

1 parent 5cc12629
Showing with 34 additions and 3 deletions
var moment = require("moment") var moment = require("moment")
, path = require("path")
, Utils = require("./utils") , Utils = require("./utils")
, DataTypes = require("./data-types") , DataTypes = require("./data-types")
, QueryInterface = require("./query-interface") , QueryInterface = require("./query-interface")
module.exports = (function() { module.exports = (function() {
var Migration = function(migrator, path) { var Migration = function(migrator, p) {
this.migrator = migrator this.migrator = migrator
this.path = path this.path = path.normalize(p)
this.filename = Utils._.last(this.path.split('/')) this.filename = Utils._.last(this.path.split(path.sep))
var parsed = Migration.parseFilename(this.filename) var parsed = Migration.parseFilename(this.filename)
......
...@@ -166,6 +166,36 @@ module.exports = (function() { ...@@ -166,6 +166,36 @@ module.exports = (function() {
} }
}).run() }).run()
} }
Migrator.prototype.execute = function(filename) {
var self = this;
return new Utils.CustomEventEmitter(function(emitter) {
var chainer = new Utils.QueryChainer;
var addMigration = function(filename) {
self.options.logging('Adding migration script at ' + filename )
var migration = new Migration(self, filename)
chainer.add(migration, 'execute', [{ method: 'up' }], {
success: function(migration, callback) {
callback();
}
})
}
if (Utils._.isArray(filename)) {
Utils._.each(filename, function(f) {
addMigration(f);
})
} else {
addMigration(filename);
}
chainer
.runSerially({ skipOnError: true })
.success(function() { emitter.emit('success', null) })
.error(function(err) { emitter.emit('error', err) })
}).run()
}
// private // private
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!