From caf55ee7df850234e21c257fdc63d9be00e02a98 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 11 Jul 2018 15:25:48 -0700 Subject: [PATCH] Deprecated usage of DB-generated UUIDs --- UPGRADE.md | 8 ++++++++ docs/en/reference/sharding.rst | 18 ++++++++++-------- .../DBAL/Platforms/AbstractPlatform.php | 2 ++ .../DBAL/Platforms/DrizzlePlatform.php | 2 ++ lib/Doctrine/DBAL/Platforms/MySqlPlatform.php | 2 ++ lib/Doctrine/DBAL/Platforms/OraclePlatform.php | 2 ++ .../DBAL/Platforms/PostgreSqlPlatform.php | 2 ++ .../DBAL/Platforms/SQLAnywherePlatform.php | 2 ++ .../DBAL/Platforms/SQLServerPlatform.php | 3 ++- lib/Doctrine/DBAL/Platforms/SqlitePlatform.php | 2 ++ 10 files changed, 34 insertions(+), 9 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index dce497856fd..25e2747b67f 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,13 @@ # Upgrade to 2.8 +## Deprecated usage of DB-generated UUIDs + +The format of DB-generated UUIDs is inconsistent across supported platforms and therefore is not portable. Some of the platforms produce UUIDv1, some produce UUIDv4, some produce the values which are not even UUID. + +Unless UUIDs are used in stored procedures which DBAL doesn't support, there's no real benefit of DB-generated UUIDs comparing to the application-generated ones. + +Use a PHP library (e.g. [ramsey/uuid](https://packagist.org/packages/ramsey/uuid)) to generate UUIDs on the application side. + ## Deprecated usage of binary fields whose length exceeds the platform maximum - The usage of binary fields whose length exceeds the maximum field size on a given platform is deprecated. diff --git a/docs/en/reference/sharding.rst b/docs/en/reference/sharding.rst index c636a5ef126..0bade11ccbd 100644 --- a/docs/en/reference/sharding.rst +++ b/docs/en/reference/sharding.rst @@ -100,11 +100,15 @@ platforms: fetchColumn('SELECT ' . $conn->getDatabasePlatform()->getGuidExpression()); + $guid = Uuid::uuid1(); - $conn->insert("my_table", array("id" => $guid, "foo" => "bar")); + $conn->insert('my_table', [ + 'id' => $guid->toString(), + 'foo' => 'bar', + ]); In your application you should hide this details in Id-Generation services: @@ -113,15 +117,13 @@ In your application you should hide this details in Id-Generation services: conn->fetchColumn('SELECT ' . - $this->conn->getDatabasePlatform()->getGuidExpression() - ); + return Uuid::uuid1(); } } diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index 299de534ff7..a9dbebe48c0 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -686,6 +686,8 @@ public function getRegexpExpression() * @return string * * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * + * @deprecated Use application-generated UUIDs instead */ public function getGuidExpression() { diff --git a/lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php b/lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php index b56134d9556..d8a4d092019 100644 --- a/lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php @@ -621,6 +621,8 @@ public function getLocateExpression($str, $substr, $startPos = false) /** * {@inheritDoc} + * + * @deprecated Use application-generated UUIDs instead */ public function getGuidExpression() { diff --git a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php index e4b89e1686f..a16bfe79da0 100644 --- a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php @@ -99,6 +99,8 @@ public function getRegexpExpression() /** * {@inheritDoc} + * + * @deprecated Use application-generated UUIDs instead */ public function getGuidExpression() { diff --git a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php index bfd17198a5d..32b12a0bc1f 100644 --- a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php @@ -108,6 +108,8 @@ public function getLocateExpression($str, $substr, $startPos = false) /** * {@inheritDoc} + * + * @deprecated Use application-generated UUIDs instead */ public function getGuidExpression() { diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php index f84d23ad428..04d431caf3d 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php @@ -1016,6 +1016,8 @@ public function getTimeTypeDeclarationSQL(array $fieldDeclaration) /** * {@inheritDoc} + * + * @deprecated Use application-generated UUIDs instead */ public function getGuidExpression() { diff --git a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php index 98bc4689a9f..79a6e483ab9 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php @@ -690,6 +690,8 @@ public function getForUpdateSQL() /** * {@inheritdoc} + * + * @deprecated Use application-generated UUIDs instead */ public function getGuidExpression() { diff --git a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php index 89d80a07097..48cbcc6c1c8 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php @@ -39,7 +39,6 @@ use function implode; use function is_array; use function is_bool; -use function is_null; use function is_numeric; use function is_string; use function preg_match; @@ -1026,6 +1025,8 @@ public function getDropViewSQL($name) /** * {@inheritDoc} + * + * @deprecated Use application-generated UUIDs instead */ public function getGuidExpression() { diff --git a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php index a9e652bf010..3c99e0f0853 100644 --- a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php @@ -63,6 +63,8 @@ public function getRegexpExpression() /** * {@inheritDoc} + * + * @deprecated Use application-generated UUIDs instead */ public function getGuidExpression() {