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

Commit 6643167a by Martin Aspeli

Make cascade optional

1 parent 151a23f6
...@@ -78,9 +78,10 @@ module.exports = (function() { ...@@ -78,9 +78,10 @@ module.exports = (function() {
dropTableQuery: function(tableName, options) { dropTableQuery: function(tableName, options) {
options = options || {} options = options || {}
var query = "DROP TABLE IF EXISTS <%= table %> CASCADE;" var query = "DROP TABLE IF EXISTS <%= table %><%= cascade %>;"
return Utils._.template(query)({ return Utils._.template(query)({
table: QueryGenerator.addQuotes(tableName) table: QueryGenerator.addQuotes(tableName),
cascade: options.cascade? " CASCADE" : ""
}) })
}, },
......
...@@ -79,8 +79,8 @@ module.exports = (function() { ...@@ -79,8 +79,8 @@ module.exports = (function() {
return queryAndEmit.call(this, sql, 'createTable') return queryAndEmit.call(this, sql, 'createTable')
} }
QueryInterface.prototype.dropTable = function(tableName) { QueryInterface.prototype.dropTable = function(tableName, options) {
var sql = this.QueryGenerator.dropTableQuery(tableName) var sql = this.QueryGenerator.dropTableQuery(tableName, options)
return queryAndEmit.call(this, sql, 'dropTable') return queryAndEmit.call(this, sql, 'dropTable')
} }
...@@ -95,7 +95,7 @@ module.exports = (function() { ...@@ -95,7 +95,7 @@ module.exports = (function() {
chainer.add(self, 'disableForeignKeyConstraints', []) chainer.add(self, 'disableForeignKeyConstraints', [])
tableNames.forEach(function(tableName) { tableNames.forEach(function(tableName) {
chainer.add(self, 'dropTable', [tableName]) chainer.add(self, 'dropTable', [tableName, {cascade: true}])
}) })
chainer.add(self, 'enableForeignKeyConstraints', []) chainer.add(self, 'enableForeignKeyConstraints', [])
......
...@@ -95,11 +95,11 @@ describe('QueryGenerator', function() { ...@@ -95,11 +95,11 @@ describe('QueryGenerator', function() {
dropTableQuery: [ dropTableQuery: [
{ {
arguments: ['myTable'], arguments: ['myTable', {cascade: true}],
expectation: "DROP TABLE IF EXISTS \"myTable\" CASCADE;" expectation: "DROP TABLE IF EXISTS \"myTable\" CASCADE;"
}, },
{ {
arguments: ['mySchema.myTable'], arguments: ['mySchema.myTable', {cascade: true}],
expectation: "DROP TABLE IF EXISTS \"mySchema\".\"myTable\" CASCADE;" expectation: "DROP TABLE IF EXISTS \"mySchema\".\"myTable\" CASCADE;"
} }
], ],
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!