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:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user