mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-18 04:42:40 +01:00
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
This commit is contained in:
parent
dbef5660fc
commit
fbc175aa6e
1 changed files with 30 additions and 0 deletions
30
resources/sql/autopatches/20141106.uniqdrafts.php
Normal file
30
resources/sql/autopatches/20141106.uniqdrafts.php
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// Destroy duplicate drafts before storage adjustment adds a unique key to this
|
||||||
|
// table. See T1191. We retain the newest draft.
|
||||||
|
|
||||||
|
// (We can't easily do this in a single SQL statement because MySQL won't let us
|
||||||
|
// modify a table that's joined in a subquery.)
|
||||||
|
|
||||||
|
$table = new DifferentialDraft();
|
||||||
|
$conn_w = $table->establishConnection('w');
|
||||||
|
|
||||||
|
$duplicates = queryfx_all(
|
||||||
|
$conn_w,
|
||||||
|
'SELECT DISTINCT u.id id FROM %T u
|
||||||
|
JOIN %T v
|
||||||
|
ON u.objectPHID = v.objectPHID
|
||||||
|
AND u.authorPHID = v.authorPHID
|
||||||
|
AND u.draftKey = v.draftKey
|
||||||
|
AND u.id < v.id',
|
||||||
|
$table->getTableName(),
|
||||||
|
$table->getTableName());
|
||||||
|
|
||||||
|
$duplicates = ipull($duplicates, 'id');
|
||||||
|
foreach (PhabricatorLiskDAO::chunkSQL($duplicates) as $chunk) {
|
||||||
|
queryfx(
|
||||||
|
$conn_w,
|
||||||
|
'DELETE FROM %T WHERE id IN (%Q)',
|
||||||
|
$table->getTableName(),
|
||||||
|
$chunk);
|
||||||
|
}
|
Loading…
Reference in a new issue