@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator

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

+27 -2
+22
resources/sql/autopatches/20180306.opath.03.purge.php
··· 1 + <?php 2 + 3 + $table = new PhabricatorOwnersPath(); 4 + $conn = $table->establishConnection('w'); 5 + 6 + $seen = array(); 7 + foreach (new LiskMigrationIterator($table) as $path) { 8 + $package_id = $path->getPackageID(); 9 + $repository_phid = $path->getRepositoryPHID(); 10 + $path_index = $path->getPathIndex(); 11 + 12 + if (!isset($seen[$package_id][$repository_phid][$path_index])) { 13 + $seen[$package_id][$repository_phid][$path_index] = true; 14 + continue; 15 + } 16 + 17 + queryfx( 18 + $conn, 19 + 'DELETE FROM %T WHERE id = %d', 20 + $table->getTableName(), 21 + $path->getID()); 22 + }
+2
resources/sql/autopatches/20180306.opath.04.unique.sql
··· 1 + ALTER TABLE {$NAMESPACE}_owners.owners_path 2 + ADD UNIQUE KEY `key_path` (packageID, repositoryPHID, pathIndex);
+3 -2
src/applications/owners/storage/PhabricatorOwnersPath.php
··· 20 20 'excluded' => 'bool', 21 21 ), 22 22 self::CONFIG_KEY_SCHEMA => array( 23 - 'packageID' => array( 24 - 'columns' => array('packageID'), 23 + 'key_path' => array( 24 + 'columns' => array('packageID', 'repositoryPHID', 'pathIndex'), 25 + 'unique' => true, 25 26 ), 26 27 ), 27 28 ) + parent::getConfiguration();