diff --git a/src/Platforms/AbstractMySQLPlatform.php b/src/Platforms/AbstractMySQLPlatform.php index 6a1d6326f07..f1c4fe1d383 100644 --- a/src/Platforms/AbstractMySQLPlatform.php +++ b/src/Platforms/AbstractMySQLPlatform.php @@ -9,7 +9,6 @@ use Doctrine\DBAL\Exception\InvalidColumnType\ColumnValuesRequired; use Doctrine\DBAL\Platforms\Keywords\KeywordList; use Doctrine\DBAL\Platforms\Keywords\MySQLKeywords; -use Doctrine\DBAL\Schema\AbstractAsset; use Doctrine\DBAL\Schema\ForeignKeyConstraint; use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Schema\MySQLSchemaManager; @@ -367,8 +366,8 @@ public function getAlterTableSQL(TableDiff $diff): array . $this->getColumnDeclarationSQL($newColumn->getQuotedName($this), $newColumnProperties); } - $addedIndexes = $this->indexAssetsByLowerCaseName($diff->getAddedIndexes()); - $modifiedIndexes = $this->indexAssetsByLowerCaseName($diff->getModifiedIndexes()); + $addedIndexes = $this->indexIndexesByLowerCaseName($diff->getAddedIndexes()); + $modifiedIndexes = $this->indexIndexesByLowerCaseName($diff->getModifiedIndexes()); $diffModified = false; if (isset($addedIndexes['primary'])) { @@ -377,19 +376,11 @@ public function getAlterTableSQL(TableDiff $diff): array unset($addedIndexes['primary']); $diffModified = true; } elseif (isset($modifiedIndexes['primary'])) { - $addedColumns = $this->indexAssetsByLowerCaseName($diff->getAddedColumns()); - - // Necessary in case the new primary key includes a new auto_increment column - foreach ($modifiedIndexes['primary']->getColumns() as $columnName) { - if (isset($addedColumns[$columnName]) && $addedColumns[$columnName]->getAutoincrement()) { - $keyColumns = array_values(array_unique($modifiedIndexes['primary']->getColumns())); - $queryParts[] = 'DROP PRIMARY KEY'; - $queryParts[] = 'ADD PRIMARY KEY (' . implode(', ', $keyColumns) . ')'; - unset($modifiedIndexes['primary']); - $diffModified = true; - break; - } - } + $keyColumns = array_values(array_unique($modifiedIndexes['primary']->getColumns())); + $queryParts[] = 'DROP PRIMARY KEY'; + $queryParts[] = 'ADD PRIMARY KEY (' . implode(', ', $keyColumns) . ')'; + unset($modifiedIndexes['primary']); + $diffModified = true; } if ($diffModified) { @@ -833,18 +824,16 @@ public function createSchemaManager(Connection $connection): MySQLSchemaManager } /** - * @param array $assets - * - * @return array + * @param array $indexes * - * @template T of AbstractAsset + * @return array */ - private function indexAssetsByLowerCaseName(array $assets): array + private function indexIndexesByLowerCaseName(array $indexes): array { $result = []; - foreach ($assets as $asset) { - $result[strtolower($asset->getName())] = $asset; + foreach ($indexes as $index) { + $result[strtolower($index->getName())] = $index; } return $result; diff --git a/tests/Functional/Schema/AlterTableTest.php b/tests/Functional/Schema/AlterTableTest.php index 50f11acaef9..8ba92b8b624 100644 --- a/tests/Functional/Schema/AlterTableTest.php +++ b/tests/Functional/Schema/AlterTableTest.php @@ -111,13 +111,6 @@ public function testDropPrimaryKeyWithAutoincrementColumn(): void public function testDropNonAutoincrementColumnFromCompositePrimaryKeyWithAutoincrementColumn(): void { - if ($this->connection->getDatabasePlatform() instanceof AbstractMySQLPlatform) { - self::markTestIncomplete( - 'DBAL does not restore the auto-increment attribute after dropping and adding the constraint,' - . ' which is a bug.', - ); - } - $this->ensureDroppingPrimaryKeyConstraintIsSupported(); $table = new Table('alter_pk'); @@ -135,13 +128,6 @@ public function testAddNonAutoincrementColumnToPrimaryKeyWithAutoincrementColumn { $platform = $this->connection->getDatabasePlatform(); - if ($platform instanceof AbstractMySQLPlatform) { - self::markTestIncomplete( - 'DBAL does not restore the auto-increment attribute after dropping and adding the constraint,' - . ' which is a bug.', - ); - } - if ($platform instanceof SQLitePlatform) { self::markTestSkipped( 'SQLite does not support auto-increment columns as part of composite primary key constraint', @@ -244,6 +230,8 @@ private function testMigration(Table $oldTable, callable $migration): void $diff = $schemaManager->createComparator() ->compareTables($oldTable, $newTable); + self::assertFalse($diff->isEmpty()); + $schemaManager->alterTable($diff); $introspectedTable = $schemaManager->introspectTable($newTable->getName());