Skip to content

Commit 85a8c8a

Browse files
author
DKravtsov
committed
Small improvements for uuid, updated docs and composer dependencies.
1 parent ec7d418 commit 85a8c8a

File tree

19 files changed

+160
-165
lines changed

19 files changed

+160
-165
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"Elasticsearch"
1515
],
1616
"homepage": "https://github.com/systemsdk/docker-symfony-api",
17-
"version": "v1.3.0",
17+
"version": "v1.3.1",
1818
"license": "MIT",
1919
"authors": [
2020
{

composer.lock

+45-43
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/packages/doctrine.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,5 @@ doctrine:
7777
datesub: DoctrineExtensions\Query\Mysql\DateSub
7878
now: DoctrineExtensions\Query\Mysql\Now
7979
string_functions:
80-
uuid_to_ouuid: App\General\Infrastructure\DQL\UuidToOuuid
81-
ouuid_to_uuid: App\General\Infrastructure\DQL\OuuidToUuid
80+
uuid_o_t_to_bin: App\General\Infrastructure\DQL\UuidOTToBin
81+
bin_to_uuid_o_t: App\General\Infrastructure\DQL\BinToUuidOT

docs/development.md

+5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ know anything about other layers (Application/Infrastructure) or framework. In t
3434
for such components like Doctrine/Swagger/Serializer/Validator (for the first time) and you can find such
3535
dependencies inside Entities.
3636

37+
Within this application we are using uuid v1 for the primary key inside Entities. Also we have id field as
38+
binary type ([details](https://uuid.ramsey.dev/en/stable/database.html#using-as-a-primary-key)). If you need to convert
39+
id into bin or from bin to string inside query, please use already existing dql functions `uuid_o_t_to_bin` and `bin_to_uuid_o_t`.
40+
For instance `... WHERE id = uuid_o_t_to_bin(:id)`, or when you need to convert uuid binary ordered time into string representative `... WHERE bin_to_uuid_o_t(id) = :id`.
41+
3742
#### Repositories
3843
Repositories need to be responsible for parameter handling and query builder callbacks/joins. Should be located on
3944
infrastructure layer. Parameter handling can help with generic REST queries.

docs/messenger.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ Once your messages have been routed, it will be consumed. In case any issue just
1313
### Message and Handler
1414
Before you can send a message, you must create it first. In order to do something when your message is dispatched, you need to create a message handler. Please follow docs in order to implement it:
1515

16-
* [Message](https://symfony.com/doc/current/messenger.html#message)
17-
* [Handler](https://symfony.com/doc/current/messenger.html#registering-handlers)
16+
* [Message](https://symfony.com/doc/current/messenger.html#creating-a-message-handler)
17+
* [Handler](https://symfony.com/doc/current/messenger.html#creating-a-message-handler)
1818

1919
## RabbitMQ Management HTTP API
2020
When activated, the management plugin provides an HTTP API at http://server-name:15672/api/ by default. Browse to that location for more information on the API. For convenience the same API reference is available from GitHub:

migrations/Version20211001194001.php

-30
Original file line numberDiff line numberDiff line change
@@ -274,33 +274,6 @@ public function up(Schema $schema): void
274274
$this->addSql('ALTER TABLE user_group ADD CONSTRAINT FK_8F02BF9D57698A6A FOREIGN KEY (role) REFERENCES role (role) ON DELETE CASCADE');
275275
$this->addSql('ALTER TABLE user_group ADD CONSTRAINT FK_8F02BF9DB03A8386 FOREIGN KEY (created_by_id) REFERENCES user (id) ON DELETE SET NULL');
276276
$this->addSql('ALTER TABLE user_group ADD CONSTRAINT FK_8F02BF9D896DBBDE FOREIGN KEY (updated_by_id) REFERENCES user (id) ON DELETE SET NULL');
277-
278-
$sqlFunctions = <<<SQL
279-
DROP FUNCTION IF EXISTS ouuid_to_uuid;
280-
CREATE
281-
FUNCTION ouuid_to_uuid(uuid BINARY(16))
282-
RETURNS VARCHAR(36) CHARSET utf8mb4 COLLATE utf8mb4_general_ci
283-
DETERMINISTIC
284-
RETURN LOWER(CONCAT(
285-
SUBSTR(HEX(uuid), 9, 8), '-',
286-
SUBSTR(HEX(uuid), 5, 4), '-',
287-
SUBSTR(HEX(uuid), 1, 4), '-',
288-
SUBSTR(HEX(uuid), 17,4), '-',
289-
SUBSTR(HEX(uuid), 21, 12 )
290-
));
291-
DROP FUNCTION IF EXISTS uuid_to_ouuid;
292-
CREATE
293-
FUNCTION uuid_to_ouuid(uuid BINARY(36))
294-
RETURNS binary(16) DETERMINISTIC
295-
RETURN UNHEX(CONCAT(
296-
SUBSTR(uuid, 15, 4),
297-
SUBSTR(uuid, 10, 4),
298-
SUBSTR(uuid, 1, 8),
299-
SUBSTR(uuid, 20, 4),
300-
SUBSTR(uuid, 25, 12)
301-
));
302-
SQL;
303-
$this->addSql($sqlFunctions);
304277
}
305278

306279
/**
@@ -345,8 +318,5 @@ public function down(Schema $schema): void
345318
$this->addSql('DROP TABLE user');
346319
$this->addSql('DROP TABLE user_has_user_group');
347320
$this->addSql('DROP TABLE user_group');
348-
349-
$this->addSql('DROP FUNCTION ouuid_to_uuid');
350-
$this->addSql('DROP FUNCTION uuid_to_ouuid');
351321
}
352322
}

src/General/Infrastructure/DQL/OuuidToUuid.php renamed to src/General/Infrastructure/DQL/BinToUuidOT.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
use Doctrine\ORM\Query\SqlWalker;
1212

1313
/**
14-
* Class OuuidToUuid
14+
* Class BinToUuidOT
1515
*
1616
* @package App\General
1717
*/
18-
class OuuidToUuid extends FunctionNode
18+
class BinToUuidOT extends FunctionNode
1919
{
2020
public mixed $value;
2121

@@ -32,6 +32,6 @@ public function parse(Parser $parser): void
3232

3333
public function getSql(SqlWalker $sqlWalker): string
3434
{
35-
return 'ouuid_to_uuid(' . $this->value->dispatch($sqlWalker) . ')';
35+
return 'BIN_TO_UUID(' . $this->value->dispatch($sqlWalker) . ', 1)';
3636
}
3737
}

0 commit comments

Comments
 (0)