Add unique constraint to AlmanacInterfaces

Summary: See discussion in D19379. The 4-tuple of (device, network, address, port) should be unique.

Test Plan: Created lots of duplicate interfaces, bound those interfaces to various services, observed migration script clean things up correctly.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin, PHID-OPKG-gm6ozazyms6q6i22gyam

Differential Revision: https://secure.phabricator.com/D19388
This commit is contained in:
Austin McKinley
2018-04-18 10:49:22 -07:00
parent 843bfb4fd8
commit 4dc8e2de56
3 changed files with 107 additions and 0 deletions

View File

@@ -15,4 +15,22 @@ final class AlmanacInterfaceEditor
return pht('%s created %s.', $author, $object);
}
protected function didCatchDuplicateKeyException(
PhabricatorLiskDAO $object,
array $xactions,
Exception $ex) {
$errors = array();
$errors[] = new PhabricatorApplicationTransactionValidationError(
null,
pht('Invalid'),
pht(
'Interfaces must have a unique combination of network, device, '.
'address, and port.'),
null);
throw new PhabricatorApplicationTransactionValidationException($errors);
}
}

View File

@@ -35,6 +35,10 @@ final class AlmanacInterface
'key_device' => array(
'columns' => array('devicePHID'),
),
'key_unique' => array(
'columns' => array('devicePHID', 'networkPHID', 'address', 'port'),
'unique' => true,
),
),
) + parent::getConfiguration();
}