Skip to content

Commit

Permalink
Merge branch 'doctrine:3.6.x' into postgres-unlogged-tables-doctrine#…
Browse files Browse the repository at this point in the history
  • Loading branch information
f-lombardo authored Jun 16, 2023
2 parents 3378413 + 19f0dec commit 83fd60c
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 26 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
6 changes: 3 additions & 3 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,9 @@ if (! $diff->isEmpty()) {
}
```

## Deprecated not passing `$fromColumn` to the `TableDiff` constructor.
## Deprecated not passing `$fromTable` to the `TableDiff` constructor.

Not passing `$fromColumn` to the `TableDiff` constructor has been deprecated.
Not passing `$fromTable` to the `TableDiff` constructor has been deprecated.

The `TableDiff::$name` property and the `TableDiff::getName()` method have been deprecated as well. In order to obtain
the name of the table that the diff describes, use `TableDiff::getOldTable()`.
Expand Down Expand Up @@ -1002,7 +1002,7 @@ deprecated in order to provide a more consistent API.

## Deprecated `Comparator::compare($fromSchema, $toSchema)`

The usage of `Comparator::compare($fromSchema, $toSchema)` is deprecated and
The usage of `Comparator::compare($fromSchema, $toSchema)` is deprecated and
replaced by `Comparator::compareSchemas($fromSchema, $toSchema)` in order to
clarify the purpose of the method.

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 @@ -809,6 +810,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
4 changes: 2 additions & 2 deletions src/Schema/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ public function getColumns()
*/
public function getForeignKeyColumns()
{
Deprecation::trigger(
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5731',
'%s is deprecated. Use getForeignKey() and ForeignKeyConstraint::getLocalColumns() instead.',
Expand Down Expand Up @@ -813,7 +813,7 @@ public function getPrimaryKey()
*/
public function getPrimaryKeyColumns()
{
Deprecation::trigger(
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5731',
'%s is deprecated. Use getPrimaryKey() and Index::getColumns() instead.',
Expand Down
4 changes: 2 additions & 2 deletions src/Schema/TableDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ public function __construct(
$this->changedForeignKeys = $changedForeignKeys;
$this->removedForeignKeys = $removedForeignKeys;

if ($fromTable !== null) {
if ($fromTable === null) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5678',
'Not passing the $fromColumn to %s is deprecated.',
'Not passing the $fromTable to %s is deprecated.',
__METHOD__,
);
}
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
24 changes: 24 additions & 0 deletions tests/Schema/TableDiffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
use Doctrine\DBAL\Schema\Identifier;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class TableDiffTest extends TestCase
{
use VerifyDeprecations;

/** @var AbstractPlatform&MockObject */
private AbstractPlatform $platform;

Expand Down Expand Up @@ -53,4 +56,25 @@ public function testReturnsNewName(): void

self::assertEquals(new Identifier('bar'), $tableDiff->getNewName());
}

public function testOmittingFromTableInConstructorIsDeprecated(): void
{
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/dbal/pull/5678');
$tableDiff = new TableDiff('foo');
}

public function testPassingFromTableToConstructorIsDeprecated(): void
{
$this->expectNoDeprecationWithIdentifier('https://github.com/doctrine/dbal/pull/5678');
$tableDiff = new TableDiff(
'foo',
[],
[],
[],
[],
[],
[],
new Table('foo'),
);
}
}

0 comments on commit 83fd60c

Please sign in to comment.