diff --git a/UPGRADE.md b/UPGRADE.md index 1db52439499..e3e6d8ec431 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -16,9 +16,11 @@ Because of that, it is now deprecated to rely on the historical defaults when they differ from what we recommend now. Instead, you should pick a strategy for each database platform you use, and it -will be used when using `AUTO`. As of now, only PostgreSQL is affected by this. -It is recommended that PostgreSQL user configure their new applications to use -`IDENTITY`: +will be used when using `AUTO`. As of now, no platform is affected by this, but +PostgreSQL will be when `doctrine/dbal` 4 is released. + +It is recommended that PostgreSQL users configure their existing and new +applications to use `SEQUENCE` until that happens: ```php use Doctrine\DBAL\Platforms\PostgreSQLPlatform; @@ -26,13 +28,10 @@ use Doctrine\ORM\Configuration; assert($configuration instanceof Configuration); $configuration->setIdentityGenerationPreferences([ - PostgreSQLPlatform::CLASS => ClassMetadata::GENERATOR_TYPE_IDENTITY, + PostgreSQLPlatform::CLASS => ClassMetadata::GENERATOR_TYPE_SEQUENCE, ]); ``` -If migrating an existing application is too costly, the deprecation can be -addressed by configuring `SEQUENCE` as the default strategy. - ## Deprecate `EntityManagerInterface::getPartialReference()` This method does not have a replacement and will be removed in 3.0. diff --git a/docs/en/reference/basic-mapping.rst b/docs/en/reference/basic-mapping.rst index 3bc4b5d33fe..66b552a1d87 100644 --- a/docs/en/reference/basic-mapping.rst +++ b/docs/en/reference/basic-mapping.rst @@ -427,20 +427,6 @@ defaults to the identifier generation mechanism your current database vendor preferred at the time that strategy was introduced: ``AUTO_INCREMENT`` with MySQL, sequences with PostgreSQL and Oracle and so on. -We now recommend using ``IDENTITY`` for PostgreSQL, and you can achieve -that while still using the ``AUTO`` strategy, by configuring what it -defaults to. - -.. code-block:: php - - setIdentityGenerationPreferences([ - PostgreSQLPlatform::class => ClassMetadata::GENERATOR_TYPE_IDENTITY, - ]); .. _identifier-generation-strategies: diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 2ad71382e85..91e528a7410 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -87,11 +87,11 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory private const RECOMMENDED_STRATEGY = [ 'Doctrine\DBAL\Platforms\MySqlPlatform' => 'IDENTITY', - 'Doctrine\DBAL\Platforms\PostgreSqlPlatform' => 'IDENTITY', + 'Doctrine\DBAL\Platforms\PostgreSqlPlatform' => 'SEQUENCE', Platforms\DB2Platform::class => 'IDENTITY', Platforms\MySQLPlatform::class => 'IDENTITY', Platforms\OraclePlatform::class => 'SEQUENCE', - Platforms\PostgreSQLPlatform::class => 'IDENTITY', + Platforms\PostgreSQLPlatform::class => 'SEQUENCE', Platforms\SQLServerPlatform::class => 'IDENTITY', Platforms\SqlitePlatform::class => 'IDENTITY', ]; @@ -657,7 +657,7 @@ private function completeIdGeneratorMapping(ClassMetadataInfo $class): void 'https://github.com/doctrine/orm/issues/8850', <<<'DEPRECATION' Context: Loading metadata for class %s -Problem: Using the IDENTITY generator strategy with platform "%s" is deprecated and will not be possible in Doctrine ORM 3.0. +Problem: Using identity columns emulated with a sequence is deprecated and will not be possible in Doctrine ORM 3.0. Solution: Use the SEQUENCE generator strategy instead. DEPRECATION , diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php index eae9e871192..3257eea59f2 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php @@ -10,7 +10,6 @@ use Doctrine\DBAL\Driver; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\OraclePlatform; -use Doctrine\DBAL\Platforms\PostgreSQLPlatform; use Doctrine\Deprecations\PHPUnit\VerifyDeprecations; use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManagerInterface; @@ -170,32 +169,6 @@ private function setUpCmfForPlatform(AbstractPlatform $platform, array $preferen return $cmf; } - public function testRelyingOnLegacyIdGenerationDefaultsIsDeprecatedIfItResultsInASuboptimalDefault(): void - { - $cm = $this->createValidClassMetadata(); - $cm->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_AUTO); - - $cmf = $this->setUpCmfForPlatform(new PostgreSQLPlatform()); - $cmf->setMetadataForClass($cm->name, $cm); - - $this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/issues/8893'); - $cmf->getMetadataFor($cm->name); - } - - public function testSpecifyingIdGenerationStrategyThroughConfigurationFixesTheDeprecation(): void - { - $cm = $this->createValidClassMetadata(); - $cm->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_AUTO); - - $cmf = $this->setUpCmfForPlatform(new PostgreSQLPlatform(), [ - PostgreSQLPlatform::class => ClassMetadata::GENERATOR_TYPE_IDENTITY, - ]); - $cmf->setMetadataForClass($cm->name, $cm); - - $this->expectNoDeprecationWithIdentifier('https://github.com/doctrine/orm/issues/8893'); - $cmf->getMetadataFor($cm->name); - } - public function testRelyingOnLegacyIdGenerationDefaultsIsOKIfItResultsInTheCurrentlyRecommendedStrategyBeingUsed(): void { $cm = $this->createValidClassMetadata();