@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+44 -5
+3 -2
src/applications/config/schema/PhabricatorConfigSchemaQuery.php
··· 68 68 69 69 $tables = queryfx_all( 70 70 $conn, 71 - 'SELECT TABLE_SCHEMA, TABLE_NAME, TABLE_COLLATION 71 + 'SELECT TABLE_SCHEMA, TABLE_NAME, TABLE_COLLATION, ENGINE 72 72 FROM INFORMATION_SCHEMA.TABLES 73 73 WHERE TABLE_SCHEMA IN (%Ls)', 74 74 $databases); ··· 146 146 147 147 $table_schema = id(new PhabricatorConfigTableSchema()) 148 148 ->setName($table_name) 149 - ->setCollation($table['TABLE_COLLATION']); 149 + ->setCollation($table['TABLE_COLLATION']) 150 + ->setEngine($table['ENGINE']); 150 151 151 152 $columns = idx($database_column_info, $table_name, array()); 152 153 foreach ($columns as $column) {
+12 -1
src/applications/config/schema/PhabricatorConfigSchemaSpec.php
··· 63 63 $database = $this->getDatabase($database_name); 64 64 65 65 $table = $this->newTable($table_name); 66 + $fulltext_engine = 'MyISAM'; 66 67 67 68 foreach ($columns as $name => $type) { 68 69 if ($type === null) { ··· 84 85 ->setCollation($collation) 85 86 ->setNullable($nullable) 86 87 ->setAutoIncrement($auto); 88 + 89 + // If this table has any FULLTEXT fields, we expect it to use the best 90 + // available FULLTEXT engine, which may not be InnoDB. 91 + switch ($type) { 92 + case 'fulltext': 93 + case 'fulltext?': 94 + $table->setEngine($fulltext_engine); 95 + break; 96 + } 87 97 88 98 $table->addColumn($column); 89 99 } ··· 174 184 protected function newTable($name) { 175 185 return id(new PhabricatorConfigTableSchema()) 176 186 ->setName($name) 177 - ->setCollation($this->getUTF8BinaryCollation()); 187 + ->setCollation($this->getUTF8BinaryCollation()) 188 + ->setEngine('InnoDB'); 178 189 } 179 190 180 191 protected function newColumn($name) {
+6
src/applications/config/schema/PhabricatorConfigStorageSchema.php
··· 18 18 const ISSUE_AUTOINCREMENT = 'autoincrement'; 19 19 const ISSUE_UNKNOWN = 'unknown'; 20 20 const ISSUE_ACCESSDENIED = 'accessdenied'; 21 + const ISSUE_ENGINE = 'engine'; 21 22 22 23 const STATUS_OKAY = 'okay'; 23 24 const STATUS_WARN = 'warn'; ··· 133 134 return pht('Column Has No Specification'); 134 135 case self::ISSUE_ACCESSDENIED: 135 136 return pht('Access Denied'); 137 + case self::ISSUE_ENGINE: 138 + return pht('Better Table Engine Available'); 136 139 default: 137 140 throw new Exception(pht('Unknown schema issue "%s"!', $issue)); 138 141 } ··· 170 173 return pht('This column has the wrong autoincrement setting.'); 171 174 case self::ISSUE_UNKNOWN: 172 175 return pht('This column is missing a type specification.'); 176 + case self::ISSUE_ENGINE: 177 + return pht('This table can use a better table engine.'); 173 178 default: 174 179 throw new Exception(pht('Unknown schema issue "%s"!', $issue)); 175 180 } ··· 194 199 case self::ISSUE_KEYCOLUMNS: 195 200 case self::ISSUE_LONGKEY: 196 201 case self::ISSUE_AUTOINCREMENT: 202 + case self::ISSUE_ENGINE: 197 203 return self::STATUS_WARN; 198 204 default: 199 205 throw new Exception(pht('Unknown schema issue "%s"!', $issue));
+14
src/applications/config/schema/PhabricatorConfigTableSchema.php
··· 4 4 extends PhabricatorConfigStorageSchema { 5 5 6 6 private $collation; 7 + private $engine; 7 8 private $columns = array(); 8 9 private $keys = array(); 9 10 ··· 62 63 return $this->collation; 63 64 } 64 65 66 + public function setEngine($engine) { 67 + $this->engine = $engine; 68 + return $this; 69 + } 70 + 71 + public function getEngine() { 72 + return $this->engine; 73 + } 74 + 65 75 protected function compareToSimilarSchema( 66 76 PhabricatorConfigStorageSchema $expect) { 67 77 68 78 $issues = array(); 69 79 if ($this->getCollation() != $expect->getCollation()) { 70 80 $issues[] = self::ISSUE_COLLATION; 81 + } 82 + 83 + if ($this->getEngine() != $expect->getEngine()) { 84 + $issues[] = self::ISSUE_ENGINE; 71 85 } 72 86 73 87 return $issues;
+9 -2
src/infrastructure/storage/management/workflow/PhabricatorStorageManagementWorkflow.php
··· 308 308 if ($phase == 'main') { 309 309 queryfx( 310 310 $conn, 311 - 'ALTER TABLE %T.%T COLLATE = %s', 311 + 'ALTER TABLE %T.%T COLLATE = %s, ENGINE = %s', 312 312 $adjust['database'], 313 313 $adjust['table'], 314 - $adjust['collation']); 314 + $adjust['collation'], 315 + $adjust['engine']); 315 316 } 316 317 break; 317 318 case 'column': ··· 480 481 $issue_unique = PhabricatorConfigStorageSchema::ISSUE_UNIQUE; 481 482 $issue_longkey = PhabricatorConfigStorageSchema::ISSUE_LONGKEY; 482 483 $issue_auto = PhabricatorConfigStorageSchema::ISSUE_AUTOINCREMENT; 484 + $issue_engine = PhabricatorConfigStorageSchema::ISSUE_ENGINE; 483 485 484 486 $adjustments = array(); 485 487 $errors = array(); ··· 543 545 $issues[] = $issue_collation; 544 546 } 545 547 548 + if ($table->hasIssue($issue_engine)) { 549 + $issues[] = $issue_engine; 550 + } 551 + 546 552 if ($issues) { 547 553 $adjustments[] = array( 548 554 'kind' => 'table', ··· 550 556 'table' => $table_name, 551 557 'issues' => $issues, 552 558 'collation' => $expect_table->getCollation(), 559 + 'engine' => $expect_table->getEngine(), 553 560 ); 554 561 } 555 562