Skip to content

Commit 648655d

Browse files
committed
add migrations & add config docs
1 parent 2685009 commit 648655d

File tree

5 files changed

+150
-5
lines changed

5 files changed

+150
-5
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"license": "MIT",
44
"description": "laravel package for patchlevel/event-sourcing",
55
"keywords": [
6-
"event-sourcing"
6+
"event-sourcing",
7+
"laravel"
78
],
89
"homepage": "https://github.com/patchlevel/laravel-event-sourcing",
910
"authors": [

config/event-sourcing.php

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,77 @@
11
<?php
22

33
return [
4+
/*
5+
|--------------------------------------------------------------------------
6+
| Connection
7+
|--------------------------------------------------------------------------
8+
|
9+
| The dbal connection configuration for the event store.
10+
| Default is the default database connection,
11+
| that is configured in the laravel database configuration.
12+
|
13+
*/
14+
415
'connection' => [
516
'url' => env('EVENT_SOURCING_DB_URL'),
617
'connection' => env(
718
'EVENT_SOURCING_DB_CONNECTION',
819
env('DB_CONNECTION', 'sqlite')
920
),
1021
],
22+
23+
/*
24+
|--------------------------------------------------------------------------
25+
| Store
26+
|--------------------------------------------------------------------------
27+
|
28+
| Here you can configure the event store.
29+
| You can choose between different types of stores.
30+
|
31+
| dbal_stream (default): Store events in a single table with a stream id.
32+
| dbal_aggregate: Store events in a single table with the aggregate and aggregate id.
33+
| in_memory: Store events in memory.
34+
| custom: Use a custom store, you need to provide a service.
35+
|
36+
*/
37+
1138
'store' => [
12-
'type' => 'dbal_aggregate',
39+
'type' => 'dbal_stream',
1340
'service' => null,
14-
'options' => []
41+
'options' => [
42+
'table_name' => 'eventstore',
43+
]
1544
],
45+
46+
/*
47+
|--------------------------------------------------------------------------
48+
| Events, Aggregates, Headers
49+
|--------------------------------------------------------------------------
50+
|
51+
| Here you can define the paths where the package should look for
52+
| events, aggregates and headers.
53+
|
54+
*/
55+
1656
'events' => [app_path()],
1757
'aggregates' => [app_path()],
1858
'headers' => [app_path()],
59+
60+
/*
61+
|--------------------------------------------------------------------------
62+
| Subscription
63+
|--------------------------------------------------------------------------
64+
|
65+
| Here you can configure the subscription.
66+
| The subscription engine is default in pseudo sync mode.
67+
| You can change it to full async mode,
68+
| by setting 'subscription.run_after_aggregate_save.enabled' to false.
69+
| In this case you need to use the `event-sourcing:subscription:run` command.
70+
| You should also set the 'subscription.catch_up'
71+
| and 'subscription.throw_on_error' to false.
72+
|
73+
*/
74+
1975
'subscription' => [
2076
'throw_on_error' => true,
2177
'catch_up' => true,
@@ -25,15 +81,43 @@
2581
'max_attempts' => 5,
2682
],
2783
'run_after_aggregate_save' => [
84+
'enabled' => true,
2885
'ids' => null,
2986
'groups' => null,
3087
'limit' => null
3188
],
3289
],
90+
91+
/*
92+
|--------------------------------------------------------------------------
93+
| Cryptography
94+
|--------------------------------------------------------------------------
95+
|
96+
| Here you can enable or disable the cryptography.
97+
| You can also define the algorithm for the cryptography.
98+
|
99+
*/
100+
33101
'cryptography' => [
34102
'enabled' => true,
35103
'algorithm' => 'aes256'
36104
],
105+
106+
/*
107+
|--------------------------------------------------------------------------
108+
| Services
109+
|--------------------------------------------------------------------------
110+
|
111+
| Here you can define your own services.
112+
|
113+
| Upcaster: Upcasters are used to convert old events to new events.
114+
| Message Decorator: Message Decorators are used to decorate messages.
115+
| Listener: Listeners are used to listen to events in the event bus.
116+
| Subscriber: Subscribers are used to subscribe to events for subscription engine.
117+
| Argument Resolver: Argument Resolvers are used to resolve arguments for subscribers.
118+
|
119+
*/
120+
37121
'upcaster' => [
38122
// App\Upcaster\YourUpcaster::class
39123
],
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
return new class extends Migration
8+
{
9+
public function up(): void
10+
{
11+
Schema::create('eventstore', function (Blueprint $table) {
12+
$table->bigIncrements('id');
13+
$table->string('stream', 255);
14+
$table->integer('playhead')->nullable();
15+
$table->string('event', 255);
16+
$table->json('payload');
17+
$table->dateTime('recorded_on');
18+
$table->boolean('new_stream_start')->default(false);
19+
$table->boolean('archived')->default(false);
20+
$table->json('custom_headers');
21+
$table->unique(['stream', 'playhead']);
22+
$table->index(['stream', 'playhead', 'archived']);
23+
});
24+
25+
Schema::create('subscriptions', function (Blueprint $table) {
26+
$table->string('id', 255);
27+
$table->string('group_name', 32);
28+
$table->string('run_mode', 16);
29+
$table->integer('position');
30+
$table->string('status', 32);
31+
$table->longText('error_message')->nullable();
32+
$table->string('error_previous_status', 32)->nullable();
33+
$table->json('error_context')->nullable();
34+
$table->integer('retry_attempt');
35+
$table->dateTime('last_saved_at');
36+
$table->index('group_name');
37+
$table->index('status');
38+
$table->primary('id');
39+
});
40+
41+
Schema::create('eventstore_cipher_keys', function (Blueprint $table) {
42+
$table->string('subject_id', 255);
43+
$table->string('crypto_key', 255);
44+
$table->string('crypto_method', 255);
45+
$table->string('crypto_iv', 255);
46+
$table->primary('subject_id');
47+
});
48+
}
49+
50+
public function down(): void
51+
{
52+
Schema::dropIfExists('eventstore');
53+
Schema::dropIfExists('subscriptions');
54+
Schema::dropIfExists('eventstore_cipher_keys');
55+
}
56+
};

src/EventSourcingServiceProvider.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@
103103

104104
class EventSourcingServiceProvider extends ServiceProvider
105105
{
106+
public static $publishGroups = ['patchlevel-config', 'patchlevel-migrations'];
107+
106108
public array $singletons = [
107109
EventMetadataFactory::class => AttributeEventMetadataFactory::class,
108110
Encoder::class => JsonEncoder::class,
@@ -118,7 +120,7 @@ public function boot(): void
118120
], 'patchlevel-config');
119121

120122
$this->publishesMigrations([
121-
__DIR__.'/../database/migrations/' => database_path('migrations')
123+
__DIR__ . '/../database/migrations/' => database_path('migrations'),
122124
], 'patchlevel-migrations');
123125

124126
if (!$this->app->runningInConsole()) {
@@ -638,9 +640,12 @@ private function registerCryptography(): void
638640
$this->app->singleton(CipherKeyStore::class, static function () {
639641
return new DoctrineCipherKeyStore(
640642
app('event_sourcing.dbal_connection'),
643+
'eventstore_cipher_keys',
641644
);
642645
});
643646

647+
$this->app->tag(CipherKeyStore::class, ['event_sourcing.doctrine_schema_configurator']);
648+
644649
$this->app->singleton(Cipher::class, static function () {
645650
return new OpensslCipher();
646651
});

src/Middleware/SubscriptionRebuildAfterFileChangeMiddleware.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ public function handle(Request $request, Closure $next): Response
4747
continue;
4848
}
4949

50-
5150
$currentModified = $this->getLastModifiedTime($subscriber);
5251

5352
if ($lastModified === $currentModified) {

0 commit comments

Comments
 (0)