Skip to content

Commit fbc175a

Browse files
author
epriestley
committed
Force Differential draft uniqueness
Summary: Ref T1191. A couple of installs have hit issues with this table, so clean it up before adjustment adds a unique key to it. Test Plan: Dropped key, added duplicate rows, ran patch, got cleanup, ran adjust to get the key back. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T1191 Differential Revision: https://secure.phabricator.com/D10799
1 parent dbef566 commit fbc175a

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
// Destroy duplicate drafts before storage adjustment adds a unique key to this
4+
// table. See T1191. We retain the newest draft.
5+
6+
// (We can't easily do this in a single SQL statement because MySQL won't let us
7+
// modify a table that's joined in a subquery.)
8+
9+
$table = new DifferentialDraft();
10+
$conn_w = $table->establishConnection('w');
11+
12+
$duplicates = queryfx_all(
13+
$conn_w,
14+
'SELECT DISTINCT u.id id FROM %T u
15+
JOIN %T v
16+
ON u.objectPHID = v.objectPHID
17+
AND u.authorPHID = v.authorPHID
18+
AND u.draftKey = v.draftKey
19+
AND u.id < v.id',
20+
$table->getTableName(),
21+
$table->getTableName());
22+
23+
$duplicates = ipull($duplicates, 'id');
24+
foreach (PhabricatorLiskDAO::chunkSQL($duplicates) as $chunk) {
25+
queryfx(
26+
$conn_w,
27+
'DELETE FROM %T WHERE id IN (%Q)',
28+
$table->getTableName(),
29+
$chunk);
30+
}

0 commit comments

Comments
 (0)