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

Commit 55e8be8a by sdepold

delete SequelizeMeta database entry after undoing a migration

1 parent 6d1bd3fc
Showing with 20 additions and 2 deletions
...@@ -36,9 +36,12 @@ module.exports = (function() { ...@@ -36,9 +36,12 @@ module.exports = (function() {
emitter.emit('failure', err) emitter.emit('failure', err)
} else { } else {
var chainer = new Utils.QueryChainer var chainer = new Utils.QueryChainer
, from = migrations[0]
if(options.method == 'down') if(options.method == 'down') {
migrations.reverse() migrations.reverse()
from = migrations[0]
}
migrations.forEach(function(migration) { migrations.forEach(function(migration) {
chainer.add(migration, 'execute', [options], { chainer.add(migration, 'execute', [options], {
...@@ -51,7 +54,10 @@ module.exports = (function() { ...@@ -51,7 +54,10 @@ module.exports = (function() {
console.log('Executed migration: ' + migration.filename) console.log('Executed migration: ' + migration.filename)
}, },
success: function(migration, callback) { success: function(migration, callback) {
saveSuccessfulMigration.call(self, migrations[0], migration, callback) if(options.method == 'down')
deleteUndoneMigration.call(self, from, migration, callback)
else
saveSuccessfulMigration.call(self, from, migration, callback)
} }
}) })
}) })
...@@ -195,5 +201,17 @@ module.exports = (function() { ...@@ -195,5 +201,17 @@ module.exports = (function() {
}) })
} }
var deleteUndoneMigration = function(from, to, callback) {
var self = this
self.findOrCreateSequelizeMetaModel().success(function(SequelizeMeta) {
SequelizeMeta
.find({ from: from.migrationId, to: to.migrationId })
.success(function(meta) {
meta.destroy().success(callback)
})
})
}
return Migrator return Migrator
})() })()
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!