From d5bf30bb48ad3bf26f1c17c2b0ebe44c1a6144a9 Mon Sep 17 00:00:00 2001 From: vrana Date: Fri, 9 Mar 2012 18:06:39 -0800 Subject: [PATCH] Prepare database for UTF-8 Summary: D1830#8 Test Plan: `scripts/sql/upgrade_schema.php` Try adding duplicate SSH Public Key - failed. Try adding new SSH Public Key - succeeded. Reviewers: epriestley CC: aran, epriestley Differential Revision: https://secure.phabricator.com/D1852 --- resources/sql/patches/115.prepareutf8.sql | 18 ++++++++++++++++++ .../history/base/DiffusionHistoryQuery.php | 4 ++-- .../history/svn/DiffusionSvnHistoryQuery.php | 4 ++-- .../query/pathid/base/DiffusionPathIDQuery.php | 4 ++-- ...catorUserSSHKeysSettingsPanelController.php | 1 + .../usersshkey/PhabricatorUserSSHKey.php | 3 ++- ...catorRepositoryCommitChangeParserWorker.php | 8 ++++---- 7 files changed, 31 insertions(+), 11 deletions(-) create mode 100644 resources/sql/patches/115.prepareutf8.sql diff --git a/resources/sql/patches/115.prepareutf8.sql b/resources/sql/patches/115.prepareutf8.sql new file mode 100644 index 0000000000..126ed28ee5 --- /dev/null +++ b/resources/sql/patches/115.prepareutf8.sql @@ -0,0 +1,18 @@ +ALTER TABLE `phabricator_project`.`project` + MODIFY `phrictionSlug` varchar(128) binary; + +ALTER TABLE phabricator_repository.repository_path + ADD COLUMN pathHash varchar(32) binary AFTER path; +UPDATE phabricator_repository.repository_path SET pathHash = MD5(path); +ALTER TABLE phabricator_repository.repository_path + MODIFY pathHash varchar(32) binary not null, + DROP KEY path, + ADD UNIQUE KEY (pathHash); + +ALTER TABLE phabricator_user.user_sshkey + ADD COLUMN keyHash varchar(32) binary AFTER keyBody; +UPDATE phabricator_user.user_sshkey SET keyHash = MD5(keyBody); +ALTER TABLE phabricator_user.user_sshkey + MODIFY keyHash varchar(32) binary not null, + DROP KEY keyBody, + ADD UNIQUE KEY (keyHash); diff --git a/src/applications/diffusion/query/history/base/DiffusionHistoryQuery.php b/src/applications/diffusion/query/history/base/DiffusionHistoryQuery.php index da8f55c197..2e479794a3 100644 --- a/src/applications/diffusion/query/history/base/DiffusionHistoryQuery.php +++ b/src/applications/diffusion/query/history/base/DiffusionHistoryQuery.php @@ -128,9 +128,9 @@ abstract class DiffusionHistoryQuery { $path_normal = DiffusionPathIDQuery::normalizePath($path); $paths = queryfx_all( $conn_r, - 'SELECT id, path FROM %T WHERE path IN (%Ls)', + 'SELECT id, path FROM %T WHERE pathHash IN (%Ls)', PhabricatorRepository::TABLE_PATH, - array($path_normal)); + array(md5($path_normal))); $paths = ipull($paths, 'id', 'path'); $path_id = idx($paths, $path_normal); diff --git a/src/applications/diffusion/query/history/svn/DiffusionSvnHistoryQuery.php b/src/applications/diffusion/query/history/svn/DiffusionSvnHistoryQuery.php index 34cc7a78da..8605470518 100644 --- a/src/applications/diffusion/query/history/svn/DiffusionSvnHistoryQuery.php +++ b/src/applications/diffusion/query/history/svn/DiffusionSvnHistoryQuery.php @@ -29,9 +29,9 @@ final class DiffusionSvnHistoryQuery extends DiffusionHistoryQuery { $paths = queryfx_all( $conn_r, - 'SELECT id, path FROM %T WHERE path IN (%Ls)', + 'SELECT id, path FROM %T WHERE pathHash IN (%Ls)', PhabricatorRepository::TABLE_PATH, - array('/'.trim($path, '/'))); + array(md5('/'.trim($path, '/')))); $paths = ipull($paths, 'id', 'path'); $path_id = $paths['/'.trim($path, '/')]; diff --git a/src/applications/diffusion/query/pathid/base/DiffusionPathIDQuery.php b/src/applications/diffusion/query/pathid/base/DiffusionPathIDQuery.php index e47d5497e1..285ff86061 100644 --- a/src/applications/diffusion/query/pathid/base/DiffusionPathIDQuery.php +++ b/src/applications/diffusion/query/pathid/base/DiffusionPathIDQuery.php @@ -36,9 +36,9 @@ final class DiffusionPathIDQuery { $paths = queryfx_all( $repository->establishConnection('r'), - 'SELECT * FROM %T WHERE path IN (%Ls)', + 'SELECT * FROM %T WHERE pathHash IN (%Ls)', PhabricatorRepository::TABLE_PATH, - array_keys($path_normal_map)); + array_map('md5', array_keys($path_normal_map))); $paths = ipull($paths, 'id', 'path'); $result = array(); diff --git a/src/applications/people/controller/settings/panels/sshkeys/PhabricatorUserSSHKeysSettingsPanelController.php b/src/applications/people/controller/settings/panels/sshkeys/PhabricatorUserSSHKeysSettingsPanelController.php index 953b30032c..fb7c7ef67f 100644 --- a/src/applications/people/controller/settings/panels/sshkeys/PhabricatorUserSSHKeysSettingsPanelController.php +++ b/src/applications/people/controller/settings/panels/sshkeys/PhabricatorUserSSHKeysSettingsPanelController.php @@ -94,6 +94,7 @@ final class PhabricatorUserSSHKeysSettingsPanelController } else { $key->setKeyType($type); $key->setKeyBody($body); + $key->setKeyHash(md5($body)); $key->setKeyComment($comment); $e_key = null; diff --git a/src/applications/people/storage/usersshkey/PhabricatorUserSSHKey.php b/src/applications/people/storage/usersshkey/PhabricatorUserSSHKey.php index e20abd6ba2..f1c2940e4e 100644 --- a/src/applications/people/storage/usersshkey/PhabricatorUserSSHKey.php +++ b/src/applications/people/storage/usersshkey/PhabricatorUserSSHKey.php @@ -1,7 +1,7 @@