From 23a6b51991f0b31f2325d208428eb45dc8c1ecac Mon Sep 17 00:00:00 2001 From: Daniel Badura Date: Mon, 6 Jan 2025 21:20:45 +0100 Subject: [PATCH 1/3] Use jsonb when using postgresql --- src/Store/DoctrineDbalStore.php | 2 ++ src/Store/StreamDoctrineDbalStore.php | 2 ++ src/Subscription/Store/DoctrineSubscriptionStore.php | 1 + tests/Unit/Store/DoctrineDbalStoreTest.php | 4 ++++ tests/Unit/Store/StreamDoctrineDbalStoreTest.php | 2 ++ 5 files changed, 11 insertions(+) diff --git a/src/Store/DoctrineDbalStore.php b/src/Store/DoctrineDbalStore.php index 76c775bd3..35ef41372 100644 --- a/src/Store/DoctrineDbalStore.php +++ b/src/Store/DoctrineDbalStore.php @@ -337,6 +337,7 @@ public function configureSchema(Schema $schema, Connection $connection): void ->setLength(255) ->setNotnull(true); $table->addColumn('payload', Types::JSON) + ->setPlatformOption('jsonb', true) ->setNotnull(true); $table->addColumn('recorded_on', Types::DATETIMETZ_IMMUTABLE) ->setNotnull(true); @@ -347,6 +348,7 @@ public function configureSchema(Schema $schema, Connection $connection): void ->setNotnull(true) ->setDefault(false); $table->addColumn('custom_headers', Types::JSON) + ->setPlatformOption('jsonb', true) ->setNotnull(true); $table->setPrimaryKey(['id']); diff --git a/src/Store/StreamDoctrineDbalStore.php b/src/Store/StreamDoctrineDbalStore.php index 69ef4b9ea..af15bfbc6 100644 --- a/src/Store/StreamDoctrineDbalStore.php +++ b/src/Store/StreamDoctrineDbalStore.php @@ -416,6 +416,7 @@ public function configureSchema(Schema $schema, Connection $connection): void ->setLength(255) ->setNotnull(true); $table->addColumn('event_payload', Types::JSON) + ->setPlatformOption('jsonb', true) ->setNotnull(true); $table->addColumn('recorded_on', Types::DATETIMETZ_IMMUTABLE) ->setNotnull(true); @@ -423,6 +424,7 @@ public function configureSchema(Schema $schema, Connection $connection): void ->setNotnull(true) ->setDefault(false); $table->addColumn('custom_headers', Types::JSON) + ->setPlatformOption('jsonb', true) ->setNotnull(true); $table->setPrimaryKey(['id']); diff --git a/src/Subscription/Store/DoctrineSubscriptionStore.php b/src/Subscription/Store/DoctrineSubscriptionStore.php index 08cde34df..e06fb7259 100644 --- a/src/Subscription/Store/DoctrineSubscriptionStore.php +++ b/src/Subscription/Store/DoctrineSubscriptionStore.php @@ -230,6 +230,7 @@ public function configureSchema(Schema $schema, Connection $connection): void ->setLength(32) ->setNotnull(false); $table->addColumn('error_context', Types::JSON) + ->setPlatformOption('jsonb', true) ->setNotnull(false); $table->addColumn('retry_attempt', Types::INTEGER) ->setNotnull(true); diff --git a/tests/Unit/Store/DoctrineDbalStoreTest.php b/tests/Unit/Store/DoctrineDbalStoreTest.php index dd6af5edc..969c34edf 100644 --- a/tests/Unit/Store/DoctrineDbalStoreTest.php +++ b/tests/Unit/Store/DoctrineDbalStoreTest.php @@ -1310,6 +1310,7 @@ public function testConfigureSchema(): void ->setLength(255) ->setNotnull(true); $table->addColumn('payload', Types::JSON) + ->setPlatformOption('jsonb', true) ->setNotnull(true); $table->addColumn('recorded_on', Types::DATETIMETZ_IMMUTABLE) ->setNotnull(true); @@ -1320,6 +1321,7 @@ public function testConfigureSchema(): void ->setNotnull(true) ->setDefault(false); $table->addColumn('custom_headers', Types::JSON) + ->setPlatformOption('jsonb', true) ->setNotnull(true); $table->setPrimaryKey(['id']); @@ -1362,6 +1364,7 @@ public function testConfigureSchemaWithStringAsAggregateIdType(): void ->setLength(255) ->setNotnull(true); $table->addColumn('payload', Types::JSON) + ->setPlatformOption('jsonb', true) ->setNotnull(true); $table->addColumn('recorded_on', Types::DATETIMETZ_IMMUTABLE) ->setNotnull(true); @@ -1372,6 +1375,7 @@ public function testConfigureSchemaWithStringAsAggregateIdType(): void ->setNotnull(true) ->setDefault(false); $table->addColumn('custom_headers', Types::JSON) + ->setPlatformOption('jsonb', true) ->setNotnull(true); $table->setPrimaryKey(['id']); diff --git a/tests/Unit/Store/StreamDoctrineDbalStoreTest.php b/tests/Unit/Store/StreamDoctrineDbalStoreTest.php index d90085a22..f581a0e9e 100644 --- a/tests/Unit/Store/StreamDoctrineDbalStoreTest.php +++ b/tests/Unit/Store/StreamDoctrineDbalStoreTest.php @@ -1416,6 +1416,7 @@ public function testConfigureSchema(): void ->setLength(255) ->setNotnull(true); $table->addColumn('event_payload', Types::JSON) + ->setPlatformOption('jsonb', true) ->setNotnull(true); $table->addColumn('recorded_on', Types::DATETIMETZ_IMMUTABLE) ->setNotnull(true); @@ -1423,6 +1424,7 @@ public function testConfigureSchema(): void ->setNotnull(true) ->setDefault(false); $table->addColumn('custom_headers', Types::JSON) + ->setPlatformOption('jsonb', true) ->setNotnull(true); $table->setPrimaryKey(['id']); From d844b98aa61c529702a8366fae999e29d44ec5e0 Mon Sep 17 00:00:00 2001 From: Daniel Badura Date: Mon, 6 Jan 2025 22:02:20 +0100 Subject: [PATCH 2/3] Filter null bytes from trace due to anon class. This leads to a crash when using jsonb. --- src/Subscription/ThrowableToErrorContextTransformer.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Subscription/ThrowableToErrorContextTransformer.php b/src/Subscription/ThrowableToErrorContextTransformer.php index 68d147ea4..89ee03769 100644 --- a/src/Subscription/ThrowableToErrorContextTransformer.php +++ b/src/Subscription/ThrowableToErrorContextTransformer.php @@ -70,6 +70,10 @@ private static function transformThrowable(Throwable $error): array */ private static function transformTrace(array $trace): array { + if (array_key_exists('class', $trace) && is_string($trace['class'])) { + $trace['class'] = str_replace("\x00", '', $trace['class']); + } + if (!array_key_exists('args', $trace)) { return $trace; } From 6fa6cfaf8f44180ead9b0246cbce0811861ddde2 Mon Sep 17 00:00:00 2001 From: Daniel Badura Date: Mon, 6 Jan 2025 22:06:48 +0100 Subject: [PATCH 3/3] Fix cs --- src/Subscription/ThrowableToErrorContextTransformer.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Subscription/ThrowableToErrorContextTransformer.php b/src/Subscription/ThrowableToErrorContextTransformer.php index 89ee03769..975efa417 100644 --- a/src/Subscription/ThrowableToErrorContextTransformer.php +++ b/src/Subscription/ThrowableToErrorContextTransformer.php @@ -21,6 +21,7 @@ use function is_resource; use function mb_strlen; use function mb_substr; +use function str_replace; /** * @psalm-import-type Context from SubscriptionError @@ -70,7 +71,7 @@ private static function transformThrowable(Throwable $error): array */ private static function transformTrace(array $trace): array { - if (array_key_exists('class', $trace) && is_string($trace['class'])) { + if (array_key_exists('class', $trace)) { $trace['class'] = str_replace("\x00", '', $trace['class']); }