From 862a09324cf97ee1b79a5b0d8ccbf9b16f1ea2e7 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Tue, 10 Jul 2018 23:27:01 -0700 Subject: [PATCH] Removed support for DB-generated UUIDs --- UPGRADE.md | 5 ++ .../DBAL/Platforms/AbstractPlatform.php | 14 ----- lib/Doctrine/DBAL/Platforms/MySqlPlatform.php | 10 ---- .../DBAL/Platforms/OraclePlatform.php | 10 ---- .../DBAL/Platforms/PostgreSqlPlatform.php | 10 ---- .../DBAL/Platforms/SQLAnywherePlatform.php | 10 ---- .../DBAL/Platforms/SQLServerPlatform.php | 10 ---- .../DBAL/Platforms/SqlitePlatform.php | 13 ----- .../DBAL/Functional/Ticket/DBAL421Test.php | 56 ------------------- .../Platforms/SQLAnywherePlatformTest.php | 1 - 10 files changed, 5 insertions(+), 134 deletions(-) delete mode 100644 tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL421Test.php diff --git a/UPGRADE.md b/UPGRADE.md index d55f935cc3d..4d3e9799e32 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,10 @@ # Upgrade to 3.0 +## BC BREAK: Removed support for DB-generated UUIDs + +The support for DB-generated UUIDs was removed as non-portable. +Please generate UUIDs on the application side (e.g. using [ramsey/uuid](https://packagist.org/packages/ramsey/uuid)). + ## BC BREAK: Removed MsSQLKeywords class The `Doctrine\DBAL\Platforms\MsSQLKeywords` has been removed. diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index f25570e8d2b..df24308f129 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -618,20 +618,6 @@ public function getRegexpExpression() throw DBALException::notSupported(__METHOD__); } - /** - * Returns the global unique identifier expression. - * - * @deprecated Use application-generated UUIDs instead - * - * @return string - * - * @throws DBALException If not supported on this platform. - */ - public function getGuidExpression() - { - throw DBALException::notSupported(__METHOD__); - } - /** * Returns the SQL snippet to get the average value of a column. * diff --git a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php index 5aba04c9ccb..da54b9fa935 100644 --- a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php @@ -79,16 +79,6 @@ public function getRegexpExpression() return 'RLIKE'; } - /** - * {@inheritDoc} - * - * @deprecated Use application-generated UUIDs instead - */ - public function getGuidExpression() - { - return 'UUID()'; - } - /** * {@inheritDoc} */ diff --git a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php index c54a14d66d3..b616e51b2e2 100644 --- a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php @@ -86,16 +86,6 @@ public function getLocateExpression($str, $substr, $startPos = false) return 'INSTR(' . $str . ', ' . $substr . ', ' . $startPos . ')'; } - /** - * {@inheritDoc} - * - * @deprecated Use application-generated UUIDs instead - */ - public function getGuidExpression() - { - return 'SYS_GUID()'; - } - /** * {@inheritdoc} */ diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php index 6fe0bc5be94..a5aa097596a 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php @@ -1013,16 +1013,6 @@ public function getTimeTypeDeclarationSQL(array $fieldDeclaration) return 'TIME(0) WITHOUT TIME ZONE'; } - /** - * {@inheritDoc} - * - * @deprecated Use application-generated UUIDs instead - */ - public function getGuidExpression() - { - return 'UUID_GENERATE_V4()'; - } - /** * {@inheritDoc} */ diff --git a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php index a15bed9719f..c11636497d1 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php @@ -667,16 +667,6 @@ public function getForUpdateSQL() return ''; } - /** - * {@inheritdoc} - * - * @deprecated Use application-generated UUIDs instead - */ - public function getGuidExpression() - { - return 'NEWID()'; - } - /** * {@inheritdoc} */ diff --git a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php index 2991900ac32..113513f1b17 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php @@ -1002,16 +1002,6 @@ public function getDropViewSQL($name) return 'DROP VIEW ' . $name; } - /** - * {@inheritDoc} - * - * @deprecated Use application-generated UUIDs instead - */ - public function getGuidExpression() - { - return 'NEWID()'; - } - /** * {@inheritDoc} */ diff --git a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php index 70481d524aa..ccb9284fa79 100644 --- a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php @@ -40,19 +40,6 @@ public function getRegexpExpression() return 'REGEXP'; } - /** - * {@inheritDoc} - * - * @deprecated Use application-generated UUIDs instead - */ - public function getGuidExpression() - { - return "HEX(RANDOMBLOB(4)) || '-' || HEX(RANDOMBLOB(2)) || '-4' || " - . "SUBSTR(HEX(RANDOMBLOB(2)), 2) || '-' || " - . "SUBSTR('89AB', 1 + (ABS(RANDOM()) % 4), 1) || " - . "SUBSTR(HEX(RANDOMBLOB(2)), 2) || '-' || HEX(RANDOMBLOB(6))"; - } - /** * {@inheritDoc} */ diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL421Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL421Test.php deleted file mode 100644 index af41670690a..00000000000 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL421Test.php +++ /dev/null @@ -1,56 +0,0 @@ -connection->getDatabasePlatform()->getName(); - if (in_array($platform, ['mysql', 'sqlite'])) { - return; - } - - $this->markTestSkipped('Currently restricted to MySQL and SQLite.'); - } - - public function testGuidShouldMatchPattern() - { - $guid = $this->connection->query($this->getSelectGuidSql())->fetchColumn(); - $pattern = '/[0-9A-F]{8}\-[0-9A-F]{4}\-[0-9A-F]{4}\-[8-9A-B][0-9A-F]{3}\-[0-9A-F]{12}/i'; - self::assertEquals(1, preg_match($pattern, $guid), 'GUID does not match pattern'); - } - - /** - * This test does (of course) not proof that all generated GUIDs are - * random, it should however provide some basic confidence. - */ - public function testGuidShouldBeRandom() - { - $statement = $this->connection->prepare($this->getSelectGuidSql()); - $guids = []; - - for ($i = 0; $i < 99; $i++) { - $statement->execute(); - $guid = $statement->fetchColumn(); - self::assertNotContains($guid, $guids, 'Duplicate GUID detected'); - $guids[] = $guid; - } - - $statement->closeCursor(); - } - - private function getSelectGuidSql() - { - return 'SELECT ' . $this->connection->getDatabasePlatform()->getGuidExpression(); - } -} diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php index b334f35d25f..1f0cf18b965 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php @@ -635,7 +635,6 @@ public function testGeneratesSQLSnippets() self::assertEquals('Y-m-d H:i:s.u', $this->platform->getDateTimeFormatString()); self::assertEquals('H:i:s.u', $this->platform->getTimeFormatString()); self::assertEquals('', $this->platform->getForUpdateSQL()); - self::assertEquals('NEWID()', $this->platform->getGuidExpression()); self::assertEquals('LOCATE(string_column, substring_column)', $this->platform->getLocateExpression('string_column', 'substring_column')); self::assertEquals('LOCATE(string_column, substring_column, 1)', $this->platform->getLocateExpression('string_column', 'substring_column', 1)); self::assertEquals("HASH(column, 'MD5')", $this->platform->getMd5Expression('column'));