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

Pg schema support #159

Merged
merged 11 commits into from
Jun 4, 2018
Merged

Pg schema support #159

merged 11 commits into from
Jun 4, 2018

Conversation

ghettovoice
Copy link
Contributor

This pull request adds support of multi schema events stores and projection for PostresSQL implementation #157 .
Summary (only Pg related classes):

  • Event streams table and projections table name can be defined with custom DB schema.
  • String before first dot in stream name treated as DB schema, so stream auto generated table will be created in custom schema.
    I added additional tests to clarify the new behaviour

Copy link
Member

@prolic prolic left a comment

Choose a reason for hiding this comment

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

I really like this idea. Can we have this for mysql / mariadb as well?

*/
private function quoteIdent(string $tableName): string
{
return array_reduce(explode('.', $tableName), function ($result, $part) {
Copy link
Member

Choose a reason for hiding this comment

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

that's really hard to read, can we simplify that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ready

*/
private function extractSchema(string $identifier): ?string
{
$parts = array_map(function ($part) {
Copy link
Member

Choose a reason for hiding this comment

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

same here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ready

@@ -0,0 +1,12 @@
CREATE SCHEMA IF NOT EXISTS custom;
Copy link
Member

Choose a reason for hiding this comment

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

I don't know if "custom" is a good default, why not "prooph" 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ready

@ghettovoice
Copy link
Contributor Author

ghettovoice commented May 25, 2018

Thank you for review! I'll fix it.
As I know in MySQL/MariaDB schema represents another database and probably with another connection configuration. Currently I don't know how to deal with this. May be connection pool or something else..

@prolic
Copy link
Member

prolic commented May 25, 2018 via email

@ghettovoice
Copy link
Contributor Author

Can you also please make sure that existing app configurations are not
broken and the use of additional schema is optional?

Tables for event streams and projections will be created in custom schema only if $eventStreamsTable, $projectionsTable and stream name will contain dot and only for Postgres driver. I highly doubt anyone is using a point in these variables intentionally right now, so there should't be problems.

@prolic
Copy link
Member

prolic commented May 25, 2018

May I asked why it's a requirement to have schemas in your project?

@prolic prolic self-assigned this May 25, 2018
@ghettovoice
Copy link
Contributor Author

ghettovoice commented May 25, 2018

Sure, it just an our internal convention: not to create all at public schema (pg extensions usually creates here functions, tables and etc.), each module adds tables, functions and etc in it's own schema, so it easy to search in relatively large db

@prolic
Copy link
Member

prolic commented May 25, 2018

👍 I'll recheck this PR this weekend.

@ghettovoice
Copy link
Contributor Author

Ok , thank you

@coveralls
Copy link

coveralls commented May 26, 2018

Coverage Status

Coverage increased (+0.2%) to 90.4% when pulling c3e925c on ghettovoice:pg-schema-support into af6d698 on prooph:master.

@prolic
Copy link
Member

prolic commented May 28, 2018

I'll have to make some more testing, I don't like this quoting method, I hope to come up with a faster solution. Currently really busy.

@prolic
Copy link
Member

prolic commented May 30, 2018

@ghettovoice I think I found a much faster quoting-function, see https://3v4l.org/7bCYi

@ghettovoice
Copy link
Contributor Author

@prolic I see 👍
My implementation uses two functions because of needless schema extraction in generateTableName
method e1b9a7b#diff-6895a5b565f06c33a1404ad8257df13e.
May be here should be another solution for persistence strategy?

@prolic
Copy link
Member

prolic commented May 30, 2018 via email

@ghettovoice
Copy link
Contributor Author

Ok, I'll try to make this before weekends

re-implement `quoteIdent` and `splitIdent` according to https://3v4l.org/7bCYi and https://3v4l.org/QcCCl
to increase quoting performance.
'_' . sha1($streamName->toString()),
]));
if ($schema) {
$schema . '.' . $table;
Copy link
Member

Choose a reason for hiding this comment

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

That doesn't make any sense

'_' . sha1($streamName->toString()),
]));
if ($schema) {
$schema . '.' . $table;
Copy link
Member

Choose a reason for hiding this comment

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

same here

'_' . sha1($streamName->toString()),
]));
if ($schema) {
$schema . '.' . $table;
Copy link
Member

Choose a reason for hiding this comment

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

and again, maybe you should add a unit test for this method

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, sorry! You are right. I thought that the test already exists

- fix generateTableName method in Postgres related persistence strategy classes
- add tests for generateTableName method
@ghettovoice
Copy link
Contributor Author

Now it's done. Yesterday I made it late at night

* @param string $ident
* @return string[]
*/
private function splitIdent(string $ident): array
Copy link
Member

Choose a reason for hiding this comment

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

On reviewing I found that the returned table name is not used at all. So why not change the signature then? Something like private function schema(string $ident): ?string. It either returns the schema or null

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was private function extractSchema(string $ident): ?string in the very first version.
I'll fix this

… - an simplified extraction of pg schema from string
Copy link
Member

@prolic prolic left a comment

Choose a reason for hiding this comment

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

GOOD WORK! thanks you

@prolic prolic merged commit 2eb70f0 into prooph:master Jun 4, 2018
@ghettovoice
Copy link
Contributor Author

Thank you for your time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants