diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index d1bab0a6233..5c9ae3a0554 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -41,6 +41,7 @@ jobs: - "8.0" - "8.1" - "8.2" + - "8.3" dependencies: - "highest" extension: @@ -106,8 +107,8 @@ jobs: matrix: php-version: - "7.4" - - "8.1" - "8.2" + - "8.3" oracle-version: - "21" include: @@ -164,8 +165,8 @@ jobs: matrix: php-version: - "7.4" - - "8.1" - "8.2" + - "8.3" oracle-version: - "21" include: @@ -229,16 +230,16 @@ jobs: - "pgsql" - "pdo_pgsql" include: - - php-version: "8.1" + - php-version: "8.2" postgres-version: "15" extension: "pgsql" - - php-version: "8.2" + - php-version: "8.3" postgres-version: "15" extension: "pgsql" - - php-version: "8.1" + - php-version: "8.2" postgres-version: "15" extension: "pdo_pgsql" - - php-version: "8.2" + - php-version: "8.3" postgres-version: "15" extension: "pdo_pgsql" @@ -302,22 +303,22 @@ jobs: - "mysqli" - "pdo_mysql" include: - - php-version: "8.1" + - php-version: "8.2" mariadb-version: "10.7" extension: "mysqli" - - php-version: "8.1" + - php-version: "8.2" mariadb-version: "10.7" extension: "pdo_mysql" - - php-version: "8.1" + - php-version: "8.2" mariadb-version: "10.11" extension: "mysqli" - - php-version: "8.1" + - php-version: "8.2" mariadb-version: "10.11" extension: "pdo_mysql" - - php-version: "8.2" + - php-version: "8.3" mariadb-version: "10.11" extension: "mysqli" - - php-version: "8.2" + - php-version: "8.3" mariadb-version: "10.11" extension: "pdo_mysql" @@ -371,7 +372,7 @@ jobs: matrix: php-version: - "7.4" - - "8.0" + - "8.1" mysql-version: - "5.7" - "8.0" @@ -390,20 +391,20 @@ jobs: php-version: "7.4" mysql-version: "8.0" extension: "mysqli" - - php-version: "8.1" + - php-version: "8.2" mysql-version: "8.0" extension: "mysqli" custom-entrypoint: >- --entrypoint sh mysql:8 -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password" - - php-version: "8.1" + - php-version: "8.2" mysql-version: "8.0" extension: "pdo_mysql" custom-entrypoint: >- --entrypoint sh mysql:8 -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password" - - php-version: "8.2" + - php-version: "8.3" mysql-version: "8.0" extension: "mysqli" - - php-version: "8.2" + - php-version: "8.3" mysql-version: "8.0" extension: "pdo_mysql" @@ -461,8 +462,8 @@ jobs: matrix: php-version: - "7.4" - - "8.1" - "8.2" + - "8.3" extension: - "sqlsrv" - "pdo_sqlsrv" @@ -529,6 +530,7 @@ jobs: php-version: - "7.4" - "8.2" + - "8.3" services: ibm_db2: diff --git a/src/Platforms/AbstractPlatform.php b/src/Platforms/AbstractPlatform.php index 1d33038411f..033e952e24a 100644 --- a/src/Platforms/AbstractPlatform.php +++ b/src/Platforms/AbstractPlatform.php @@ -4155,7 +4155,7 @@ public function getDefaultSchemaName() */ public function supportsCreateDropDatabase() { - Deprecation::trigger( + Deprecation::triggerIfCalledFromOutside( 'doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5513', '%s is deprecated.', diff --git a/src/Platforms/PostgreSQLPlatform.php b/src/Platforms/PostgreSQLPlatform.php index 9c528438734..9e6648cbda2 100644 --- a/src/Platforms/PostgreSQLPlatform.php +++ b/src/Platforms/PostgreSQLPlatform.php @@ -10,6 +10,7 @@ use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Schema\PostgreSQLSchemaManager; use Doctrine\DBAL\Schema\Sequence; +use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Types\BinaryType; use Doctrine\DBAL\Types\BlobType; @@ -810,6 +811,36 @@ public function getDropForeignKeySQL($foreignKey, $table) return $this->getDropConstraintSQL($foreignKey, $table); } + /** + * {@inheritDoc} + */ + public function getDropIndexSQL($index, $table = null) + { + if ($index instanceof Index && $index->isPrimary() && $table !== null) { + $constraintName = $index->getName() === 'primary' ? $this->tableName($table) . '_pkey' : $index->getName(); + + return $this->getDropConstraintSQL($constraintName, $table); + } + + if ($index === '"primary"' && $table !== null) { + $constraintName = $this->tableName($table) . '_pkey'; + + return $this->getDropConstraintSQL($constraintName, $table); + } + + return parent::getDropIndexSQL($index, $table); + } + + /** + * @param Table|string|null $table + * + * @return string + */ + private function tableName($table) + { + return $table instanceof Table ? $table->getName() : (string) $table; + } + /** * {@inheritDoc} */ diff --git a/tests/Functional/Driver/DBAL6024Test.php b/tests/Functional/Driver/DBAL6024Test.php new file mode 100644 index 00000000000..4b6d3bf374f --- /dev/null +++ b/tests/Functional/Driver/DBAL6024Test.php @@ -0,0 +1,43 @@ +addColumn('id', 'integer'); + $table->setPrimaryKey(['id']); + $this->dropAndCreateTable($table); + + $newTable = clone $table; + $newTable->dropPrimaryKey(); + + $schemaManager = $this->connection->createSchemaManager(); + $diff = $schemaManager->createComparator()->compareTables($table, $newTable); + + $statements = $this->connection->getDatabasePlatform()->getAlterTableSQL($diff); + foreach ($statements as $statement) { + $this->connection->executeStatement($statement); + } + + $validationSchema = $schemaManager->introspectSchema(); + $validationTable = $validationSchema->getTable($table->getName()); + + $this->assertNull($validationTable->getPrimaryKey()); + } +} diff --git a/tests/Platforms/PostgreSQLPlatformTest.php b/tests/Platforms/PostgreSQLPlatformTest.php index 67b05904421..614eb45f8f7 100644 --- a/tests/Platforms/PostgreSQLPlatformTest.php +++ b/tests/Platforms/PostgreSQLPlatformTest.php @@ -593,6 +593,44 @@ public function testDroppingConstraintsBeforeColumns(): void self::assertEquals($expectedSql, $sql); } + public function testDroppingPrimaryKey(): void + { + $oldTable = new Table('mytable'); + $oldTable->addColumn('id', 'integer'); + $oldTable->setPrimaryKey(['id']); + + $newTable = clone $oldTable; + $newTable->dropPrimaryKey(); + + $diff = (new Comparator())->compareTables($oldTable, $newTable); + + $sql = $this->platform->getAlterTableSQL($diff); + + $expectedSql = ['ALTER TABLE mytable DROP CONSTRAINT mytable_pkey']; + + self::assertEquals($expectedSql, $sql); + } + + public function testDroppingPrimaryKeyWithUserDefinedName(): void + { + self::markTestSkipped('Edge case not covered yet'); + + $oldTable = new Table('mytable'); + $oldTable->addColumn('id', 'integer'); + $oldTable->setPrimaryKey(['id'], 'a_user_name'); + + $newTable = clone $oldTable; + $newTable->dropPrimaryKey(); + + $diff = (new Comparator())->compareTables($oldTable, $newTable); + + $sql = $this->platform->getAlterTableSQL($diff); + + $expectedSql = ['ALTER TABLE mytable DROP CONSTRAINT a_user_name']; + + self::assertEquals($expectedSql, $sql); + } + public function testUsesSequenceEmulatedIdentityColumns(): void { self::assertTrue($this->platform->usesSequenceEmulatedIdentityColumns());