Skip to content

Commit 409722e

Browse files
committed
Upgrade to domainTag
1 parent b29bfd1 commit 409722e

File tree

9 files changed

+26
-26
lines changed

9 files changed

+26
-26
lines changed

resources/migrations/doctrine/Version20241009183226.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ public function up(Schema $schema): void
2727
<<<'SQL'
2828
CREATE TABLE `event_store_relation` (
2929
`event_id` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
30-
`domain_id` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
31-
PRIMARY KEY (`event_id`,`domain_id`),
30+
`domain_tag` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
31+
PRIMARY KEY (`event_id`,`domain_tag`),
3232
CONSTRAINT `event_store_relation_ibfk_1` FOREIGN KEY (`event_id`) REFERENCES `event_store` (`id`)
3333
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3434
SQL

resources/migrations/phinx/20241210194054.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ final class V20241210194054 extends AbstractMigration
88
{
99
public function change(): void
1010
{
11-
$this->table('event_store_relation', ['id' => false, 'primary_key' => ['event_id', 'domain_id']])
11+
$this->table('event_store_relation', ['id' => false, 'primary_key' => ['event_id', 'domain_tag']])
1212
->addColumn('event_id', 'string', ['limit' => 50, 'null' => false])
13-
->addColumn('domain_id', 'string', ['limit' => 50, 'null' => false])
13+
->addColumn('domain_tag', 'string', ['limit' => 50, 'null' => false])
1414
->addForeignKey('event_id', 'event_store', 'id')
1515
->create();
1616
}

resources/schema.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ CREATE TABLE `event_store` (
1010

1111
CREATE TABLE `event_store_relation` (
1212
`event_id` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
13-
`domain_id` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
14-
PRIMARY KEY (`event_id`,`domain_id`),
13+
`domain_tag` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
14+
PRIMARY KEY (`event_id`,`domain_tag`),
1515
CONSTRAINT `event_store_relation_ibfk_1` FOREIGN KEY (`event_id`) REFERENCES `event_store` (`id`)
1616
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

src/DoctrineDbalRdbmsEventStoreRepository.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* payload: string,
2121
* metadata: string,
2222
* appliedAt: string,
23-
* domainId: string
23+
* domainTag: string
2424
* }
2525
*/
2626
final readonly class DoctrineDbalRdbmsEventStoreRepository implements RdbmsEventStoreRepository
@@ -33,7 +33,7 @@ public function __construct(
3333
) {}
3434

3535
#[Override]
36-
public function getEvents(array $domainIds, array $eventNames): array
36+
public function getEvents(array $domainTags, array $eventNames): array
3737
{
3838
$eventStoreSchema = $this->eventStoreTableSchema;
3939
$eventStoreRelationSchema = $this->eventStoreRelationTableSchema;
@@ -46,7 +46,7 @@ public function getEvents(array $domainIds, array $eventNames): array
4646
es.{$eventStoreSchema->eventNameFieldName} as eventName,
4747
es.{$eventStoreSchema->appliedAtFieldName} as appliedAt,
4848
es.{$eventStoreSchema->metadataFieldName} as metadata,
49-
esr.{$eventStoreRelationSchema->domainIdFieldName} as domainId
49+
esr.{$eventStoreRelationSchema->domainTagFieldName} as domainTag
5050
DQL
5151
)
5252
->from($eventStoreSchema->tableName, 'es')
@@ -56,9 +56,9 @@ public function getEvents(array $domainIds, array $eventNames): array
5656
$eventStoreRelationSchema->eventIdFieldName,
5757
))
5858
->where(sprintf('es.%s IN(:eventNames)', $eventStoreSchema->eventNameFieldName))
59-
->andWhere(sprintf('esr.%s IN(:domainIds)', $eventStoreRelationSchema->domainIdFieldName))
59+
->andWhere(sprintf('esr.%s IN(:domainTags)', $eventStoreRelationSchema->domainTagFieldName))
6060
->setParameter('eventNames', $eventNames, ArrayParameterType::STRING)
61-
->setParameter('domainIds', $domainIds, ArrayParameterType::STRING)
61+
->setParameter('domainTags', $domainTags, ArrayParameterType::STRING)
6262
->orderBy(sprintf('es.%s', $eventStoreSchema->appliedAtFieldName), 'asc')
6363
->executeQuery()
6464
->fetchAllAssociative();
@@ -72,14 +72,14 @@ public function getEvents(array $domainIds, array $eventNames): array
7272

7373
$event = $events[$eventId] ?? $this->rdbmsEventFactory->createFromRow($row);
7474

75-
$events[$eventId] = $event->withDomainId($row['domainId']);
75+
$events[$eventId] = $event->withDomainTag($row['domainTag']);
7676
}
7777

7878
return array_values($events);
7979
}
8080

8181
#[Override]
82-
public function getLastEventIdPersisted(array $domainIds, array $eventNames): ?string
82+
public function getLastEventIdPersisted(array $domainTags, array $eventNames): ?string
8383
{
8484
$eventStoreSchema = $this->eventStoreTableSchema;
8585
$eventStoreRelationSchema = $this->eventStoreRelationTableSchema;
@@ -94,9 +94,9 @@ public function getLastEventIdPersisted(array $domainIds, array $eventNames): ?s
9494
$eventStoreRelationSchema->eventIdFieldName,
9595
))
9696
->where(sprintf('es.%s IN(:eventNames)', $eventStoreSchema->eventNameFieldName))
97-
->andWhere(sprintf('esr.%s IN(:domainIds)', $eventStoreRelationSchema->domainIdFieldName))
97+
->andWhere(sprintf('esr.%s IN(:domainTags)', $eventStoreRelationSchema->domainTagFieldName))
9898
->setParameter('eventNames', $eventNames, ArrayParameterType::STRING)
99-
->setParameter('domainIds', $domainIds, ArrayParameterType::STRING)
99+
->setParameter('domainTags', $domainTags, ArrayParameterType::STRING)
100100
->orderBy(sprintf('es.%s', $eventStoreSchema->appliedAtFieldName), 'desc')
101101
->setMaxResults(1)
102102
->executeQuery()
@@ -131,14 +131,14 @@ public function saveEvents(array $events): void
131131
])
132132
->executeStatement();
133133

134-
foreach ($event->domainIds as $domainId) {
134+
foreach ($event->domainTags as $domainTag) {
135135
$this->connection->createQueryBuilder()
136136
->insert($eventStoreRelationSchema->tableName)
137137
->setValue($eventStoreRelationSchema->eventIdFieldName, ':eventId')
138-
->setValue($eventStoreRelationSchema->domainIdFieldName, ':domainId')
138+
->setValue($eventStoreRelationSchema->domainTagFieldName, ':domainTag')
139139
->setParameters([
140140
'eventId' => $event->eventId,
141-
'domainId' => $domainId,
141+
'domainTag' => $domainTag,
142142
])
143143
->executeStatement();
144144
}

src/TableSchema/EventStoreRelationTableSchema.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
public function __construct(
1010
public string $tableName,
1111
public string $eventIdFieldName,
12-
public string $domainIdFieldName,
12+
public string $domainTagFieldName,
1313
) {}
1414
}

src/TableSchema/TableSchemaFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ public static function createDefaultEventStore(
2929
public static function createDefaultEventStoreRelation(
3030
string $tableName = 'event_store_relation',
3131
string $eventIdFieldName = 'event_id',
32-
string $domainIdFieldName = 'domain_id',
32+
string $domainTagFieldName = 'domain_tag',
3333
): EventStoreRelationTableSchema {
3434
return new EventStoreRelationTableSchema(
3535
$tableName,
3636
$eventIdFieldName,
37-
$domainIdFieldName,
37+
$domainTagFieldName,
3838
);
3939
}
4040
}

tests/DoctrineDbalRdbmsEventFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function itShouldCreateRdbmsEvent(): void
2323
'payload' => '{"some":"data"}',
2424
'metadata' => '{"some":"metadata"}',
2525
'appliedAt' => '2018-12-01 12:05:08.234543',
26-
'domainId' => '5f183c87-20c5-412e-8b0f-e8d86c7b7a47',
26+
'domainTag' => '5f183c87-20c5-412e-8b0f-e8d86c7b7a47',
2727
]);
2828

2929
self::assertSame('5e3ce06e-8f08-440e-b7ea-412ac6c3e892', $event->eventId);

tests/TableSchema/TableSchemaFactoryTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function itShouldCreateDefaultEventStoreRelationTableSchema(): void
5656

5757
self::assertSame('event_store_relation', $schema->tableName);
5858
self::assertSame('event_id', $schema->eventIdFieldName);
59-
self::assertSame('domain_id', $schema->domainIdFieldName);
59+
self::assertSame('domain_tag', $schema->domainTagFieldName);
6060
}
6161

6262
#[Test]
@@ -65,11 +65,11 @@ public function itShouldCreateCustomEventStoreRelationTableSchema(): void
6565
$schema = TableSchemaFactory::createDefaultEventStoreRelation(
6666
'custom_event_store_relation',
6767
'custom_event_id',
68-
'custom_domain_id',
68+
'custom_domain_tag',
6969
);
7070

7171
self::assertSame('custom_event_store_relation', $schema->tableName);
7272
self::assertSame('custom_event_id', $schema->eventIdFieldName);
73-
self::assertSame('custom_domain_id', $schema->domainIdFieldName);
73+
self::assertSame('custom_domain_tag', $schema->domainTagFieldName);
7474
}
7575
}

tests/schema.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ CREATE TABLE `event_store` (
88

99
CREATE TABLE `event_store_relation` (
1010
`event_id` varchar(50) NOT NULL,
11-
`domain_id` varchar(50) NOT NULL
11+
`domain_tag` varchar(50) NOT NULL
1212
);

0 commit comments

Comments
 (0)