The library also offers symfony
cli commands to create or delete databases
.
It is also possible to manage the schema
and projections
.
These commands are optional
and only wrap existing functionalities
that are also available in this way.
To use the symfony cli command you first have to install
the packet.
composer require symfony/console
There are two commands for creating and deleting a database.
- DatabaseCreateCommand:
event-sourcing:database:create
- DatabaseDropCommand:
event-sourcing:database:drop
The database schema can also be created, updated and dropped.
- SchemaCreateCommand:
event-sourcing:schema:create
- SchemaUpdateCommand:
event-sourcing:schema:update
- SchemaDropCommand:
event-sourcing:schema:drop
📖 You can also register doctrine migration commands, see the store documentation for this.
The creation, deletion and rebuilding of the projections is also possible via the cli.
- ProjectionCreateCommand:
event-sourcing:projection:create
- ProjectionDropCommand:
event-sourcing:projection:drop
- ProjectionRebuildCommand:
event-sourcing:projection:rebuild
📖 The pipeline will be used to rebuild the projection.
A cli php file can look like this:
use Patchlevel\EventSourcing\Console\Command;
use Patchlevel\EventSourcing\Console\DoctrineHelper;
use Patchlevel\EventSourcing\Schema\DoctrineSchemaManager;
use Symfony\Component\Console\Application;
$store = /* define your doctrine store */;
$projectionRepository = /* create a project repository */;
$cli = new Application('Event-Sourcing CLI');
$cli->setCatchExceptions(true);
$doctrineHelper = new DoctrineHelper();
$schemaManager = new DoctrineSchemaManager();
$cli->addCommands(array(
new Command\DatabaseCreateCommand($store, $doctrineHelper),
new Command\DatabaseDropCommand($store, $doctrineHelper),
new Command\ProjectionCreateCommand($projectionRepository),
new Command\ProjectionDropCommand($projectionRepository),
new Command\ProjectionRebuildCommand($store, $projectionRepository),
new Command\SchemaCreateCommand($store, $schemaManager),
new Command\SchemaDropCommand($store, $schemaManager),
new Command\SchemaUpdateCommand($store, $schemaManager),
));
$cli->run();
📖 You can also register doctrine migration commands, see the store documentation for this.