From 1bf4422c749c8a6777e4e77eb7806c8dcad6e2b8 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 6 Mar 2018 19:33:49 -0800 Subject: [PATCH] Add and populate a `pathIndex` column for OwnersPath Summary: Ref T11015. This supports making path names arbitrarily long and putting a proper unique key on the table. Test Plan: - Migrated, checked database, saw nice digested indexes. - Edited a package, saw new rows update with digested indexes. Maniphest Tasks: T11015 Differential Revision: https://secure.phabricator.com/D19181 --- .../autopatches/20180306.opath.01.digest.sql | 2 ++ .../20180306.opath.02.digestpopulate.php | 19 +++++++++++++++++++ .../owners/storage/PhabricatorOwnersPath.php | 11 +++++++++-- 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 resources/sql/autopatches/20180306.opath.01.digest.sql create mode 100644 resources/sql/autopatches/20180306.opath.02.digestpopulate.php diff --git a/resources/sql/autopatches/20180306.opath.01.digest.sql b/resources/sql/autopatches/20180306.opath.01.digest.sql new file mode 100644 index 0000000000..2418366fc5 --- /dev/null +++ b/resources/sql/autopatches/20180306.opath.01.digest.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_owners.owners_path + ADD pathIndex BINARY(12) NOT NULL; diff --git a/resources/sql/autopatches/20180306.opath.02.digestpopulate.php b/resources/sql/autopatches/20180306.opath.02.digestpopulate.php new file mode 100644 index 0000000000..a6b817fc46 --- /dev/null +++ b/resources/sql/autopatches/20180306.opath.02.digestpopulate.php @@ -0,0 +1,19 @@ +establishConnection('w'); + +foreach (new LiskMigrationIterator($table) as $path) { + $index = PhabricatorHash::digestForIndex($path->getPath()); + + if ($index === $path->getPathIndex()) { + continue; + } + + queryfx( + $conn, + 'UPDATE %T SET pathIndex = %s WHERE id = %d', + $table->getTableName(), + $index, + $path->getID()); +} diff --git a/src/applications/owners/storage/PhabricatorOwnersPath.php b/src/applications/owners/storage/PhabricatorOwnersPath.php index f240db2851..47f7faa2b3 100644 --- a/src/applications/owners/storage/PhabricatorOwnersPath.php +++ b/src/applications/owners/storage/PhabricatorOwnersPath.php @@ -4,6 +4,7 @@ final class PhabricatorOwnersPath extends PhabricatorOwnersDAO { protected $packageID; protected $repositoryPHID; + protected $pathIndex; protected $path; protected $excluded; @@ -15,6 +16,7 @@ final class PhabricatorOwnersPath extends PhabricatorOwnersDAO { self::CONFIG_TIMESTAMPS => false, self::CONFIG_COLUMN_SCHEMA => array( 'path' => 'text255', + 'pathIndex' => 'bytes12', 'excluded' => 'bool', ), self::CONFIG_KEY_SCHEMA => array( @@ -25,12 +27,17 @@ final class PhabricatorOwnersPath extends PhabricatorOwnersDAO { ) + parent::getConfiguration(); } - public static function newFromRef(array $ref) { $path = new PhabricatorOwnersPath(); $path->repositoryPHID = $ref['repositoryPHID']; - $path->path = $ref['path']; + + $raw_path = $ref['path']; + + $path->pathIndex = PhabricatorHash::digestForIndex($raw_path); + $path->path = $raw_path; + $path->excluded = $ref['excluded']; + return $path; }