Skip to content

Commit

Permalink
Merge pull request #5119 from morozov/deprecate-prefers-identity-columns
Browse files Browse the repository at this point in the history
Deprecate AbstractPlatform::prefersIdentityColumns()
  • Loading branch information
morozov authored Dec 15, 2021
2 parents 5f28b74 + 058c448 commit 9247a4c
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 1 deletion.
5 changes: 5 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ Relying on the name of the platform is discouraged. To identify the platform, us
The `ServerInfoAwareConnection` and `VersionAwarePlatformDriver` interfaces are deprecated. In the next major version,
all drivers and driver connections will be required to implement the APIs aware of the server version.

## Deprecated `AbstractPlatform::prefersIdentityColumns()`.

Whether to use identity columns should be decided by the application developer. For example, based on the set
of supported database platforms.

## Deprecated `AbstractPlatform::getNowExpression()`.

Relying on dates generated by the database is deprecated. Generate dates within the application.
Expand Down
9 changes: 9 additions & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,15 @@
See https://github.com/doctrine/dbal/pull/4966
-->
<referencedMethod name="Doctrine\DBAL\Connection::getWrappedConnection"/>
<!--
TODO: remove in 4.0.0
See https://github.com/doctrine/dbal/pull/1519
-->
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractMySQLPlatform::prefersIdentityColumns"/>
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractPlatform::prefersIdentityColumns"/>
<referencedMethod name="Doctrine\DBAL\Platforms\DB2Platform::prefersIdentityColumns"/>
<referencedMethod name="Doctrine\DBAL\Platforms\SQLServerPlatform::prefersIdentityColumns"/>
<referencedMethod name="Doctrine\DBAL\Platforms\SqlitePlatform::prefersIdentityColumns"/>
</errorLevel>
</DeprecatedMethod>
<DeprecatedProperty>
Expand Down
8 changes: 8 additions & 0 deletions src/Platforms/AbstractMySQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,19 @@ public function getBooleanTypeDeclarationSQL(array $column)
/**
* {@inheritDoc}
*
* @deprecated
*
* MySQL prefers "autoincrement" identity columns since sequences can only
* be emulated with a table.
*/
public function prefersIdentityColumns()
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pulls/1519',
'AbstractMySQLPlatform::prefersIdentityColumns() is deprecated.'
);

return true;
}

Expand Down
8 changes: 8 additions & 0 deletions src/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -2914,10 +2914,18 @@ public function getColumnCollationDeclarationSQL($collation)
* Whether the platform prefers identity columns (eg. autoincrement) for ID generation.
* Subclasses should override this method to return TRUE if they prefer identity columns.
*
* @deprecated
*
* @return bool
*/
public function prefersIdentityColumns()
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pulls/1519',
'AbstractPlatform::prefersIdentityColumns() is deprecated.'
);

return false;
}

Expand Down
8 changes: 8 additions & 0 deletions src/Platforms/DB2Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -847,9 +847,17 @@ public function supportsIdentityColumns()

/**
* {@inheritDoc}
*
* @deprecated
*/
public function prefersIdentityColumns()
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pulls/1519',
'DB2Platform::prefersIdentityColumns() is deprecated.'
);

return true;
}

Expand Down
8 changes: 8 additions & 0 deletions src/Platforms/SQLServerPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,17 @@ public function getDateDiffExpression($date1, $date2)
*
* Microsoft SQL Server prefers "autoincrement" identity columns
* since sequences can only be emulated with a table.
*
* @deprecated
*/
public function prefersIdentityColumns()
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pulls/1519',
'SQLServerPlatform::prefersIdentityColumns() is deprecated.'
);

return true;
}

Expand Down
8 changes: 8 additions & 0 deletions src/Platforms/SqlitePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,17 @@ public function getSetTransactionIsolationSQL($level)

/**
* {@inheritDoc}
*
* @deprecated
*/
public function prefersIdentityColumns()
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pulls/1519',
'SqlitePlatform::prefersIdentityColumns() is deprecated.'
);

return true;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/WriteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function testUpdate(): void

public function testLastInsertId(): void
{
if (! $this->connection->getDatabasePlatform()->prefersIdentityColumns()) {
if (! $this->connection->getDatabasePlatform()->supportsIdentityColumns()) {
self::markTestSkipped('Test only works on platforms with identity columns.');
}

Expand Down

0 comments on commit 9247a4c

Please sign in to comment.