-
-
Notifications
You must be signed in to change notification settings - Fork 168
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
Initial PostgreSQL support #1933
Conversation
…ion: 7 ERROR: function lower(jsonb) does not exist
…: syntax error at or near user - user is a protected name and need quotation!
@Wieter Awesome, thank you for your work! 👍 I'll keep a close eye on this, and as soon as the |
@bobdenotter Sure no problem! |
Two quick pointers:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shaping up nicely! 👍
I've left some comments/remarks in your changes.
@@ -24,7 +24,7 @@ DATABASE_URL=sqlite:///%kernel.project_dir%/var/data/bolt.sqlite | |||
#DATABASE_URL=mysql://db_user:"db_password"@localhost:3306/db_name | |||
|
|||
# Postgres | |||
#DATABASE_URL=postgresql://db_user:"db_password"@localhost:5432/db_name?serverVersion=11" | |||
#DATABASE_URL=postgresql://db_user:"db_password"@localhost:5432/db_name?serverVersion=11&charset=utf8" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is utf8
not the default? Do we need to explicitly set it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is better to explicitly set here, to force users to think about the charset.
Additionally, it is hardcoded in config/packages/doctrine.yaml
as charset: utf8mb4
, which is fine for MySQL but unsupported in PostgreSQL (for as far as I could find). Setting it in the DATABASE_URL ensures an override to UTF8.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, fair enough! Does Postgres still handle emoji properly, if it doesn't have utf8mb4
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Emoji should work as they are UTF-8, I'll have to test it to know for sure.
From what I understand, MySQL utf-8 is not really full utf-8, it uses 3-bytes per character instead the regular 4byte. I do not know why it was decided, but here lies the origin: https://github.com/mysql/mysql-server/commit/43a506c0ced0e6ea101d3ab8b4b423ce3fa327d0
That's probably why for MySQL utf8mb4 is required. For postgres. utf8 is full utf8, so 4 byte.
something to keep in mind in case of problems -> https://stackoverflow.com/questions/36198847/what-type-should-i-use-to-store-emoji-in-postgresql
@@ -0,0 +1,3 @@ | |||
# Reference extension configuration file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file doesn't have to be committed.
config/packages/doctrine.yaml
Outdated
@@ -31,8 +31,11 @@ doctrine: | |||
alias: App | |||
dql: | |||
string_functions: | |||
JSON_EXTRACT: Bolt\Doctrine\Functions\JsonExtract | |||
CAST: DoctrineExtensions\Query\Mysql\Cast | |||
JSON_EXTRACT: Bolt\Doctrine\Functions\JsonExtract # Why have a duplicate of the Scienta version? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know that it used to be different. I'll check if that's still the case, or if we can fall back to the original. I'll get back to you on that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, looked it up: The Scienta versions (like src/Query/AST/Functions/Mysql/JsonExtract.php
) are specific for SQLite, Mysql or Postgres. Ours extends AbstractJsonFunctionNode
instead, and can be used on either.
src/.preload.php
Outdated
@@ -0,0 +1,5 @@ | |||
<?php |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is not needed. I don't know where it came from, but I occasionally see it popping up on my end as well. Regardless, we can remove it here.
src/Doctrine/JsonHelper.php
Outdated
@@ -23,9 +23,19 @@ class JsonHelper | |||
public static function wrapJsonFunction(?string $where = null, ?string $slug = null, Connection $connection) | |||
{ | |||
$version = new Version($connection); | |||
//print_r($version->getPlatform()['driver_name']); # pgsql | |||
//exit(print($where)); // translations_anyField.value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove commented-out code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, sidenote: instead of print_r
, use dump()
. It's so much nicer. ;-)
https://symfony.com/doc/current/components/var_dumper.html#dump-examples-and-output
templates/helpers/_field_blocks.twig
Outdated
@@ -43,11 +43,14 @@ | |||
{% block extended_fields %} | |||
|
|||
{# Special case for 'select' fields: if it's a multiple select, the field is an array. #} | |||
{# I dont know what is going on here, but field.selectedIds for pgsql showcase/mr-jean-feeney (and others) #} | |||
{# yield field values, NOT integer IDs.. Also, selectedIds does not exists (try dump(field) ) #} | |||
{# TODO: FIX IT, bypassing for now by setting field.id #} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is weird. Might be an unrelated bug, that's coming to light here.. I'll check this one out as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, took a look at this. Not sure why it was failing on your end.. {{ field.id }}
is not a good fix, because it's an entirely different ID than the one(s) we need.
It uses method getSelectedIds
from src/Entity/Field/SelectField.php
, so it really should exist, if the field is a SelectField.
One thing you might try is to explicitly set it to return an array instead of one item:
{% setcontent selected = field.contentType where {'id': field.selectedIds} returnmultiple %}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be fixed now. selectedIds function returned full (string) values, instead of (integer)IDs. So, why not select on field.value: .. instead of field.id: .. :)
Works nicely in postgres, I still have to run a test for the others.
vendor/vaimo/webdriver-binary-downloader/src/Analysers/PlatformAnalyser.php
Outdated
Show resolved
Hide resolved
vendor/vaimo/webdriver-binary-downloader/src/Interfaces/PlatformAnalyserInterface.php
Outdated
Show resolved
Hide resolved
…PHP supports SQLite since version 5.3.0
src/Doctrine/Version.php
Outdated
// JSON supported since SQLite version 3.9.0 | ||
public const SQLITE_WITH_JSON = '3.9.0'; | ||
// PHP supports SQLite since version 5.3.0 | ||
public const PHP_WITH_SQLITE = '5.3.0'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not correct. If we merge this in, Bolt will absolutely assume it has JSON support on installations where it doesn't have it.
Maybe we should change the name of the constant, because it's more "PHP_WITH_SQLITE_THAT_HAS_JSON_SUPPORT_BUNDLED". I've definitely seen this break on PHP 7.2 setups. (Ubuntu 2018.04, if i recall correctly). I'm aware that some installations on lower versions have this bundled, but we can't rely on it. Two examples are listed right above, as "Not OK".
Ideally, we could properly test if we have it, but I have not found a proper way to do that.. If you have a good suggestion, I'm all for it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've written a small test and implemented in a new version (e827a79). Meanwhile I'll leave the (restored) old code commented out until we've fully tested everything. Cleanup is the last step.
@bobdenotter somehow the test fails, while if I manually perform the failed action in the test myself (by going to ../bolt/edit/44 and embedding the video) the correct output is given ("Matched embed" --> Silversun Pickups - Nightlight (Official Video), and Silversun Pickups) For now, I'll leave it like this and work on something differently. sidenote: it would be nice if a test can be run for database-specific implementation, i.e. postgres vs mysql. |
Travis is extra special stubborn on this one! I'll fix the conflict and Travis checks on this PR, when i have a bit of time.. (i expect tomorrow!) |
… ERROR: invalid input syntax for integer: "a voluptas possimus aut libero doloremque."") in "helpers/_field_blocks.twig".
It seems that for PostgreSQL on my side everything is working nicely, but other users should help test the full functionality as well, as bugs might be hidden. |
It looks like some of the tests are failing, because of the JSON check now. See: https://travis-ci.com/github/bolt/core/jobs/396066538 I'll see if I can reproduce that on my end! |
@Wieter Tests are passing now!
That sounds like the prudent thing to do! Let's roll with that. Once again, thank you for your contribution on this feature! |
@bobdenotter You're welcome! |
@@ -21,7 +21,7 @@ class FieldTranslation implements TranslationInterface | |||
*/ | |||
private $id; | |||
|
|||
/** @ORM\Column(type="json") */ | |||
/** @ORM\Column(type="json", options={"jsonb": true}) */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been working to get bolt compatible with PostgreSQL.
From my end everything seems to be working fine, good enough to be used for the purpose at hand (running at FreeBSD 12.1 \w PostgreSQL v11.6).
A quick check from my side on usage of MySQL and SQLite did not show serious problems after fixing a CAST specifically for MySQL (2707e71).
There might be some minor bugs still around (hence the WIP), that need user testing. For example something strange with the template used (bypassed in c68e6d5) where a selectfield does not have an .selectedIds (integer). Somehow sqlite & mysql have no problems with that, but postgres is more strict. There may arise more of those issues.