mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-04 20:52:43 +01:00
fbc175aa6e
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
30 lines
832 B
PHP
30 lines
832 B
PHP
<?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);
|
|
}
|