Skip to content

Commit

Permalink
Merge pull request #3212 from morozov/bpo/2.8/3167
Browse files Browse the repository at this point in the history
Deprecated usage of DB-generated UUIDs
  • Loading branch information
morozov authored Jul 12, 2018
2 parents d475ade + caf55ee commit 3e2bee7
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 9 deletions.
8 changes: 8 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
18 changes: 10 additions & 8 deletions docs/en/reference/sharding.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,15 @@ platforms:
<?php
use Doctrine\DBAL\DriverManager;
use Ramsey\Uuid\Uuid;
$conn = DriverManager::getConnection(/**..**/);
$guid = $conn->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:

Expand All @@ -113,15 +117,13 @@ In your application you should hide this details in Id-Generation services:
<?php
namespace MyApplication;
use Ramsey\Uuid\Uuid;
class IdGenerationService
{
private $conn;
public function generateCustomerId()
public function generateCustomerId() : Uuid
{
return $this->conn->fetchColumn('SELECT ' .
$this->conn->getDatabasePlatform()->getGuidExpression()
);
return Uuid::uuid1();
}
}
Expand Down
2 changes: 2 additions & 0 deletions lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
2 changes: 2 additions & 0 deletions lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,8 @@ public function getLocateExpression($str, $substr, $startPos = false)

/**
* {@inheritDoc}
*
* @deprecated Use application-generated UUIDs instead
*/
public function getGuidExpression()
{
Expand Down
2 changes: 2 additions & 0 deletions lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public function getRegexpExpression()

/**
* {@inheritDoc}
*
* @deprecated Use application-generated UUIDs instead
*/
public function getGuidExpression()
{
Expand Down
2 changes: 2 additions & 0 deletions lib/Doctrine/DBAL/Platforms/OraclePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ public function getLocateExpression($str, $substr, $startPos = false)

/**
* {@inheritDoc}
*
* @deprecated Use application-generated UUIDs instead
*/
public function getGuidExpression()
{
Expand Down
2 changes: 2 additions & 0 deletions lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,8 @@ public function getTimeTypeDeclarationSQL(array $fieldDeclaration)

/**
* {@inheritDoc}
*
* @deprecated Use application-generated UUIDs instead
*/
public function getGuidExpression()
{
Expand Down
2 changes: 2 additions & 0 deletions lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,8 @@ public function getForUpdateSQL()

/**
* {@inheritdoc}
*
* @deprecated Use application-generated UUIDs instead
*/
public function getGuidExpression()
{
Expand Down
3 changes: 2 additions & 1 deletion lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1026,6 +1025,8 @@ public function getDropViewSQL($name)

/**
* {@inheritDoc}
*
* @deprecated Use application-generated UUIDs instead
*/
public function getGuidExpression()
{
Expand Down
2 changes: 2 additions & 0 deletions lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public function getRegexpExpression()

/**
* {@inheritDoc}
*
* @deprecated Use application-generated UUIDs instead
*/
public function getGuidExpression()
{
Expand Down

0 comments on commit 3e2bee7

Please sign in to comment.