Skip to content

Commit 783631b

Browse files
committed
use uuid1 plus time ordered codec.
1 parent a376235 commit 783631b

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

pkg/dbal/DbalContext.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,7 @@ public function createDataBaseTable()
173173

174174
$table = new Table($this->getTableName());
175175

176-
if ($this->getDbalConnection()->getDatabasePlatform()->hasNativeGuidType()) {
177-
$table->addColumn('id', 'guid');
178-
} else {
179-
$table->addColumn('id', Type::BINARY, ['length' => 16]);
180-
}
181-
176+
$table->addColumn('id', Type::BINARY, ['length' => 16, 'fixed' => true]);
182177
$table->addColumn('human_id', Type::STRING, ['length' => 36]);
183178
$table->addColumn('published_at', Type::BIGINT);
184179
$table->addColumn('body', Type::TEXT, ['notnull' => false]);

pkg/dbal/DbalProducer.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
use Interop\Queue\PsrDestination;
1111
use Interop\Queue\PsrMessage;
1212
use Interop\Queue\PsrProducer;
13+
use Ramsey\Uuid\Codec\OrderedTimeCodec;
1314
use Ramsey\Uuid\Uuid;
15+
use Ramsey\Uuid\UuidFactory;
1416

1517
class DbalProducer implements PsrProducer
1618
{
@@ -34,12 +36,18 @@ class DbalProducer implements PsrProducer
3436
*/
3537
private $context;
3638

39+
/**
40+
* @var OrderedTimeCodec
41+
*/
42+
private $uuidCodec;
43+
3744
/**
3845
* @param DbalContext $context
3946
*/
4047
public function __construct(DbalContext $context)
4148
{
4249
$this->context = $context;
50+
$this->uuidCodec = new OrderedTimeCodec((new UuidFactory())->getUuidBuilder());
4351
}
4452

4553
/**
@@ -75,11 +83,10 @@ public function send(PsrDestination $destination, PsrMessage $message)
7583
));
7684
}
7785

78-
$hasNativeGuid = $this->context->getDbalConnection()->getDatabasePlatform()->hasNativeGuidType();
79-
$uuid = Uuid::uuid4();
86+
$uuid = Uuid::uuid1();
8087

8188
$dbalMessage = [
82-
'id' => $hasNativeGuid ? $uuid->toString() : $uuid->getBytes(),
89+
'id' => $this->uuidCodec->encodeBinary($uuid),
8390
'human_id' => $uuid->toString(),
8491
'published_at' => (int) microtime(true) * 10000,
8592
'body' => $body,

0 commit comments

Comments
 (0)