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

Commit 91f3c8c1 by Sascha Depold

correctly propagate the emitter

1 parent b1b9a661
......@@ -36,6 +36,6 @@ postgresn: postgres-native
# test all the dialects \o/
all: sqlite mysql postgres postgres-native binary
all: sqlite mysql postgres postgres-native
.PHONY: sqlite mysql postgres pgsql postgres-native postgresn all test binary
.PHONY: sqlite mysql postgres pgsql postgres-native postgresn all test
......@@ -114,8 +114,8 @@ if(typeof program.env === 'string') {
configuration.environment = program.env
}
if(program.migrate) {
if(configFileExists()) {
if (program.migrate) {
if (configFileExists()) {
var config
, options = {}
......@@ -130,8 +130,9 @@ if(program.migrate) {
if(['database', 'username', 'password'].indexOf(key) == -1) {
options[key] = value
}
if(key === "use_env_variable") {
if(process.env[value]) {
if (key === "use_env_variable") {
if (process.env[value]) {
var db_info = process.env[value].match(
/([^:]+):\/\/([^:]+):([^@]+)@([^:]+):(\d+)\/(.+)/);
config.database = db_info[6];
......@@ -153,17 +154,22 @@ if(program.migrate) {
, migratorOptions = { path: configuration.migrationsPath }
, migrator = sequelize.getMigrator(migratorOptions)
if(program.undo) {
if (program.undo) {
sequelize.migrator.findOrCreateSequelizeMetaDAO().success(function(Meta) {
Meta.find({ order: 'id DESC' }).success(function(meta) {
if(meta) {
if (meta) {
migrator = sequelize.getMigrator(_.extend(migratorOptions, meta), true)
}
migrator.migrate({ method: 'down' })
migrator.migrate({ method: 'down' }).success(function() {
process.exit(0)
})
})
})
} else {
sequelize.migrate()
sequelize.migrate().success(function() {
process.exit(0)
})
}
} else {
console.log('Cannot find "' + relativeConfigFile() + '". Have you run "sequelize --init"?')
......
......@@ -58,8 +58,10 @@ module.exports = (function() {
} else {
self.options.logging("Running migrations...")
}
migrations.forEach(function(migration) {
var migrationTime
chainer.add(migration, 'execute', [options], {
before: function(migration) {
if (self.options.logging !== false) {
......@@ -67,6 +69,7 @@ module.exports = (function() {
}
migrationTime = process.hrtime()
},
after: function(migration) {
migrationTime = process.hrtime(migrationTime)
migrationTime = Math.round( (migrationTime[0] * 1000) + (migrationTime[1] / 1000000));
......@@ -75,6 +78,7 @@ module.exports = (function() {
self.options.logging('Completed in ' + migrationTime + 'ms')
}
},
success: function(migration, callback) {
if (options.method === 'down') {
deleteUndoneMigration.call(self, from, migration, callback)
......@@ -233,11 +237,21 @@ module.exports = (function() {
var self = this
return new Utils.CustomEventEmitter(function(emitter) {
self.findOrCreateSequelizeMetaDAO().success(function(SequelizeMeta) {
SequelizeMeta.find({ order: 'id DESC' }).success(function(meta) {
emitter.emit('success', meta ? meta : null)
}).error(function(err) { emitter.emit('error', err) })
}).error(function(err) { emitter.emit('error', err) })
self
.findOrCreateSequelizeMetaDAO()
.success(function(SequelizeMeta) {
SequelizeMeta
.find({ order: 'id DESC' })
.success(function(meta) {
emitter.emit('success', meta ? meta : null)
})
.error(function(err) {
emitter.emit('error', err)
})
})
.error(function(err) {
emitter.emit('error', err)
})
}).run()
}
......@@ -245,7 +259,8 @@ module.exports = (function() {
var self = this
return new Utils.CustomEventEmitter(function(emitter) {
getLastMigrationFromDatabase.call(self)
getLastMigrationFromDatabase
.call(self)
.success(function(meta) {
emitter.emit('success', meta ? meta.to : null)
})
......
......@@ -210,7 +210,7 @@ module.exports = (function() {
}
Sequelize.prototype.migrate = function(options) {
this.getMigrator().migrate(options)
return this.getMigrator().migrate(options)
}
Sequelize.prototype.query = function(sql, callee, options, replacements) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!