Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f4b4ad9

Browse files
committed
Deprecated usage of DB-generated UUIDs
1 parent 29f1799 commit f4b4ad9

11 files changed

Lines changed: 39 additions & 8 deletions

File tree

UPGRADE.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Upgrade to 2.8
22

3+
## Deprecated usage of DB-generated UUIDs
4+
5+
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.
6+
7+
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.
8+
9+
Use a PHP library (e.g. [ramsey/uuid](https://packagist.org/packages/ramsey/uuid)) to generate UUIDs on the application side.
10+
311
## Deprecated usage of binary fields whose length exceeds the platform maximum
412

513
- The usage of binary fields whose length exceeds the maximum field size on a given platform is deprecated.

docs/en/reference/sharding.rst

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,15 @@ platforms:
100100
101101
<?php
102102
use Doctrine\DBAL\DriverManager;
103+
use Ramsey\Uuid\Uuid;
103104
104105
$conn = DriverManager::getConnection(/**..**/);
105-
$guid = $conn->fetchColumn('SELECT ' . $conn->getDatabasePlatform()->getGuidExpression());
106+
$guid = Uuid::uuid1();
106107
107-
$conn->insert("my_table", array("id" => $guid, "foo" => "bar"));
108+
$conn->insert('my_table', [
109+
'id' => $guid->toString(),
110+
'foo' => 'bar',
111+
]);
108112
109113
In your application you should hide this details in Id-Generation services:
110114

@@ -113,15 +117,13 @@ In your application you should hide this details in Id-Generation services:
113117
<?php
114118
namespace MyApplication;
115119
120+
use Ramsey\Uuid\Uuid;
121+
116122
class IdGenerationService
117123
{
118-
private $conn;
119-
120-
public function generateCustomerId()
124+
public function generateCustomerId() : Uuid
121125
{
122-
return $this->conn->fetchColumn('SELECT ' .
123-
$this->conn->getDatabasePlatform()->getGuidExpression()
124-
);
126+
return Uuid::uuid1();
125127
}
126128
}
127129

lib/Doctrine/DBAL/Platforms/AbstractPlatform.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,8 @@ public function getRegexpExpression()
686686
* @return string
687687
*
688688
* @throws \Doctrine\DBAL\DBALException If not supported on this platform.
689+
*
690+
* @deprecated Use application-generated UUIDs instead
689691
*/
690692
public function getGuidExpression()
691693
{

lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,8 @@ public function getLocateExpression($str, $substr, $startPos = false)
621621

622622
/**
623623
* {@inheritDoc}
624+
*
625+
* @deprecated Use application-generated UUIDs instead
624626
*/
625627
public function getGuidExpression()
626628
{

lib/Doctrine/DBAL/Platforms/MySqlPlatform.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ public function getRegexpExpression()
9999

100100
/**
101101
* {@inheritDoc}
102+
*
103+
* @deprecated Use application-generated UUIDs instead
102104
*/
103105
public function getGuidExpression()
104106
{

lib/Doctrine/DBAL/Platforms/OraclePlatform.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ public function getLocateExpression($str, $substr, $startPos = false)
108108

109109
/**
110110
* {@inheritDoc}
111+
*
112+
* @deprecated Use application-generated UUIDs instead
111113
*/
112114
public function getGuidExpression()
113115
{

lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,8 @@ public function getTimeTypeDeclarationSQL(array $fieldDeclaration)
10161016

10171017
/**
10181018
* {@inheritDoc}
1019+
*
1020+
* @deprecated Use application-generated UUIDs instead
10191021
*/
10201022
public function getGuidExpression()
10211023
{

lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,8 @@ public function getForUpdateSQL()
690690

691691
/**
692692
* {@inheritdoc}
693+
*
694+
* @deprecated Use application-generated UUIDs instead
693695
*/
694696
public function getGuidExpression()
695697
{

lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,8 @@ public function getDropViewSQL($name)
10261026

10271027
/**
10281028
* {@inheritDoc}
1029+
*
1030+
* @deprecated Use application-generated UUIDs instead
10291031
*/
10301032
public function getGuidExpression()
10311033
{

lib/Doctrine/DBAL/Platforms/SqlitePlatform.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ public function getRegexpExpression()
6363

6464
/**
6565
* {@inheritDoc}
66+
*
67+
* @deprecated Use application-generated UUIDs instead
6668
*/
6769
public function getGuidExpression()
6870
{

0 commit comments

Comments
 (0)