Fix bug foreign key index being delete wrongly
This commit is contained in:
parent
7aec25b0d1
commit
5d8104af3f
|
@ -279,6 +279,8 @@ function mixinMigration(MySQL, mysql) {
|
||||||
if (indexName === 'PRIMARY' ||
|
if (indexName === 'PRIMARY' ||
|
||||||
(m.properties[indexName] && self.id(model, indexName))) return;
|
(m.properties[indexName] && self.id(model, indexName))) return;
|
||||||
|
|
||||||
|
if (m.settings.foreignKeys && m.settings.foreignKeys[indexName]) return;
|
||||||
|
|
||||||
if (indexNames.indexOf(indexName) === -1 && !m.properties[indexName] ||
|
if (indexNames.indexOf(indexName) === -1 && !m.properties[indexName] ||
|
||||||
m.properties[indexName] && !m.properties[indexName].index) {
|
m.properties[indexName] && !m.properties[indexName].index) {
|
||||||
sql.push('DROP INDEX ' + self.client.escapeId(indexName));
|
sql.push('DROP INDEX ' + self.client.escapeId(indexName));
|
||||||
|
|
|
@ -479,7 +479,7 @@ describe('MySQL connector', function() {
|
||||||
// should be actual after autoupdate
|
// should be actual after autoupdate
|
||||||
ds.isActual(function(err, isEqual) {
|
ds.isActual(function(err, isEqual) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
assert(!isEqual);
|
assert(isEqual);
|
||||||
|
|
||||||
// get and validate the properties on this model
|
// get and validate the properties on this model
|
||||||
ds.discoverModelProperties('order_test', function(err, props) {
|
ds.discoverModelProperties('order_test', function(err, props) {
|
||||||
|
@ -527,6 +527,87 @@ describe('MySQL connector', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should auto migrate/update foreign keys in tables multiple times without error', function(done) {
|
||||||
|
|
||||||
|
var customer3_schema = {
|
||||||
|
'name': 'CustomerTest3',
|
||||||
|
'options': {
|
||||||
|
'idInjection': false,
|
||||||
|
'mysql': {
|
||||||
|
'schema': 'myapp_test',
|
||||||
|
'table': 'customer_test3',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'properties': {
|
||||||
|
'id': {
|
||||||
|
'type': 'String',
|
||||||
|
'length': 20,
|
||||||
|
'id': 1,
|
||||||
|
},
|
||||||
|
'name': {
|
||||||
|
'type': 'String',
|
||||||
|
'required': false,
|
||||||
|
'length': 40,
|
||||||
|
},
|
||||||
|
'email': {
|
||||||
|
'type': 'String',
|
||||||
|
'required': true,
|
||||||
|
'length': 40,
|
||||||
|
},
|
||||||
|
'age': {
|
||||||
|
'type': 'Number',
|
||||||
|
'required': false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
var schema_v1 = {
|
||||||
|
'name': 'OrderTest',
|
||||||
|
'options': {
|
||||||
|
'idInjection': false,
|
||||||
|
'mysql': {
|
||||||
|
'schema': 'myapp_test',
|
||||||
|
'table': 'order_test',
|
||||||
|
},
|
||||||
|
'foreignKeys': {
|
||||||
|
'fk_ordertest_customerId': {
|
||||||
|
'name': 'fk_ordertest_customerId',
|
||||||
|
'entity': 'CustomerTest3',
|
||||||
|
'entityKey': 'id',
|
||||||
|
'foreignKey': 'customerId',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'properties': {
|
||||||
|
'id': {
|
||||||
|
'type': 'String',
|
||||||
|
'length': 20,
|
||||||
|
'id': 1,
|
||||||
|
},
|
||||||
|
'customerId': {
|
||||||
|
'type': 'String',
|
||||||
|
'length': 20,
|
||||||
|
},
|
||||||
|
'description': {
|
||||||
|
'type': 'String',
|
||||||
|
'required': false,
|
||||||
|
'length': 40,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
ds.createModel(customer3_schema.name, customer3_schema.properties, customer3_schema.options);
|
||||||
|
ds.createModel(schema_v1.name, schema_v1.properties, schema_v1.options);
|
||||||
|
|
||||||
|
// do initial update/creation of table
|
||||||
|
ds.autoupdate(function(err) {
|
||||||
|
assert(!err, err);
|
||||||
|
ds.autoupdate(function(err, result) {
|
||||||
|
return done(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
function setupAltColNameData() {
|
function setupAltColNameData() {
|
||||||
var schema = {
|
var schema = {
|
||||||
name: 'ColRenameTest',
|
name: 'ColRenameTest',
|
||||||
|
|
Loading…
Reference in New Issue