From 0a77b0e53e7f96a46bbf5013489b1de67286f308 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 30 Aug 2018 06:13:43 -0700 Subject: [PATCH] Work around an issue in MariaDB where dropping a column from a UNIQUE KEY fails Summary: See T13193. See T13077. If we drop a column which is part of a UNIQUE KEY, MariaDB raises an error. This is probably a bad idea on our side anyway, but in this case it wasn't an obviously bad idea. To get around this: - Drop the unique key, if it exists, before dropping the column. - Explicitly add the new unique key afterward. Test Plan: Ran `bin/storage upgrade` locally without issue, but I'm on MySQL. Will follow up on T13193. Reviewers: amckinley Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam Differential Revision: https://secure.phabricator.com/D19624 --- .../20180828.phriction.06.c.documentid.php | 20 +++++++++++++++++++ .../20180828.phriction.07.documentkey.sql | 2 ++ .../phriction/storage/PhrictionContent.php | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 resources/sql/autopatches/20180828.phriction.06.c.documentid.php create mode 100644 resources/sql/autopatches/20180828.phriction.07.documentkey.sql diff --git a/resources/sql/autopatches/20180828.phriction.06.c.documentid.php b/resources/sql/autopatches/20180828.phriction.06.c.documentid.php new file mode 100644 index 0000000000..474643d620 --- /dev/null +++ b/resources/sql/autopatches/20180828.phriction.06.c.documentid.php @@ -0,0 +1,20 @@ +establishConnection('w'); + +try { + queryfx( + $conn, + 'ALTER TABLE %T DROP KEY documentID', + $table->getTableName()); +} catch (AphrontQueryException $ex) { + // Ignore. +} diff --git a/resources/sql/autopatches/20180828.phriction.07.documentkey.sql b/resources/sql/autopatches/20180828.phriction.07.documentkey.sql new file mode 100644 index 0000000000..aea3c97130 --- /dev/null +++ b/resources/sql/autopatches/20180828.phriction.07.documentkey.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_phriction.phriction_content + ADD UNIQUE KEY `key_version` (documentPHID, version); diff --git a/src/applications/phriction/storage/PhrictionContent.php b/src/applications/phriction/storage/PhrictionContent.php index 287974715f..5c597ab885 100644 --- a/src/applications/phriction/storage/PhrictionContent.php +++ b/src/applications/phriction/storage/PhrictionContent.php @@ -34,7 +34,7 @@ final class PhrictionContent 'description' => 'text', ), self::CONFIG_KEY_SCHEMA => array( - 'documentID' => array( + 'key_version' => array( 'columns' => array('documentPHID', 'version'), 'unique' => true, ),