-
Notifications
You must be signed in to change notification settings - Fork 177
Initial PostgreSQL support #1933
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
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
6b700c7
Freebsd-Installable
WellinqScience1337 16ef756
Fixtures can be loaded (fix of #1905)
WellinqScience1337 22dafba
Bypassing lower-case search bug: BUG SQLSTATE[42883]: Undefined funct…
WellinqScience1337 b9934e6
Missing assets due to wrong order in README
WellinqScience1337 b070b4a
Bugfix for admin login to log. SQLSTATE[42601]: Syntax error: 7 ERROR…
WellinqScience1337 ed7396d
Fixed RandomSelect for records in PostgreSQL
WellinqScience1337 ad555b2
Ran Code Style checking / Static Analysis
WellinqScience1337 f85fd41
Fixed search function for PostgreSQL and jsonb
WellinqScience1337 2707e71
Fixed the search/CAST for MySQL - JSON is already considered TEXT in …
WellinqScience1337 c68e6d5
found strange bug, partial fix
WellinqScience1337 4729e76
Minor cleanup and fix
WellinqScience1337 4ac9bb8
Lower is breaking more than gaining
WellinqScience1337 d9c2312
Fully postgres/mysql compatible
WellinqScience1337 d3b2e2b
Some cleanup
WellinqScience1337 fea65d4
Further cleanup & fix of showcase editability in postgres
WellinqScience1337 cc659b2
style fixes
WellinqScience1337 f873aef
Fix search bug SQLite that appeared since inclusion in JSONwrapper - …
WellinqScience1337 d7ab4a0
Trying to get test to pass for SQLite in Docker
WellinqScience1337 e827a79
improved sqlite json checking
WellinqScience1337 3bbb957
Merge branch 'master' into development-postgres
bobdenotter 39490e4
cleanup
WellinqScience1337 89fa4b7
Fix for returned bug: SQLSTATE[22P02]: Invalid text representation: 7…
WellinqScience1337 0ec56d4
Don't overwrite `$searchTerm`
bobdenotter 0d0f50d
Don't use `Bolt\Doctrine\Version`
bobdenotter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bolt\Doctrine\Query; | ||
|
||
use Doctrine\ORM\Query\AST\Functions\FunctionNode; | ||
use Doctrine\ORM\Query\Lexer; | ||
use Doctrine\ORM\Query\Parser; | ||
use Doctrine\ORM\Query\SqlWalker; | ||
|
||
class Cast extends FunctionNode | ||
{ | ||
/** @var \Doctrine\ORM\Query\AST\PathExpression */ | ||
protected $first; | ||
/** @var string */ | ||
protected $second; | ||
/** @var string */ | ||
protected $backend_driver; | ||
|
||
public function getSql(SqlWalker $sqlWalker): string | ||
{ | ||
$backend_driver = $sqlWalker->getConnection()->getDriver()->getName(); | ||
|
||
// test if we are using MySQL | ||
if (mb_strpos($backend_driver, 'mysql') !== false) { | ||
// YES we are using MySQL | ||
// how do we know what type $this->first is? For now hardcoding | ||
// type(t.value) = JSON for MySQL. JSONB for others. | ||
// alternatively, test if true: $this->first->dispatch($sqlWalker)==='b2_.value', | ||
// b4_.value for /bolt/new/showcases | ||
if ($this->first->dispatch($sqlWalker) === 'b2_.value' || | ||
$this->first->dispatch($sqlWalker) === 'b4_.value') { | ||
return $this->first->dispatch($sqlWalker); | ||
} | ||
} | ||
|
||
return sprintf('CAST(%s AS %s)', | ||
$this->first->dispatch($sqlWalker), | ||
$this->second | ||
); | ||
} | ||
|
||
public function parse(Parser $parser): void | ||
{ | ||
$parser->match(Lexer::T_IDENTIFIER); | ||
$parser->match(Lexer::T_OPEN_PARENTHESIS); | ||
$this->first = $parser->ArithmeticPrimary(); | ||
$parser->match(Lexer::T_AS); | ||
$parser->match(Lexer::T_IDENTIFIER); | ||
$this->second = $parser->getLexer()->token['value']; | ||
$parser->match(Lexer::T_CLOSE_PARENTHESIS); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. |
||
protected $value = []; | ||
|
||
public function getId(): ?int | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
ascharset: 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