Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecated usage of DB-generated UUIDs #3212

Merged
merged 1 commit into from
Jul 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest the UUID PECL instead.
It less invasive and the code is much more simple.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean it's less invasive?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got intrigued with the "less invasive" too 😄 but DBAL would simply handle a string so it doesn't really matter which lib/extension is being used.

I'd still recommend @ramsey's lib, though. It's better documented (IMO) and supports all UUID versions (even the namespaced ones)...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also don't understand the less invasive part.
The referenced PECL extension requires setup by server admin, has no documentation on php.net, is unix-only and has last release in 2015.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has not been updated because it does not need to be. It just works.

About less invasive, i may be unclear. Sorry. I don't like the PHP lib because there is so many code for a really simple thing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applies also to core libs: 90%+ of the code is just to emulate userland behaviour. If you can avoid an extension for doing something that can be done in userland, then do avoid it.


## 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