Allow bin/storage adjust to adjust table engines
Summary: Ref T11741. On recent-enough versions of MySQL, we would prefer to use InnoDB for fulltext indexes instead of MyISAM. Allow `bin/storage adjust` to read actual and expected table engines, and apply adjustments as necessary. We have one existing bad table that uses the wrong engine, `metamta_applicationemail`. This change corrects that table. Test Plan: - Ran `bin/storage upgrade`. - Saw the adjustment phase apply this change properly: ``` >>>[463] <query> ALTER TABLE `local_metamta`.`metamta_applicationemail` COLLATE = 'utf8mb4_bin', ENGINE = 'InnoDB' ``` Reviewers: chad Reviewed By: chad Maniphest Tasks: T11741 Differential Revision: https://secure.phabricator.com/D16941
This commit is contained in:
@@ -68,7 +68,7 @@ final class PhabricatorConfigSchemaQuery extends Phobject {
|
||||
|
||||
$tables = queryfx_all(
|
||||
$conn,
|
||||
'SELECT TABLE_SCHEMA, TABLE_NAME, TABLE_COLLATION
|
||||
'SELECT TABLE_SCHEMA, TABLE_NAME, TABLE_COLLATION, ENGINE
|
||||
FROM INFORMATION_SCHEMA.TABLES
|
||||
WHERE TABLE_SCHEMA IN (%Ls)',
|
||||
$databases);
|
||||
@@ -146,7 +146,8 @@ final class PhabricatorConfigSchemaQuery extends Phobject {
|
||||
|
||||
$table_schema = id(new PhabricatorConfigTableSchema())
|
||||
->setName($table_name)
|
||||
->setCollation($table['TABLE_COLLATION']);
|
||||
->setCollation($table['TABLE_COLLATION'])
|
||||
->setEngine($table['ENGINE']);
|
||||
|
||||
$columns = idx($database_column_info, $table_name, array());
|
||||
foreach ($columns as $column) {
|
||||
|
||||
@@ -63,6 +63,7 @@ abstract class PhabricatorConfigSchemaSpec extends Phobject {
|
||||
$database = $this->getDatabase($database_name);
|
||||
|
||||
$table = $this->newTable($table_name);
|
||||
$fulltext_engine = 'MyISAM';
|
||||
|
||||
foreach ($columns as $name => $type) {
|
||||
if ($type === null) {
|
||||
@@ -85,6 +86,15 @@ abstract class PhabricatorConfigSchemaSpec extends Phobject {
|
||||
->setNullable($nullable)
|
||||
->setAutoIncrement($auto);
|
||||
|
||||
// If this table has any FULLTEXT fields, we expect it to use the best
|
||||
// available FULLTEXT engine, which may not be InnoDB.
|
||||
switch ($type) {
|
||||
case 'fulltext':
|
||||
case 'fulltext?':
|
||||
$table->setEngine($fulltext_engine);
|
||||
break;
|
||||
}
|
||||
|
||||
$table->addColumn($column);
|
||||
}
|
||||
|
||||
@@ -174,7 +184,8 @@ abstract class PhabricatorConfigSchemaSpec extends Phobject {
|
||||
protected function newTable($name) {
|
||||
return id(new PhabricatorConfigTableSchema())
|
||||
->setName($name)
|
||||
->setCollation($this->getUTF8BinaryCollation());
|
||||
->setCollation($this->getUTF8BinaryCollation())
|
||||
->setEngine('InnoDB');
|
||||
}
|
||||
|
||||
protected function newColumn($name) {
|
||||
|
||||
@@ -18,6 +18,7 @@ abstract class PhabricatorConfigStorageSchema extends Phobject {
|
||||
const ISSUE_AUTOINCREMENT = 'autoincrement';
|
||||
const ISSUE_UNKNOWN = 'unknown';
|
||||
const ISSUE_ACCESSDENIED = 'accessdenied';
|
||||
const ISSUE_ENGINE = 'engine';
|
||||
|
||||
const STATUS_OKAY = 'okay';
|
||||
const STATUS_WARN = 'warn';
|
||||
@@ -133,6 +134,8 @@ abstract class PhabricatorConfigStorageSchema extends Phobject {
|
||||
return pht('Column Has No Specification');
|
||||
case self::ISSUE_ACCESSDENIED:
|
||||
return pht('Access Denied');
|
||||
case self::ISSUE_ENGINE:
|
||||
return pht('Better Table Engine Available');
|
||||
default:
|
||||
throw new Exception(pht('Unknown schema issue "%s"!', $issue));
|
||||
}
|
||||
@@ -170,6 +173,8 @@ abstract class PhabricatorConfigStorageSchema extends Phobject {
|
||||
return pht('This column has the wrong autoincrement setting.');
|
||||
case self::ISSUE_UNKNOWN:
|
||||
return pht('This column is missing a type specification.');
|
||||
case self::ISSUE_ENGINE:
|
||||
return pht('This table can use a better table engine.');
|
||||
default:
|
||||
throw new Exception(pht('Unknown schema issue "%s"!', $issue));
|
||||
}
|
||||
@@ -194,6 +199,7 @@ abstract class PhabricatorConfigStorageSchema extends Phobject {
|
||||
case self::ISSUE_KEYCOLUMNS:
|
||||
case self::ISSUE_LONGKEY:
|
||||
case self::ISSUE_AUTOINCREMENT:
|
||||
case self::ISSUE_ENGINE:
|
||||
return self::STATUS_WARN;
|
||||
default:
|
||||
throw new Exception(pht('Unknown schema issue "%s"!', $issue));
|
||||
|
||||
@@ -4,6 +4,7 @@ final class PhabricatorConfigTableSchema
|
||||
extends PhabricatorConfigStorageSchema {
|
||||
|
||||
private $collation;
|
||||
private $engine;
|
||||
private $columns = array();
|
||||
private $keys = array();
|
||||
|
||||
@@ -62,6 +63,15 @@ final class PhabricatorConfigTableSchema
|
||||
return $this->collation;
|
||||
}
|
||||
|
||||
public function setEngine($engine) {
|
||||
$this->engine = $engine;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getEngine() {
|
||||
return $this->engine;
|
||||
}
|
||||
|
||||
protected function compareToSimilarSchema(
|
||||
PhabricatorConfigStorageSchema $expect) {
|
||||
|
||||
@@ -70,6 +80,10 @@ final class PhabricatorConfigTableSchema
|
||||
$issues[] = self::ISSUE_COLLATION;
|
||||
}
|
||||
|
||||
if ($this->getEngine() != $expect->getEngine()) {
|
||||
$issues[] = self::ISSUE_ENGINE;
|
||||
}
|
||||
|
||||
return $issues;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user