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

Commit 91f3c8c1 by Sascha Depold

correctly propagate the emitter

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