Update alterTable to actually drop constraints
This commit is contained in:
parent
1324333ffd
commit
782959cf20
|
@ -129,6 +129,7 @@ function mixinMigration(MySQL, mysql) {
|
||||||
var newFkNames = Object.keys(newFks).filter(function(name) {
|
var newFkNames = Object.keys(newFks).filter(function(name) {
|
||||||
return !!m.settings.foreignKeys[name];
|
return !!m.settings.foreignKeys[name];
|
||||||
});
|
});
|
||||||
|
var dropConstraintSql = [];
|
||||||
var sql = [];
|
var sql = [];
|
||||||
var ai = {};
|
var ai = {};
|
||||||
|
|
||||||
|
@ -185,7 +186,7 @@ function mixinMigration(MySQL, mysql) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (needsToDrop) {
|
if (needsToDrop) {
|
||||||
sql.push('DROP FOREIGN KEY ' + fk.fkName);
|
dropConstraintSql.push('DROP FOREIGN KEY ' + fk.fkName);
|
||||||
removedFks.push(fk); //keep track that we removed these
|
removedFks.push(fk); //keep track that we removed these
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -342,13 +343,22 @@ function mixinMigration(MySQL, mysql) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sql.length) {
|
if (sql.length || dropConstraintSql.length) {
|
||||||
var query = 'ALTER TABLE ' + self.tableEscaped(model) + ' ' +
|
var stmtList = [dropConstraintSql, sql]
|
||||||
sql.join(',\n');
|
.filter(function(stmts) { return stmts.length; })
|
||||||
|
.map(function(statements) {
|
||||||
|
return 'ALTER TABLE ' + self.tableEscaped(model) +
|
||||||
|
' ' + statements.join(',\n');
|
||||||
|
});
|
||||||
|
|
||||||
if (checkOnly) {
|
if (checkOnly) {
|
||||||
done(null, true, {statements: sql, query: query});
|
done(null, true, {statements: stmtList, query: stmtList.join(';')});
|
||||||
} else {
|
} else {
|
||||||
this.execute(query, done);
|
async.eachSeries(stmtList, function(stmt, execDone) {
|
||||||
|
self.execute(stmt, execDone);
|
||||||
|
}, function(err) {
|
||||||
|
done(err);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
done();
|
done();
|
||||||
|
|
Loading…
Reference in New Issue