Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions docs/UPGRADE-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,25 @@ Migrate your events with the `migrate_to_new_store` option and the `event-sourci
while you are still on 3.x, otherwise your events can no longer be read.
:::

### Use Doctrine Bundle

The option `store.merge_orm_schema` has been renamed to `use_doctrine_bundle` and moved to the top level.
It does not only affect the store, but means that event sourcing fully uses the doctrine bundle:
its connection, its commands, its schema and its migrations instead of the own tooling of this bundle.

before:

```yaml
patchlevel_event_sourcing:
store:
merge_orm_schema: true
```
after:

```yaml
patchlevel_event_sourcing:
use_doctrine_bundle: true
```
### Read Only Mode

`read_only` is now only supported by the `dbal_stream` store.
Expand Down
43 changes: 24 additions & 19 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ otherwise you may run into transaction problems.
:::

:::warning
If you want to use the same connection as doctrine orm, then you have to set the flag `merge_orm_schema`.
If you want to use the same connection as doctrine orm, then you have to set the flag `use_doctrine_bundle`.
Otherwise you should avoid using the same connection as other tools.
:::

Expand All @@ -131,6 +131,29 @@ You can find out more about the dbal configuration
[here](https://symfony.com/bundles/DoctrineBundle/current/configuration.html).
:::

If your application already uses the doctrine bundle, you can let event sourcing use it completely
instead of the own tooling of this bundle.

```yaml
patchlevel_event_sourcing:
connection:
service: doctrine.dbal.default_connection
use_doctrine_bundle: true
```
With `use_doctrine_bundle` enabled:

* The connection comes from the doctrine bundle, so configure `connection.service` with a doctrine connection.
* The database, schema and migration commands of event sourcing are not registered.
Use the doctrine commands like `doctrine:database:create`, `doctrine:schema:update` and `doctrine:migrations:diff`.
* A doctrine event listener adds the tables of event sourcing, like the store and the subscription store,
to the doctrine orm schema, so the doctrine commands manage them too.
* The `migration` configuration of this bundle is ignored, configure the doctrine migrations bundle instead.

:::warning
The event sourcing tables are added to the schema of the doctrine orm.
So the same connection must be used as with the doctrine orm, otherwise errors may occur!
:::

If you are using Doctrine for your projections too, you need to create a dedicated connection for this.
You can do this by defining a new connection named `projection` in the `doctrine.yaml` file
and use the same connection url as for the event store.
Expand Down Expand Up @@ -233,24 +256,6 @@ patchlevel_event_sourcing:
This is useful if you have maintenance work on the event store and you want to avoid side effects.
:::

### Merge ORM Schema

You can also merge the schema with doctrine orm. You have to set the following flag for this:

```yaml
patchlevel_event_sourcing:
store:
merge_orm_schema: true
```
:::warning
If you want to merge the schema, then the same doctrine connection must be used as with the doctrine orm.
Otherwise errors may occur!
:::

:::note
All schema relevant commands are removed if you activate this option. You should use the doctrine commands then.
:::

:::tip
If you want to learn more about store, read the [library documentation](/docs/event-sourcing/latest/store).
:::
Expand Down
4 changes: 2 additions & 2 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ patchlevel_event_sourcing:
provide_dedicated_connection: true
store:
type: dbal_stream
# if you are using doctrine bundle you should enable this
#merge_orm_schema: true
# if you are using doctrine bundle you should enable this
#use_doctrine_bundle: true
command_bus:
service: messenger.default_bus
query_bus:
Expand Down
5 changes: 3 additions & 2 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
* provide_dedicated_connection: bool
* },
* store: array{
* merge_orm_schema: bool,
* options: array<string, mixed>,
* type: string,
* service: ?string,
Expand All @@ -79,6 +78,7 @@
* migration: array{path: string, namespace: string},
* clock: array{freeze: ?string, service: ?string},
* dcb: array{enabled: bool},
* use_doctrine_bundle: bool,
* hydrator: array{
* default_lazy: bool,
* cryptography: array{
Expand Down Expand Up @@ -117,7 +117,6 @@ public function getConfigTreeBuilder(): TreeBuilder
->defaultValue('dbal_stream')
->end()
->scalarNode('service')->defaultNull()->end()
->booleanNode('merge_orm_schema')->defaultFalse()->end()
->arrayNode('options')->variablePrototype()->end()->end()
->booleanNode('read_only')->defaultFalse()->end()
->arrayNode('migrate_to_new_store')
Expand Down Expand Up @@ -306,6 +305,8 @@ public function getConfigTreeBuilder(): TreeBuilder
->canBeEnabled()
->end()

->booleanNode('use_doctrine_bundle')->defaultFalse()->end()

->arrayNode('hydrator')
->addDefaultsIfNotSet()
->children()
Expand Down
4 changes: 2 additions & 2 deletions src/DependencyInjection/PatchlevelEventSourcingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ private function configureCommands(ContainerBuilder $container): void
/** @param Config $config */
private function configureMigration(array $config, ContainerBuilder $container): void
{
if (!class_exists(DependencyFactory::class) || $config['store']['merge_orm_schema'] !== false) {
if (!class_exists(DependencyFactory::class) || $config['use_doctrine_bundle']) {
return;
}

Expand Down Expand Up @@ -1271,7 +1271,7 @@ private function configureSchema(array $config, ContainerBuilder $container): vo

$container->setAlias(DoctrineSchemaConfigurator::class, ChainDoctrineSchemaConfigurator::class);

if ($config['store']['merge_orm_schema']) {
if ($config['use_doctrine_bundle']) {
$container->register(DoctrineSchemaListener::class)
->setArguments([new Reference(DoctrineSchemaConfigurator::class)])
->addTag('doctrine.event_listener', ['event' => ToolEvents::postGenerateSchema]);
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/PatchlevelEventSourcingBundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ public function testSubscriptionCleanupWithDoctrine(): void
[
'patchlevel_event_sourcing' => [
'connection' => ['service' => 'doctrine.dbal.eventstore_connection'],
'store' => ['merge_orm_schema' => true],
'use_doctrine_bundle' => true,
],
],
);
Expand Down Expand Up @@ -1805,7 +1805,7 @@ public function testSchemaMerge(): void
[
'patchlevel_event_sourcing' => [
'connection' => ['service' => 'doctrine.dbal.eventstore_connection'],
'store' => ['merge_orm_schema' => true],
'use_doctrine_bundle' => true,
],
],
);
Expand Down
Loading