Add a unique key to OwnersPath on "<packageID, repositoryPHID, pathIndex>"
Summary: Depends on D19181. Ref T11015. This nukes duplicates from the table if they exist, then adds a unique key. (Duplicates should not exist and can not be added with any recent version of the web UI.) Test Plan: - Tried to add duplicates with web UI, didn't have any luck. - Explicitly added duplicates with manual `INSERT`s. - Viewed packages in web UI and saw duplicates. - Ran migrations, got a clean purge and a nice unique key. - There's still no way to actually hit a duplicate key error in the UI (unless you can collide hashes, I suppose), this is purely a correctness/robustness change. Maniphest Tasks: T11015 Differential Revision: https://secure.phabricator.com/D19182
This commit is contained in:
22
resources/sql/autopatches/20180306.opath.03.purge.php
Normal file
22
resources/sql/autopatches/20180306.opath.03.purge.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$table = new PhabricatorOwnersPath();
|
||||||
|
$conn = $table->establishConnection('w');
|
||||||
|
|
||||||
|
$seen = array();
|
||||||
|
foreach (new LiskMigrationIterator($table) as $path) {
|
||||||
|
$package_id = $path->getPackageID();
|
||||||
|
$repository_phid = $path->getRepositoryPHID();
|
||||||
|
$path_index = $path->getPathIndex();
|
||||||
|
|
||||||
|
if (!isset($seen[$package_id][$repository_phid][$path_index])) {
|
||||||
|
$seen[$package_id][$repository_phid][$path_index] = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
queryfx(
|
||||||
|
$conn,
|
||||||
|
'DELETE FROM %T WHERE id = %d',
|
||||||
|
$table->getTableName(),
|
||||||
|
$path->getID());
|
||||||
|
}
|
||||||
2
resources/sql/autopatches/20180306.opath.04.unique.sql
Normal file
2
resources/sql/autopatches/20180306.opath.04.unique.sql
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE {$NAMESPACE}_owners.owners_path
|
||||||
|
ADD UNIQUE KEY `key_path` (packageID, repositoryPHID, pathIndex);
|
||||||
@@ -20,8 +20,9 @@ final class PhabricatorOwnersPath extends PhabricatorOwnersDAO {
|
|||||||
'excluded' => 'bool',
|
'excluded' => 'bool',
|
||||||
),
|
),
|
||||||
self::CONFIG_KEY_SCHEMA => array(
|
self::CONFIG_KEY_SCHEMA => array(
|
||||||
'packageID' => array(
|
'key_path' => array(
|
||||||
'columns' => array('packageID'),
|
'columns' => array('packageID', 'repositoryPHID', 'pathIndex'),
|
||||||
|
'unique' => true,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
) + parent::getConfiguration();
|
) + parent::getConfiguration();
|
||||||
|
|||||||
Reference in New Issue
Block a user