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

Commit cc054e94 by Bulkan Evcimen

dropAllTables now accepts an options object

If this object contains a propert called `skip` that is an array,
then all table names in this array wont be dropped
1 parent d1b1e6cb
...@@ -120,9 +120,15 @@ var QueryInterface = module.exports = { ...@@ -120,9 +120,15 @@ var QueryInterface = module.exports = {
}.bind(this)) }.bind(this))
}, },
dropAllTables: function(tablesToSkip) { dropAllTables: function(options) {
var self = this var self = this
if (!options) {
options = {}
}
var skip = options.skip || [];
return new Utils.CustomEventEmitter(function(dropAllTablesEmitter) { return new Utils.CustomEventEmitter(function(dropAllTablesEmitter) {
var events = [] var events = []
, chainer = new Utils.QueryChainer() , chainer = new Utils.QueryChainer()
...@@ -150,7 +156,7 @@ var QueryInterface = module.exports = { ...@@ -150,7 +156,7 @@ var QueryInterface = module.exports = {
tableNames.forEach(function(tableName) { tableNames.forEach(function(tableName) {
// if tableName is not in the Array of tables names then dont drop it // if tableName is not in the Array of tables names then dont drop it
if (tablesToSkip.indexOf(tableName) == -1) { if (skip.indexOf(tableName) == -1) {
queries.push(self.QueryGenerator.dropTableQuery(tableName).replace(';', '')) queries.push(self.QueryGenerator.dropTableQuery(tableName).replace(';', ''))
} }
}) })
......
...@@ -234,15 +234,18 @@ module.exports = (function() { ...@@ -234,15 +234,18 @@ module.exports = (function() {
}).run() }).run()
} }
QueryInterface.prototype.dropAllTables = function(tablesToSkip) { QueryInterface.prototype.dropAllTables = function(options) {
var self = this var self = this
if (!tablesToSkip) {
tablesToSkip = []; if (!options) {
options = {}
} }
var skip = options.skip || [];
if (this.sequelize.options.dialect === 'sqlite') { if (this.sequelize.options.dialect === 'sqlite') {
// sqlite needs some special treatment as it cannot drop a column // sqlite needs some special treatment as it cannot drop a column
return SQLiteQueryInterface.dropAllTables.call(this, tablesToSkip) return SQLiteQueryInterface.dropAllTables.call(this, options)
} else { } else {
return new Utils.CustomEventEmitter(function(dropAllTablesEmitter) { return new Utils.CustomEventEmitter(function(dropAllTablesEmitter) {
var events = [] var events = []
...@@ -266,7 +269,7 @@ module.exports = (function() { ...@@ -266,7 +269,7 @@ module.exports = (function() {
// add the table removal query to the chainer // add the table removal query to the chainer
tableNames.forEach(function(tableName) { tableNames.forEach(function(tableName) {
// if tableName is not in the Array of tables names then dont drop it // if tableName is not in the Array of tables names then dont drop it
if (tablesToSkip.indexOf(tableName) == -1) { if (skip.indexOf(tableName) == -1) {
chainer.add(self, 'dropTable', [ tableName, { cascade: true } ]) chainer.add(self, 'dropTable', [ tableName, { cascade: true } ])
} }
}) })
......
...@@ -51,7 +51,7 @@ describe(Support.getTestDialectTeaser("QueryInterface"), function () { ...@@ -51,7 +51,7 @@ describe(Support.getTestDialectTeaser("QueryInterface"), function () {
self.queryInterface.createTable('skipme', { self.queryInterface.createTable('skipme', {
name: DataTypes.STRING, name: DataTypes.STRING,
}).success(function() { }).success(function() {
self.queryInterface.dropAllTables(['skipme']).complete(function(err){ self.queryInterface.dropAllTables({skip: ['skipme']}).complete(function(err){
expect(err).to.be.null expect(err).to.be.null
self.queryInterface.showAllTables().complete(function(err, tableNames) { self.queryInterface.showAllTables().complete(function(err, tableNames) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!