diff --git a/resources/sql/autopatches/20180306.opath.03.purge.php b/resources/sql/autopatches/20180306.opath.03.purge.php new file mode 100644 --- /dev/null +++ b/resources/sql/autopatches/20180306.opath.03.purge.php @@ -0,0 +1,22 @@ +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()); +} diff --git a/resources/sql/autopatches/20180306.opath.04.unique.sql b/resources/sql/autopatches/20180306.opath.04.unique.sql new file mode 100644 --- /dev/null +++ b/resources/sql/autopatches/20180306.opath.04.unique.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_owners.owners_path + ADD UNIQUE KEY `key_path` (packageID, repositoryPHID, pathIndex); diff --git a/src/applications/owners/storage/PhabricatorOwnersPath.php b/src/applications/owners/storage/PhabricatorOwnersPath.php --- a/src/applications/owners/storage/PhabricatorOwnersPath.php +++ b/src/applications/owners/storage/PhabricatorOwnersPath.php @@ -20,8 +20,9 @@ 'excluded' => 'bool', ), self::CONFIG_KEY_SCHEMA => array( - 'packageID' => array( - 'columns' => array('packageID'), + 'key_path' => array( + 'columns' => array('packageID', 'repositoryPHID', 'pathIndex'), + 'unique' => true, ), ), ) + parent::getConfiguration();