Removed support for DB-generated UUIDs

parent 13bef8a5
# 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: Changes in the `Doctrine\DBAL\Connection` API
- The following methods have been removed as leaking internal implementation details: `::getHost()`, `::getPort()`, `::getUsername()`, `::getPassword()`.
......
......@@ -583,20 +583,6 @@ abstract class AbstractPlatform
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.
*
......
......@@ -79,16 +79,6 @@ class MySqlPlatform extends AbstractPlatform
return 'RLIKE';
}
/**
* {@inheritDoc}
*
* @deprecated Use application-generated UUIDs instead
*/
public function getGuidExpression()
{
return 'UUID()';
}
/**
* {@inheritDoc}
*/
......
......@@ -89,16 +89,6 @@ class OraclePlatform extends AbstractPlatform
return 'INSTR(' . $str . ', ' . $substr . ', ' . $startPos . ')';
}
/**
* {@inheritDoc}
*
* @deprecated Use application-generated UUIDs instead
*/
public function getGuidExpression()
{
return 'SYS_GUID()';
}
/**
* {@inheritdoc}
*/
......
......@@ -1030,16 +1030,6 @@ SQL
return 'TIME(0) WITHOUT TIME ZONE';
}
/**
* {@inheritDoc}
*
* @deprecated Use application-generated UUIDs instead
*/
public function getGuidExpression()
{
return 'UUID_GENERATE_V4()';
}
/**
* {@inheritDoc}
*/
......
......@@ -1083,16 +1083,6 @@ SQL
return 'DROP VIEW ' . $name;
}
/**
* {@inheritDoc}
*
* @deprecated Use application-generated UUIDs instead
*/
public function getGuidExpression()
{
return 'NEWID()';
}
/**
* {@inheritDoc}
*/
......
......@@ -41,19 +41,6 @@ class SqlitePlatform extends AbstractPlatform
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))";
}
/**
* @param string $type
*
......
<?php
namespace Doctrine\DBAL\Tests\Functional\Ticket;
use Doctrine\DBAL\Tests\FunctionalTestCase;
use function in_array;
use function preg_match;
/**
* @group DBAL-421
*/
class DBAL421Test extends FunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();
$platform = $this->connection->getDatabasePlatform()->getName();
if (in_array($platform, ['mysql', 'sqlite'])) {
return;
}
$this->markTestSkipped('Currently restricted to MySQL and SQLite.');
}
public function testGuidShouldMatchPattern(): void
{
$guid = $this->connection->query($this->getSelectGuidSql())->fetchOne();
$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(): void
{
$statement = $this->connection->prepare($this->getSelectGuidSql());
$guids = [];
for ($i = 0; $i < 99; $i++) {
$guid = $statement->execute()->fetchFirstColumn();
self::assertNotContains($guid, $guids, 'Duplicate GUID detected');
$guids[] = $guid;
}
}
private function getSelectGuidSql(): string
{
return 'SELECT ' . $this->connection->getDatabasePlatform()->getGuidExpression();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment