From dd53bd187fb30db150cc8dc2096826f122a4d0ad 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 28a9a977b..1acc5e6c5 100644 --- a/src/Store/DoctrineDbalStore.php +++ b/src/Store/DoctrineDbalStore.php @@ -331,6 +331,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); @@ -341,6 +342,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 5e4bb3b91..6c1487046 100644 --- a/src/Store/StreamDoctrineDbalStore.php +++ b/src/Store/StreamDoctrineDbalStore.php @@ -399,6 +399,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); @@ -409,6 +410,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 3ef9d2355..c30d56022 100644 --- a/tests/Unit/Store/DoctrineDbalStoreTest.php +++ b/tests/Unit/Store/DoctrineDbalStoreTest.php @@ -1309,6 +1309,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); @@ -1319,6 +1320,7 @@ public function testConfigureSchema(): void ->setNotnull(true) ->setDefault(false); $table->addColumn('custom_headers', Types::JSON) + ->setPlatformOption('jsonb', true) ->setNotnull(true); $table->setPrimaryKey(['id']); @@ -1361,6 +1363,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); @@ -1371,6 +1374,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 00a56a491..6357eb466 100644 --- a/tests/Unit/Store/StreamDoctrineDbalStoreTest.php +++ b/tests/Unit/Store/StreamDoctrineDbalStoreTest.php @@ -1404,6 +1404,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); @@ -1414,6 +1415,7 @@ public function testConfigureSchema(): void ->setNotnull(true) ->setDefault(false); $table->addColumn('custom_headers', Types::JSON) + ->setPlatformOption('jsonb', true) ->setNotnull(true); $table->setPrimaryKey(['id']); From fac8d7c1f5bdbafdc3675ee38df31d7ab7437226 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 96f1571b8..f9b2f5e1e 100644 --- a/src/Subscription/ThrowableToErrorContextTransformer.php +++ b/src/Subscription/ThrowableToErrorContextTransformer.php @@ -56,6 +56,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 f6d552046618d18e109fb4b795edf5275d68c761 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 f9b2f5e1e..f4d60da0e 100644 --- a/src/Subscription/ThrowableToErrorContextTransformer.php +++ b/src/Subscription/ThrowableToErrorContextTransformer.php @@ -13,6 +13,7 @@ use function is_object; use function is_resource; use function sprintf; +use function str_replace; /** * @psalm-import-type Context from SubscriptionError @@ -56,7 +57,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']); }