diff --git a/src/Console/Commands/EventStoreReset.php b/src/Console/Commands/EventStoreReset.php new file mode 100644 index 0000000..dbe856b --- /dev/null +++ b/src/Console/Commands/EventStoreReset.php @@ -0,0 +1,53 @@ +client = $client; + + parent::__construct(); + } + + public function handle() + { + if (! $this->confirm('Please stop all workers first. Continue?')) return; + + $this->call('migrate:fresh'); + + $streams = collect(config('eventstore.subscription_streams')); + + $streams->map([$this, 'deleteSubscription']); + $streams->map([$this, 'createSubscription']); + } + + public function deleteSubscription($stream) + { + $name = config('eventstore.group'); + + try { + $this->client->delete("/subscriptions/{$stream}/{$name}"); + } + catch (ClientException $e) { + throw_if($e->getCode() !== 404, $e); + } + } + + public function createSubscription($stream) + { + $name = config('eventstore.group'); + + $this->client->put("/subscriptions/{$stream}/{$name}"); + } +} diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index dbf43ed..bbb5acf 100755 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -2,6 +2,7 @@ namespace DigitalRisks\LaravelEventStore; +use DigitalRisks\LaravelEventStore\Console\Commands\EventStoreReset; use DigitalRisks\LaravelEventStore\Console\Commands\EventStoreWorker; use DigitalRisks\LaravelEventStore\Contracts\ShouldBeStored; use DigitalRisks\LaravelEventStore\Listeners\SendToEventStoreListener; @@ -22,6 +23,7 @@ public function boot() $this->commands([ EventStoreWorker::class, + EventStoreReset::class, ]); }