1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-26 07:20:57 +01:00

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
This commit is contained in:
epriestley 2018-08-30 06:13:43 -07:00
parent 75a0455152
commit 0a77b0e53e
3 changed files with 23 additions and 1 deletions

View file

@ -0,0 +1,20 @@
<?php
// See T13193. We're about to drop the "documentID" column, which is part of
// a UNIQUE KEY. In MariaDB, we must first drop the "documentID" key or we get
// into deep trouble.
// There's no "IF EXISTS" modifier for "ALTER TABLE" so run this as a PHP patch
// instead of an SQL patch.
$table = new PhrictionContent();
$conn = $table->establishConnection('w');
try {
queryfx(
$conn,
'ALTER TABLE %T DROP KEY documentID',
$table->getTableName());
} catch (AphrontQueryException $ex) {
// Ignore.
}

View file

@ -0,0 +1,2 @@
ALTER TABLE {$NAMESPACE}_phriction.phriction_content
ADD UNIQUE KEY `key_version` (documentPHID, version);

View file

@ -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,
),