diff --git a/docs/UPGRADE-4.0.md b/docs/UPGRADE-4.0.md index 15dc432c..83a9c37f 100644 --- a/docs/UPGRADE-4.0.md +++ b/docs/UPGRADE-4.0.md @@ -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. diff --git a/docs/configuration.md b/docs/configuration.md index 7c221b08..6f2cfcea 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -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. ::: @@ -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. @@ -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). ::: diff --git a/docs/installation.md b/docs/installation.md index bd5f07f1..c90e25d7 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -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: diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 69c2fd8e..aa6aa1b2 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -62,7 +62,6 @@ * provide_dedicated_connection: bool * }, * store: array{ - * merge_orm_schema: bool, * options: array, * type: string, * service: ?string, @@ -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{ @@ -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') @@ -306,6 +305,8 @@ public function getConfigTreeBuilder(): TreeBuilder ->canBeEnabled() ->end() + ->booleanNode('use_doctrine_bundle')->defaultFalse()->end() + ->arrayNode('hydrator') ->addDefaultsIfNotSet() ->children() diff --git a/src/DependencyInjection/PatchlevelEventSourcingExtension.php b/src/DependencyInjection/PatchlevelEventSourcingExtension.php index c39cb2ac..9d8c7b90 100644 --- a/src/DependencyInjection/PatchlevelEventSourcingExtension.php +++ b/src/DependencyInjection/PatchlevelEventSourcingExtension.php @@ -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; } @@ -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]); diff --git a/tests/Unit/PatchlevelEventSourcingBundleTest.php b/tests/Unit/PatchlevelEventSourcingBundleTest.php index d68440f2..d64d15a3 100644 --- a/tests/Unit/PatchlevelEventSourcingBundleTest.php +++ b/tests/Unit/PatchlevelEventSourcingBundleTest.php @@ -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, ], ], ); @@ -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, ], ], );