diff --git a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php index b6332026cdd..2c058b8bf6a 100644 --- a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php @@ -18,7 +18,6 @@ use function strpos; use function strtok; use function strtolower; -use function trim; /** * Schema manager for the MySql RDBMS. @@ -305,25 +304,28 @@ public function listTableDetails($tableName) $table->addOption('autoincrement', $tableOptions['AUTO_INCREMENT']); } $table->addOption('comment', $tableOptions['TABLE_COMMENT']); + $table->addOption('create_options', $this->parseCreateOptions($tableOptions['CREATE_OPTIONS'])); - if ($tableOptions['CREATE_OPTIONS'] === null) { - return $table; - } + return $table; + } - $createOptionsString = trim($tableOptions['CREATE_OPTIONS']); + /** + * @return string[]|true[] + */ + private function parseCreateOptions(string $string) : array + { + $options = []; - $createOptions = []; + if ($string === '') { + return $options; + } - if ($createOptionsString !== '') { - foreach (explode(' ', $createOptionsString) as $option) { - [$createOption, $value] = explode('=', $option); + foreach (explode(' ', $string) as $pair) { + $parts = explode('=', $pair, 2); - $createOptions[$createOption] = $value; - } + $options[$parts[0]] = $parts[1] ?? true; } - $table->addOption('create_options', $createOptions); - - return $table; + return $options; } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php index 475dcee3ee6..937d04c9058 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php @@ -502,6 +502,7 @@ public function testEnsureTableOptionsAreReflectedInMetadata() : void ROW_FORMAT COMPRESSED COMMENT 'This is a test' AUTO_INCREMENT=42 +PARTITION BY HASH (col1) SQL; $this->connection->query($sql); @@ -511,7 +512,10 @@ public function testEnsureTableOptionsAreReflectedInMetadata() : void self::assertEquals('utf8_general_ci', $onlineTable->getOption('collation')); self::assertEquals(42, $onlineTable->getOption('autoincrement')); self::assertEquals('This is a test', $onlineTable->getOption('comment')); - self::assertEquals(['row_format' => 'COMPRESSED'], $onlineTable->getOption('create_options')); + self::assertEquals([ + 'row_format' => 'COMPRESSED', + 'partitioned' => true, + ], $onlineTable->getOption('create_options')); } public function testEnsureTableWithoutOptionsAreReflectedInMetadata() : void