From 9d5a2b3b4f6808cd8172104e221b9217315d8313 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 14 Sep 2017 05:08:35 -0700 Subject: [PATCH] Add a RefPosition table to hold branch/tag positions once the RefCursor table is split Summary: Ref T11823. Currently, we have a "RefCursor" table which stores rows like `` with some more data. Because Mercurial can have a single branch pointing at several different places, this table must allow multiple rows with the same branch or tag name. Among other things, this means there isn't a single PHID which can be used to identify a branch name in a stable way. However, we have several UIs where we want to be able to do this. Some specific examples where we run into trouble: in Mercurial, if there are 5 heads for "default", that means there are 5 phids. And currently, if someone deletes a branch, we lose the PHID for it. Instead, we'd rather retain it so the whole world doesn't break if you accidentally delete a branch and then fix it a little later. (I'll likely hold this until the rest of the logic is fleshed out a little more in followup changes.) Test Plan: Ran `bin/storage upgrade`, saw the table get created without warnings. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T11823 Differential Revision: https://secure.phabricator.com/D18602 --- .../autopatches/20170914.ref.01.position.sql | 6 +++++ src/__phutil_library_map__.php | 2 ++ .../PhabricatorRepositoryRefPosition.php | 26 +++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 resources/sql/autopatches/20170914.ref.01.position.sql create mode 100644 src/applications/repository/storage/PhabricatorRepositoryRefPosition.php diff --git a/resources/sql/autopatches/20170914.ref.01.position.sql b/resources/sql/autopatches/20170914.ref.01.position.sql new file mode 100644 index 0000000000..2d0a505d17 --- /dev/null +++ b/resources/sql/autopatches/20170914.ref.01.position.sql @@ -0,0 +1,6 @@ +CREATE TABLE {$NAMESPACE}_repository.repository_refposition ( + id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + cursorID INT UNSIGNED NOT NULL, + commitIdentifier VARCHAR(40) NOT NULL COLLATE {$COLLATE_TEXT}, + isClosed BOOL NOT NULL +) ENGINE=InnoDB, COLLATE {$COLLATE_TEXT}; diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 282e5aaf62..c535d46322 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -3863,6 +3863,7 @@ phutil_register_library_map(array( 'PhabricatorRepositoryRefCursorPHIDType' => 'applications/repository/phid/PhabricatorRepositoryRefCursorPHIDType.php', 'PhabricatorRepositoryRefCursorQuery' => 'applications/repository/query/PhabricatorRepositoryRefCursorQuery.php', 'PhabricatorRepositoryRefEngine' => 'applications/repository/engine/PhabricatorRepositoryRefEngine.php', + 'PhabricatorRepositoryRefPosition' => 'applications/repository/storage/PhabricatorRepositoryRefPosition.php', 'PhabricatorRepositoryRepositoryPHIDType' => 'applications/repository/phid/PhabricatorRepositoryRepositoryPHIDType.php', 'PhabricatorRepositorySchemaSpec' => 'applications/repository/storage/PhabricatorRepositorySchemaSpec.php', 'PhabricatorRepositorySearchEngine' => 'applications/repository/query/PhabricatorRepositorySearchEngine.php', @@ -9434,6 +9435,7 @@ phutil_register_library_map(array( 'PhabricatorRepositoryRefCursorPHIDType' => 'PhabricatorPHIDType', 'PhabricatorRepositoryRefCursorQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhabricatorRepositoryRefEngine' => 'PhabricatorRepositoryEngine', + 'PhabricatorRepositoryRefPosition' => 'PhabricatorRepositoryDAO', 'PhabricatorRepositoryRepositoryPHIDType' => 'PhabricatorPHIDType', 'PhabricatorRepositorySchemaSpec' => 'PhabricatorConfigSchemaSpec', 'PhabricatorRepositorySearchEngine' => 'PhabricatorApplicationSearchEngine', diff --git a/src/applications/repository/storage/PhabricatorRepositoryRefPosition.php b/src/applications/repository/storage/PhabricatorRepositoryRefPosition.php new file mode 100644 index 0000000000..838037b1a0 --- /dev/null +++ b/src/applications/repository/storage/PhabricatorRepositoryRefPosition.php @@ -0,0 +1,26 @@ + false, + self::CONFIG_COLUMN_SCHEMA => array( + 'commitIdentifier' => 'text40', + 'isClosed' => 'bool', + ), + self::CONFIG_KEY_SCHEMA => array( + 'key_position' => array( + 'columns' => array('cursorID', 'commitIdentifier'), + 'unique' => true, + ), + ), + ) + parent::getConfiguration(); + } + +}