Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use jsonb when using postgresql #671

Draft
wants to merge 3 commits into
base: 3.8.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Store/DoctrineDbalStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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']);
Expand Down
2 changes: 2 additions & 0 deletions src/Store/StreamDoctrineDbalStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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']);
Expand Down
1 change: 1 addition & 0 deletions src/Subscription/Store/DoctrineSubscriptionStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/Subscription/ThrowableToErrorContextTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -56,6 +57,10 @@
*/
private static function transformTrace(array $trace): array
{
if (array_key_exists('class', $trace)) {
$trace['class'] = str_replace("\x00", '', $trace['class']);

Check warning on line 61 in src/Subscription/ThrowableToErrorContextTransformer.php

View workflow job for this annotation

GitHub Actions / Mutation tests on diff (locked, 8.3, ubuntu-latest)

Escaped Mutant for Mutator "UnwrapStrReplace": --- Original +++ New @@ @@ private static function transformTrace(array $trace) : array { if (array_key_exists('class', $trace)) { - $trace['class'] = str_replace("\x00", '', $trace['class']); + $trace['class'] = $trace['class']; } if (!array_key_exists('args', $trace)) { return $trace;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any better suggestions @DavidBadura ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't that be its own PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now, this is not doing any harm. When we adjust the table type to jsonb Postgres checks if the json is valid and doesn't like null bytes in there.

I don't think that this must be in a separate bugfix PR but I could extract it. The only thing is if the user already has null bytes in the table. Then he would need to remove them. Or do you have a case in mind?

}

if (!array_key_exists('args', $trace)) {
return $trace;
}
Expand Down
4 changes: 4 additions & 0 deletions tests/Unit/Store/DoctrineDbalStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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']);
Expand Down Expand Up @@ -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);
Expand All @@ -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']);
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/Store/StreamDoctrineDbalStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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']);
Expand Down
Loading