diff --git a/resources/sql/autopatches/20141113.auditdupes.php b/resources/sql/autopatches/20141113.auditdupes.php new file mode 100644 index 0000000000..2cc7b9bab4 --- /dev/null +++ b/resources/sql/autopatches/20141113.auditdupes.php @@ -0,0 +1,22 @@ +establishConnection('w'); + +echo "Removing duplicate Audit requests...\n"; +$seen_audit_map = array(); +foreach (new LiskMigrationIterator($table) as $request) { + $commit_phid = $request->getCommitPHID(); + $auditor_phid = $request->getAuditorPHID(); + if (isset($seen_audit_map[$commit_phid][$auditor_phid])) { + $request->delete(); + } + + if (!isset($seen_audit_map[$commit_phid])) { + $seen_audit_map[$commit_phid] = array(); + } + + $seen_audit_map[$commit_phid][$auditor_phid] = 1; +} + +echo "Done.\n"; diff --git a/src/applications/repository/storage/PhabricatorRepositoryAuditRequest.php b/src/applications/repository/storage/PhabricatorRepositoryAuditRequest.php index 9752529253..56613ac494 100644 --- a/src/applications/repository/storage/PhabricatorRepositoryAuditRequest.php +++ b/src/applications/repository/storage/PhabricatorRepositoryAuditRequest.php @@ -27,6 +27,10 @@ final class PhabricatorRepositoryAuditRequest 'auditorPHID' => array( 'columns' => array('auditorPHID', 'auditStatus'), ), + 'key_unique' => array( + 'columns' => array('commitPHID', 'auditorPHID'), + 'unique' => true, + ), ), ) + parent::getConfiguration(); }