chg: [appModel] Create UUID unique index for other tables

pull/6168/head
mokaddem 2020-09-03 13:29:54 +02:00
parent b374e67a15
commit fb5c26997a
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
2 changed files with 20 additions and 12 deletions

View File

@ -1494,9 +1494,22 @@ class AppModel extends Model
$indexArray[] = array('shadow_attributes', 'last_seen'); $indexArray[] = array('shadow_attributes', 'last_seen');
break; break;
case 'createUUIDsConstraints': case 'createUUIDsConstraints':
$this->__dropIndex('events', 'uuid');
$sqlArray[] = "ALTER TABLE events ADD CONSTRAINT `uuid` UNIQUE (uuid);"; $sqlArray[] = "ALTER TABLE events ADD CONSTRAINT `uuid` UNIQUE (uuid);";
$this->__dropIndex('attributes', 'uuid');
$sqlArray[] = "ALTER TABLE attributes ADD CONSTRAINT `uuid` UNIQUE (uuid);"; $sqlArray[] = "ALTER TABLE attributes ADD CONSTRAINT `uuid` UNIQUE (uuid);";
$this->__dropIndex('objects', 'uuid');
$sqlArray[] = "ALTER TABLE objects ADD CONSTRAINT `uuid` UNIQUE (uuid);"; $sqlArray[] = "ALTER TABLE objects ADD CONSTRAINT `uuid` UNIQUE (uuid);";
$this->__dropIndex('sightings', 'uuid');
$sqlArray[] = "ALTER TABLE sightings ADD CONSTRAINT `uuid` UNIQUE (uuid);";
$this->__dropIndex('dashboards', 'uuid');
$sqlArray[] = "ALTER TABLE dashboards ADD CONSTRAINT `uuid` UNIQUE (uuid);";
$this->__dropIndex('inbox', 'uuid');
$sqlArray[] = "ALTER TABLE inbox ADD CONSTRAINT `uuid` UNIQUE (uuid);";
$this->__dropIndex('organisations', 'uuid');
$sqlArray[] = "ALTER TABLE organisations ADD CONSTRAINT `uuid` UNIQUE (uuid);";
$this->__dropIndex('tag_collections', 'uuid');
$sqlArray[] = "ALTER TABLE tag_collections ADD CONSTRAINT `uuid` UNIQUE (uuid);";
break; break;
default: default:
return false; return false;
@ -2303,7 +2316,6 @@ class AppModel extends Model
} }
} }
} }
$this->updateDatabase('makeAttributeUUIDsUnique');
return $counter; return $counter;
} }
@ -2342,7 +2354,6 @@ class AppModel extends Model
} }
} }
} }
$this->updateDatabase('makeEventUUIDsUnique');
return $counter; return $counter;
} }
@ -2369,7 +2380,6 @@ class AppModel extends Model
} }
} }
} }
$this->updateDatabase('makeObjectUUIDsUnique');
return $counter; return $counter;
} }
@ -2398,7 +2408,6 @@ class AppModel extends Model
} }
} }
} }
$this->updateDatabase('makeClusterUUIDsUnique');
return $counter; return $counter;
} }
@ -2413,19 +2422,18 @@ class AppModel extends Model
)); ));
$counter = 0; $counter = 0;
foreach ($duplicates as $duplicate) { foreach ($duplicates as $duplicate) {
$attributes = $this->Sighting->find('all', array( $sightings = $this->Sighting->find('all', array(
'recursive' => -1, 'recursive' => -1,
'conditions' => array('uuid' => $duplicate['Sighting']['uuid']), 'conditions' => array('uuid' => $duplicate['Sighting']['uuid']),
)); ));
foreach ($sightings as $k => $sighting) { foreach ($sightings as $k => $sighting) {
if ($k > 0) { if ($k > 0) {
$this->Sighting->delete($sighting['Sighting']['id']); $this->Sighting->delete($sighting['Sighting']['id']);
$this->Log->createLogEntry('SYSTEM', 'delete', 'Sighting', $sighting['Sighting']['id'], __('Removed sighting (%s)', $sighting['Sighting']['id']), __('Sighting\'s UUID duplicated (%s)', $sighting['Sighting']['uuid'])); // $this->Log->createLogEntry('SYSTEM', 'delete', 'Sighting', $sighting['Sighting']['id'], __('Removed sighting (%s)', $sighting['Sighting']['id']), __('Sighting\'s UUID duplicated (%s)', $sighting['Sighting']['uuid']));
$counter++; $counter++;
} }
} }
} }
$this->updateDatabase('makeSightingUUIDsUnique');
return $counter; return $counter;
} }

View File

@ -6817,7 +6817,7 @@
"dashboards": { "dashboards": {
"id": true, "id": true,
"name": false, "name": false,
"uuid": false, "uuid": true,
"user_id": false, "user_id": false,
"restrict_to_org_id": false, "restrict_to_org_id": false,
"restrict_to_permission_flag": false "restrict_to_permission_flag": false
@ -6920,7 +6920,7 @@
"id": true, "id": true,
"title": false, "title": false,
"type": false, "type": false,
"uuid": false, "uuid": true,
"user_agent_sha256": false, "user_agent_sha256": false,
"ip": false, "ip": false,
"timestamp": false "timestamp": false
@ -6990,7 +6990,7 @@
}, },
"organisations": { "organisations": {
"id": true, "id": true,
"uuid": false, "uuid": true,
"name": false "name": false
}, },
"org_blocklists": { "org_blocklists": {
@ -7077,7 +7077,7 @@
"attribute_id": false, "attribute_id": false,
"event_id": false, "event_id": false,
"org_id": false, "org_id": false,
"uuid": false, "uuid": true,
"source": false, "source": false,
"type": false "type": false
}, },
@ -7090,7 +7090,7 @@
}, },
"tag_collections": { "tag_collections": {
"id": true, "id": true,
"uuid": false, "uuid": true,
"user_id": false, "user_id": false,
"org_id": false "org_id": false
}, },