Skip to content

Commit

Permalink
Merge branch '3.6.x' into 3.7.x
Browse files Browse the repository at this point in the history
* 3.6.x:
  Fix incorrect syntax for dropping primary indexes in PostgreSQL (doctrine#6025)
  trigger if called outside for AbstractPlatform::supportsCreateDropDatabase (doctrine#6064)
  Run tests with PHP 8.3 (doctrine#6060)
  • Loading branch information
derrabus committed Jun 15, 2023
2 parents e9b3de4 + 19f0dec commit d722992
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 19 deletions.
38 changes: 20 additions & 18 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
- "8.0"
- "8.1"
- "8.2"
- "8.3"
dependencies:
- "highest"
extension:
Expand Down Expand Up @@ -106,8 +107,8 @@ jobs:
matrix:
php-version:
- "7.4"
- "8.1"
- "8.2"
- "8.3"
oracle-version:
- "21"
include:
Expand Down Expand Up @@ -164,8 +165,8 @@ jobs:
matrix:
php-version:
- "7.4"
- "8.1"
- "8.2"
- "8.3"
oracle-version:
- "21"
include:
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -371,7 +372,7 @@ jobs:
matrix:
php-version:
- "7.4"
- "8.0"
- "8.1"
mysql-version:
- "5.7"
- "8.0"
Expand All @@ -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"

Expand Down Expand Up @@ -461,8 +462,8 @@ jobs:
matrix:
php-version:
- "7.4"
- "8.1"
- "8.2"
- "8.3"
extension:
- "sqlsrv"
- "pdo_sqlsrv"
Expand Down Expand Up @@ -529,6 +530,7 @@ jobs:
php-version:
- "7.4"
- "8.2"
- "8.3"

services:
ibm_db2:
Expand Down
2 changes: 1 addition & 1 deletion src/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down
31 changes: 31 additions & 0 deletions src/Platforms/PostgreSQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}
*/
Expand Down
43 changes: 43 additions & 0 deletions tests/Functional/Driver/DBAL6024Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Doctrine\DBAL\Tests\Functional\Driver;

use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Tests\FunctionalTestCase;
use Doctrine\DBAL\Tests\TestUtil;

class DBAL6024Test extends FunctionalTestCase
{
protected function setUp(): void
{
if (TestUtil::isDriverOneOf('pdo_pgsql', 'pgsql')) {
return;
}

self::markTestSkipped('This test requires the pdo_pgsql or the pgsql driver.');
}

public function testDropPrimaryKey(): void
{
$table = new Table('mytable');
$table->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());
}
}
38 changes: 38 additions & 0 deletions tests/Platforms/PostgreSQLPlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit d722992

Please sign in to comment.