Skip to content

Commit 310373e

Browse files
committedNov 14, 2014
Audit - delete duplicate audit requests and add unique key
Summary: Fixes T1768. This is mostly a data cleanliness issue as duplicate rows don't really do anything, but let's clear it up now. Test Plan: made some duplicate rows by adding the same auditor multiple times. ran ./bin/storage upgrade and it worked perfectly! Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin, epriestley Maniphest Tasks: T1768 Differential Revision: https://secure.phabricator.com/D10849
1 parent 3fd16a9 commit 310373e

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
$table = new PhabricatorRepositoryAuditRequest();
4+
$conn_w = $table->establishConnection('w');
5+
6+
echo "Removing duplicate Audit requests...\n";
7+
$seen_audit_map = array();
8+
foreach (new LiskMigrationIterator($table) as $request) {
9+
$commit_phid = $request->getCommitPHID();
10+
$auditor_phid = $request->getAuditorPHID();
11+
if (isset($seen_audit_map[$commit_phid][$auditor_phid])) {
12+
$request->delete();
13+
}
14+
15+
if (!isset($seen_audit_map[$commit_phid])) {
16+
$seen_audit_map[$commit_phid] = array();
17+
}
18+
19+
$seen_audit_map[$commit_phid][$auditor_phid] = 1;
20+
}
21+
22+
echo "Done.\n";

‎src/applications/repository/storage/PhabricatorRepositoryAuditRequest.php

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public function getConfiguration() {
2727
'auditorPHID' => array(
2828
'columns' => array('auditorPHID', 'auditStatus'),
2929
),
30+
'key_unique' => array(
31+
'columns' => array('commitPHID', 'auditorPHID'),
32+
'unique' => true,
33+
),
3034
),
3135
) + parent::getConfiguration();
3236
}

0 commit comments

Comments
 (0)
Failed to load comments.