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

Commit 0920a17a by sdepold

added undo for migrations

1 parent 3992d875
Showing with 17 additions and 2 deletions
...@@ -34,6 +34,7 @@ program ...@@ -34,6 +34,7 @@ program
.version('1.3.0') .version('1.3.0')
.option('-i, --init', 'Initializes the project. Creates a config/config.json') .option('-i, --init', 'Initializes the project. Creates a config/config.json')
.option('-m, --migrate', 'Runs undone migrations') .option('-m, --migrate', 'Runs undone migrations')
.option('-u, --undo', 'Redo the last migration.')
.option('-f, --force', 'Forces the action to be done.') .option('-f, --force', 'Forces the action to be done.')
.parse(process.argv) .parse(process.argv)
...@@ -50,8 +51,22 @@ if(program.migrate) { ...@@ -50,8 +51,22 @@ if(program.migrate) {
options = _.extend(options, { logging: false }) options = _.extend(options, { logging: false })
var sequelize = new Sequelize(config.database, config.username, config.password, options) var sequelize = new Sequelize(config.database, config.username, config.password, options)
sequelize.migrate({ path: __dirname + '/../spec/assets/migrations' }) , migratorOptions = { path: __dirname + '/../spec/assets/migrations' }
, migrator = sequelize.getMigrator(migratorOptions)
if(program.undo) {
sequelize.migrator.findOrCreateSequelizeMetaModel().success(function(Meta) {
Meta.find({ order: 'id DESC' }).success(function(meta) {
if(meta)
migrator = sequelize.getMigrator(_.extend(migratorOptions, meta), true)
migrator.migrate({ method: 'down' })
})
})
} else {
sequelize.migrate()
}
} else { } else {
throw new Error('Please add a configuration file under config/config.json. You might run "sequelize --init".') throw new Error('Please add a configuration file under config/config.json. You might run "sequelize --init".')
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!