Skip to content

Installation

If you are not using a symfony flex or the recipes for it, then you have to carry out a few installation steps by hand.

Require package

The first thing to do is to install packet if it has not already been done.

composer require patchlevel/event-sourcing-bundle

Note

how to install composer

Enable bundle

Then we have to activate the bundle in the config/bundles.php:

use Patchlevel\EventSourcingBundle\PatchlevelEventSourcingBundle;

return [
    PatchlevelEventSourcingBundle::class => ['all' => true],
];

Configuration file

Now you have to add following recommended configuration file here config/packages/patchlevel_event_sourcing.yaml.

patchlevel_event_sourcing:
    aggregates: '%kernel.project_dir%/src'
    events: '%kernel.project_dir%/src'
    connection:
      url: '%env(EVENTSTORE_URL)%'
      provide_dedicated_connection: true

when@dev:
  patchlevel_event_sourcing:
    subscription:
      catch_up: true
      throw_on_error: true
      run_after_aggregate_save: true
      rebuild_after_file_change: true
      auto_setup: true

when@test:
  patchlevel_event_sourcing:
    subscription:
      catch_up: true
      throw_on_error: true
      run_after_aggregate_save: true

Dotenv

Finally, we have to fill the ENV variable with a connection url.

EVENTSTORE_URL="pdo-pgsql://app:[email protected]:5432/app?serverVersion=16&charset=utf8"

Note

You can find out more about what a connection url looks like here.

Database with Docker

If you are using docker, you can use the following compose.yaml file to start a postgres database.

services:
  eventstore:
    image: postgres:${POSTGRES_VERSION:-16}-alpine
    environment:
      POSTGRES_DB: ${POSTGRES_DB:-app}
      # You should definitely change the password in production
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-!ChangeMe!}
      POSTGRES_USER: ${POSTGRES_USER:-app}
    volumes:
      - eventstore_data:/var/lib/postgresql/data:rw
      # You may use a bind-mounted host directory instead, so that it is harder to accidentally remove the volume and lose all your data!
      # - ./docker/db/data:/var/lib/postgresql/data:rw

volumes:
  eventstore_data:
And for development, you can add a compose.override.yaml file to expose the port.

services:
  eventstore:
    ports:
      - "5432"

Symfony CLI

If you are using the symfony cli, you can configure that the database is started automatically if you start the server. For this you have to add the following configuration to the .symfony.local.yaml file.

workers:
  docker_compose: ~

Success

You have successfully installed the bundle. Now you can start with the quickstart to get a feeling for the bundle.