Skip to content

Commit fa2c744

Browse files
authored
Merge pull request #758 from patchlevel/remove-legacy-store
Remove deprecated `DoctrineDbalStore` in favor of `StreamDoctrineDbalStore`
2 parents 4c162f5 + ee4fafb commit fa2c744

64 files changed

Lines changed: 376 additions & 4781 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

baseline.xml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,6 @@
8282
</MixedMethodCall>
8383
</file>
8484
<file src="src/Repository/DefaultRepository.php">
85-
<PossiblyNullArgument>
86-
<code><![CDATA[$streamName]]></code>
87-
</PossiblyNullArgument>
8885
<PropertyTypeCoercion>
8986
<code><![CDATA[new WeakMap()]]></code>
9087
</PropertyTypeCoercion>
@@ -131,14 +128,6 @@
131128
<code><![CDATA[$streamName]]></code>
132129
</PropertyTypeCoercion>
133130
</file>
134-
<file src="src/Store/DoctrineDbalStoreStream.php">
135-
<ArgumentTypeCoercion>
136-
<code><![CDATA[(int)$data['playhead']]]></code>
137-
</ArgumentTypeCoercion>
138-
<MixedArgument>
139-
<code><![CDATA[$dateTimeType->convertToPHPValue($data['recorded_on'], $platform)]]></code>
140-
</MixedArgument>
141-
</file>
142131
<file src="src/Store/InMemoryStore.php">
143132
<MixedPropertyTypeCoercion>
144133
<code><![CDATA[$this->messages]]></code>

docs/pages/UPGRADE-4.0.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44

55
### Child Aggregate
66

7-
We removed our experimental feature of child aggregates.
7+
We removed our experimental feature of child aggregates.
88
This was our first attempt to split aggregates into smaller parts,
99
but we found a better way to do this with the `Micro Aggregate` feature.
1010

1111
## Subscription
1212

1313
The constructor of the `DefaultSubscriptionEngine` class has been changed.
14+
1415
* Instead of passing a `Store` instance, you now need to pass a `MessageLoader` instance.
1516
* Instead of passing a `RetryStrategy` instance, you now need to pass a `RetryStrategyRepository` instance.
1617

@@ -59,4 +60,32 @@ $subscriptionEngine = new DefaultSubscriptionEngine(
5960
$subscriberAccessorRepository,
6061
RetryStrategyRepository::withDefault($retryStrategy),
6162
);
62-
```
63+
```
64+
65+
## Store
66+
67+
### DoctrineDbalStore
68+
69+
`DoctrineDbalStore` has been removed in favor of `StreamDoctrineDbalStore`.
70+
And all the associated classes:
71+
72+
* `Patchlevel\EventSourcing\Store\Criteria\AggregateNameCriterion`
73+
* `Patchlevel\EventSourcing\Store\Criteria\AggregateIdCriterion`
74+
* `Patchlevel\EventSourcing\Store\DoctrineDbalStore`
75+
* `Patchlevel\EventSourcing\Store\DoctrineDbalStoreStream`
76+
* `Patchlevel\EventSourcing\Store\ReadOnlyStore`
77+
78+
## Message
79+
80+
### AggregateHeader
81+
82+
`Patchlevel\EventSourcing\Aggregate\AggregateHeader` has been removed
83+
and replaced with the following headers:
84+
85+
* `Patchlevel\EventSourcing\Store\Header\StreamNameHeader`
86+
* `Patchlevel\EventSourcing\Store\Header\PlayheadHeader`
87+
* `Patchlevel\EventSourcing\Store\Header\RecordedOnHeader`
88+
89+
### AggregateToStreamHeaderTranslator
90+
91+
`Patchlevel\EventSourcing\Store\AggregateToStreamHeaderTranslator` has been removed.

docs/pages/aggregate.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,6 @@ final class Profile extends BasicAggregateRoot
360360

361361
## Stream Name
362362

363-
!!! warning
364-
365-
The `stream name` works only with the [StreamDoctrineDbalStore](./store.md#streamdoctrinedbalstore).
366-
367363
The stream name is the name of the stream in the event store.
368364
By default, the stream name has the format `aggregateName-aggregateId`.
369365
But you can also define your own stream name with the `Stream` attribute.
@@ -657,10 +653,6 @@ For these cases you can use Micro Aggregates.
657653

658654
### Micro Aggregates
659655

660-
!!! warning
661-
662-
This feature works only with the [StreamDoctrineDbalStore](./store.md#streamdoctrinedbalstore).
663-
664656
Micro Aggregates are a pattern to split an aggregate into several smaller aggregates.
665657
Each of these aggregates is saved in the same stream.
666658
This gives the Micro Aggregates the ability to independently manage their state and trigger their events,
@@ -740,7 +732,6 @@ final class Shipping extends BasicAggregateRoot
740732
}
741733
}
742734
```
743-
744735
## Aggregate Root Registry
745736

746737
The library needs to know about all aggregates so that the correct aggregate class is used to load from the database.

docs/pages/getting_started.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ use Doctrine\DBAL\Tools\DsnParser;
276276
use Patchlevel\EventSourcing\Metadata\AggregateRoot\AttributeAggregateRootRegistryFactory;
277277
use Patchlevel\EventSourcing\Repository\DefaultRepositoryManager;
278278
use Patchlevel\EventSourcing\Serializer\DefaultEventSerializer;
279-
use Patchlevel\EventSourcing\Store\DoctrineDbalStore;
279+
use Patchlevel\EventSourcing\Store\StreamDoctrineDbalStore;
280280
use Patchlevel\EventSourcing\Subscription\Engine\DefaultSubscriptionEngine;
281281
use Patchlevel\EventSourcing\Subscription\Repository\RunSubscriptionEngineRepositoryManager;
282282
use Patchlevel\EventSourcing\Subscription\Store\DoctrineSubscriptionStore;
@@ -296,7 +296,7 @@ $mailer;
296296
$serializer = DefaultEventSerializer::createFromPaths(['src/Domain/Hotel/Event']);
297297
$aggregateRegistry = (new AttributeAggregateRootRegistryFactory())->create(['src/Domain/Hotel']);
298298

299-
$eventStore = new DoctrineDbalStore(
299+
$eventStore = new StreamDoctrineDbalStore(
300300
$connection,
301301
$serializer,
302302
);

docs/pages/store.md

Lines changed: 3 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -12,73 +12,10 @@ The store is optimized to efficiently store and load events for aggregates.
1212
## Configure Store
1313

1414
We offer different stores to store the messages.
15-
Two stores based on [doctrine dbal](https://www.doctrine-project.org/projects/dbal.html)
16-
and one in-memory store for testing purposes.
1715

18-
### DoctrineDbalStore
19-
20-
This is the current default store for event sourcing.
21-
You can create a store with the `DoctrineDbalStore` class.
22-
The store needs a dbal connection, an event serializer and has some optional parameters like options.
23-
24-
```php
25-
use Doctrine\DBAL\DriverManager;
26-
use Doctrine\DBAL\Tools\DsnParser;
27-
use Patchlevel\EventSourcing\Serializer\DefaultEventSerializer;
28-
use Patchlevel\EventSourcing\Store\DoctrineDbalStore;
29-
30-
$connection = DriverManager::getConnection(
31-
(new DsnParser())->parse('pdo-pgsql://user:secret@localhost/app'),
32-
);
33-
34-
$store = new DoctrineDbalStore(
35-
$connection,
36-
DefaultEventSerializer::createFromPaths(['src/Event']),
37-
);
38-
```
39-
!!! note
40-
41-
You can find out more about how to create a connection
42-
[here](https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html)
43-
44-
Following options are available in `DoctrineDbalStore`:
45-
46-
| Option | Type | Default | Description |
47-
|-------------------|-----------------|------------|----------------------------------------------|
48-
| table_name | string | eventstore | The name of the table in the database |
49-
| aggregate_id_type | "uuid"/"string" | uuid | The type of the `aggregate_id` column |
50-
| locking | bool | true | If the store should use locking for writing |
51-
| lock_id | int | 133742 | The id of the lock |
52-
| lock_timeout | int | -1 | The timeout of the lock. -1 means no timeout |
53-
54-
The table structure of the `DoctrineDbalStore` looks like this:
55-
56-
| Column | Type | Description |
57-
|------------------|-------------|--------------------------------------------------|
58-
| id | bigint | The index of the whole stream (autoincrement) |
59-
| aggregate | string | The name of the aggregate |
60-
| aggregate_id | uuid/string | The id of the aggregate |
61-
| playhead | int | The current playhead of the aggregate |
62-
| event | string | The name of the event |
63-
| payload | json | The payload of the event |
64-
| recorded_on | datetime | The date when the event was recorded |
65-
| new_stream_start | bool | If the event is the first event of the aggregate |
66-
| archived | bool | If the event is archived |
67-
| custom_headers | json | Custom headers for the event |
68-
69-
!!! note
70-
71-
The default type of the `aggregate_id` column is `uuid` if the database supports it and `string` if not.
72-
You can change the type with the `aggregate_id_type` to `string` if you want use custom id.
73-
7416
### StreamDoctrineDbalStore
7517

76-
We offer a new store called `StreamDoctrineDbalStore`.
77-
This store is decoupled from the aggregate and can be used to store events from other sources.
78-
The difference to the `DoctrineDbalStore` is that the `StreamDoctrineDbalStore` merge the aggregate id
79-
and the aggregate name into one column named `stream`. Additionally, the column `playhead` is nullable.
80-
This store introduces two new methods `streams` and `remove`.
81-
18+
We offer a store called `StreamDoctrineDbalStore`.
8219
The store needs a dbal connection, an event serializer and has some optional parameters like options.
8320

8421
```php
@@ -139,22 +76,16 @@ $store = new InMemoryStore();
13976

14077
You can pass messages to the constructor to initialize the store with some events.
14178

142-
### ReadOnlyStore & StreamReadOnlyStore
79+
### StreamReadOnlyStore
14380

144-
Last but not least, we offer two read-only stores.
145-
One for the `DoctrineDbalStore` and one for the `StreamDoctrineDbalStore`.
81+
Last but not least, we offer a read-only store named `StreamReadOnlyStore`.
14682
It passes all methods to the underlying store, but throws an `StoreIsReadOnly` exception when trying to execute write
14783
operations.
14884

14985
```php
150-
use Patchlevel\EventSourcing\Store\ReadOnlyStore;
151-
use Patchlevel\EventSourcing\Store\Store;
15286
use Patchlevel\EventSourcing\Store\StreamReadOnlyStore;
15387
use Patchlevel\EventSourcing\Store\StreamStore;
15488

155-
/** @var Store $store */
156-
$readOnlyStore = new ReadOnlyStore($store);
157-
15889
/** @var StreamStore $store */
15990
$readOnlyStore = new StreamReadOnlyStore($store);
16091
```
@@ -456,10 +387,6 @@ use Patchlevel\EventSourcing\Store\StreamStore;
456387
/** @var StreamStore $store */
457388
$store->remove('profile-*');
458389
```
459-
!!! note
460-
461-
The method is only available in the `StreamStore` like `StreamDoctrineDbalStore`.
462-
463390
### List Streams
464391

465392
You can list all streams with the `streams` method.
@@ -470,10 +397,6 @@ use Patchlevel\EventSourcing\Store\StreamStore;
470397
/** @var StreamStore $store */
471398
$streams = $store->streams(); // ['profile-1', 'profile-2', 'profile-3']
472399
```
473-
!!! note
474-
475-
The method is only available in the `StreamStore` like `StreamDoctrineDbalStore`.
476-
477400
### Transaction
478401

479402
There is also the possibility of executing a function in a transaction.

infection.json.dist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"mutators": {
1515
"@default": true
1616
},
17-
"minMsi": 72,
18-
"minCoveredMsi": 95,
17+
"minMsi": 69,
18+
"minCoveredMsi": 93,
1919
"testFrameworkOptions": "--testsuite=unit"
2020
}

phpstan-baseline.neon

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,6 @@ parameters:
4848
count: 1
4949
path: src/Repository/DefaultRepository.php
5050

51-
-
52-
message: '#^Parameter \#1 \.\.\.\$streamName of class Patchlevel\\EventSourcing\\Store\\Criteria\\StreamCriterion constructor expects string, string\|null given\.$#'
53-
identifier: argument.type
54-
count: 1
55-
path: src/Repository/DefaultRepository.php
56-
5751
-
5852
message: '#^Parameter \#2 \$data of method Patchlevel\\Hydrator\\Hydrator\:\:hydrate\(\) expects array\<string, mixed\>, mixed given\.$#'
5953
identifier: argument.type
@@ -90,30 +84,6 @@ parameters:
9084
count: 1
9185
path: src/Store/Criteria/StreamCriterion.php
9286

93-
-
94-
message: '#^Method Patchlevel\\EventSourcing\\Store\\DoctrineDbalStoreStream\:\:current\(\) never returns null so it can be removed from the return type\.$#'
95-
identifier: return.unusedType
96-
count: 1
97-
path: src/Store/DoctrineDbalStoreStream.php
98-
99-
-
100-
message: '#^Parameter \#3 \$playhead of class Patchlevel\\EventSourcing\\Aggregate\\AggregateHeader constructor expects int\<1, max\>, int given\.$#'
101-
identifier: argument.type
102-
count: 1
103-
path: src/Store/DoctrineDbalStoreStream.php
104-
105-
-
106-
message: '#^Parameter \#4 \$recordedOn of class Patchlevel\\EventSourcing\\Aggregate\\AggregateHeader constructor expects DateTimeImmutable, mixed given\.$#'
107-
identifier: argument.type
108-
count: 1
109-
path: src/Store/DoctrineDbalStoreStream.php
110-
111-
-
112-
message: '#^Ternary operator condition is always true\.$#'
113-
identifier: ternary.alwaysTrue
114-
count: 1
115-
path: src/Store/DoctrineDbalStoreStream.php
116-
11787
-
11888
message: '#^Method Patchlevel\\EventSourcing\\Store\\StreamDoctrineDbalStoreStream\:\:current\(\) never returns null so it can be removed from the return type\.$#'
11989
identifier: return.unusedType
@@ -177,7 +147,7 @@ parameters:
177147
-
178148
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Patchlevel\\\\EventSourcing\\\\Tests\\\\Integration\\\\BankAccountSplitStream\\\\BankAccount'' and Patchlevel\\EventSourcing\\Tests\\Integration\\BankAccountSplitStream\\BankAccount will always evaluate to true\.$#'
179149
identifier: staticMethod.alreadyNarrowedType
180-
count: 6
150+
count: 4
181151
path: tests/Integration/BankAccountSplitStream/IntegrationTest.php
182152

183153
-

src/Aggregate/AggregateHeader.php

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)