Skip to content

Commit 9263580

Browse files
committed
Merge pull request #201 from wzrdtales/bugfix/foreignkeyBehavior
[Bugfix] Deleting the index together with the foreign key is now optional It's an unexpected behavior, instead it can be explicitly done via options.dropIndex boolean.
2 parents ad11016 + 69960cd commit 9263580

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

lib/driver/mysql.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,24 @@ var MysqlDriver = Base.extend({
250250
this.runSql(sql, callback);
251251
},
252252

253-
removeForeignKey: function(tableName, keyName, callback) {
253+
removeForeignKey: function(tableName, keyName, options, callback) {
254254
var sql = util.format('ALTER TABLE `%s` DROP FOREIGN KEY `%s`', tableName, keyName);
255255
this.runSql(sql, function () {
256-
sql = util.format('ALTER TABLE `%s` DROP INDEX `%s`', tableName, keyName);
257-
this.runSql(sql, function () {
256+
257+
if( typeof(options) === 'function' ) {
258+
259+
options();
260+
}
261+
else if(options.dropIndex === true) {
262+
263+
sql = util.format('ALTER TABLE `%s` DROP INDEX `%s`', tableName, keyName);
264+
this.runSql(sql, function () {
265+
callback();
266+
});
267+
}
268+
else
258269
callback();
259-
});
270+
260271
}.bind(this));
261272
},
262273

0 commit comments

Comments
 (0)