-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Adds default namespace to schema. #2490
Conversation
Some databases supports namespaces and has default one. For example Postgres has default "public". When schema created from classes, which has table names without namespaces, but this namespace is assumed, we should add it explicitly, if it not exists yet. It will help in diffs between real DB and config shemas. This is 1st part of fix DBAL-1168
Next step will be to add this visitor to the end of
|
*/ | ||
class AddDefaultNamespace extends AbstractVisitor | ||
{ | ||
|
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.
Docblock
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.
What wrong with 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.
It's missing :-)
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.
It's missing :-)
What is missing?? There is top comment and class comment. What is "docblock" then? Can you provide an example?
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.
/**
* @var AbstractPlatform
*/
private $platform;
Could be added by default, but then act as no-op if the platform doesn't support schemas? |
I also thought about this option first, but then deside to do the check outside to give more readability at the place where it should be added at But if your experience tells you to move it inside -- let's move it inside. It will become more reusable then. |
If it's not a no-op when the platform does not support schemas, then it will become a setup issue for most users, making working apps not portable. IMO, it should be done inside the visitor. |
Ok, I will rework it. Pls not merge many commits, I will rebase em after approve. Regarding docblock. What bad there? Bad |
* It will help in diffs between real DB and config shemas. | ||
* | ||
* @author Alexander Ustimenko <a@ustimen.co> | ||
* @since 2.5 |
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.
2.6
--- Branch will be rebased after approve --- Merge branch 'master' into DBAL-1168-add-default-schema-name
Pls give me know when you think it will be ready for merge -- I will rebase it. Or you can rebase it on master and squash all in one commit. |
@deeky666 when approximately will you plan to review? |
{ | ||
|
||
/** | ||
* @var \Doctrine\DBAL\Platforms\AbstractPlatform |
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 class is already imported, so you should use @var AbstractPlatform
instead.
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.
Not sure. In other classes in same directory also fully qualified names used. So I decided to leave it as it was here before.
*/ | ||
class AddDefaultNamespace extends AbstractVisitor | ||
{ | ||
|
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.
Please, remove surplus LF.
--- Branch will be rebased after approve --- Merge branch 'master' into DBAL-1168-add-default-schema-name
There's waaaaaay older stuff around here. If @deeky666 didn't have time to check it, he's evidently busy at the moment. |
No, I cannot. He's pretty much the gatekeeper, and I talk with him from On 8 Nov 2016 8:25 a.m., "Alexander Ustimenko" notifications@github.com @Ocramius https://github.com/Ocramius As I see, @deeky666 Do you know him? Is he alive/healthy? Can you assign someone else from 31 people that are in Doctrine's members — Reply to this email directly, view it on GitHub |
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.
Status: Needs work.
*/ | ||
public function acceptSchema(Schema $schema) | ||
{ | ||
if (!$this->platform->supportsSchemas()) { |
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.
Please, respect Doctrine CS.
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.
@phansys which concrete point of them?
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'm guessing it's this one? doctrine/coding-standard#7
Logical NOT operators (!) MUST have leading and trailing spaces
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.
Holy shit, pettifoggers )) I will README https://github.com/doctrine/coding-standard and will come back to you soon.
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.
@teohhanhui it's an opened PR, not yet merged.
I will not change it.
I ran phpcs and it found tons of ERRORs in other files in same directory and nothing in mine. So this is not serious.
$ phpcs --standard=/home/garex/.composer/vendor/doctrine/coding-standard/Doctrine lib/Doctrine/DBAL/Schema/Visitor/*
FILE: ...thub/dbal/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php
--------------------------------------------------------------------------------
FOUND 3 ERROR(S) AND 1 WARNING(S) AFFECTING 4 LINE(S)
--------------------------------------------------------------------------------
78 | WARNING | Line exceeds 120 characters; contains 127 characters
104 | ERROR | Equals sign not aligned with surrounding assignments; expected
| | 4 spaces but found 1 space
105 | ERROR | Equals sign not aligned with surrounding assignments; expected
| | 8 spaces but found 1 space
106 | ERROR | Equals sign not aligned with surrounding assignments; expected
| | 5 spaces but found 1 space
--------------------------------------------------------------------------------
UPGRADE TO PHP_CODESNIFFER 2.0 TO FIX ERRORS AUTOMATICALLY
--------------------------------------------------------------------------------
FILE: ...github/dbal/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php
--------------------------------------------------------------------------------
FOUND 3 ERROR(S) AFFECTING 3 LINE(S)
--------------------------------------------------------------------------------
100 | ERROR | Equals sign not aligned with surrounding assignments; expected 3
| | spaces but found 1 space
101 | ERROR | Equals sign not aligned with surrounding assignments; expected 6
| | spaces but found 1 space
113 | ERROR | Equals sign not aligned with surrounding assignments; expected 6
| | spaces but found 1 space
--------------------------------------------------------------------------------
UPGRADE TO PHP_CODESNIFFER 2.0 TO FIX ERRORS AUTOMATICALLY
--------------------------------------------------------------------------------
FILE: ...ome/garex/src/github/dbal/lib/Doctrine/DBAL/Schema/Visitor/Graphviz.php
--------------------------------------------------------------------------------
FOUND 10 ERROR(S) AND 2 WARNING(S) AFFECTING 6 LINE(S)
--------------------------------------------------------------------------------
42 | ERROR | Missing space before the string concatenation operator ".".
42 | ERROR | Missing space after the string concatenation operator ".".
43 | ERROR | Missing space before the string concatenation operator ".".
43 | ERROR | Missing space after the string concatenation operator ".".
60 | ERROR | Missing space before the string concatenation operator ".".
60 | ERROR | Missing space after the string concatenation operator ".".
90 | WARNING | Line exceeds 120 characters; contains 182 characters
99 | WARNING | Line exceeds 120 characters; contains 181 characters
100 | ERROR | Missing space before the string concatenation operator ".".
100 | ERROR | Missing space after the string concatenation operator ".".
100 | ERROR | Missing space before the string concatenation operator ".".
100 | ERROR | Missing space after the string concatenation operator ".".
--------------------------------------------------------------------------------
UPGRADE TO PHP_CODESNIFFER 2.0 TO FIX ERRORS AUTOMATICALLY
--------------------------------------------------------------------------------
FILE: ...github/dbal/lib/Doctrine/DBAL/Schema/Visitor/RemoveNamespacedAssets.php
--------------------------------------------------------------------------------
FOUND 4 ERROR(S) AFFECTING 4 LINE(S)
--------------------------------------------------------------------------------
61 | ERROR | Expected 0 spaces after opening bracket; 1 found
71 | ERROR | Expected 0 spaces after opening bracket; 1 found
84 | ERROR | Expected 0 spaces after opening bracket; 1 found
90 | ERROR | Expected 0 spaces after opening bracket; 1 found
--------------------------------------------------------------------------------
UPGRADE TO PHP_CODESNIFFER 2.0 TO FIX ERRORS AUTOMATICALLY
--------------------------------------------------------------------------------
FILE: .../src/github/dbal/lib/Doctrine/DBAL/Schema/Visitor/SchemaDiffVisitor.php
--------------------------------------------------------------------------------
FOUND 8 ERROR(S) AFFECTING 8 LINE(S)
--------------------------------------------------------------------------------
41 | ERROR | Visibility must be declared on method "visitOrphanedForeignKey"
48 | ERROR | Visibility must be declared on method "visitChangedSequence"
55 | ERROR | Visibility must be declared on method "visitRemovedSequence"
60 | ERROR | Visibility must be declared on method "visitNewSequence"
65 | ERROR | Visibility must be declared on method "visitNewTable"
71 | ERROR | Visibility must be declared on method "visitNewTableForeignKey"
76 | ERROR | Visibility must be declared on method "visitRemovedTable"
81 | ERROR | Visibility must be declared on method "visitChangedTable"
--------------------------------------------------------------------------------
UPGRADE TO PHP_CODESNIFFER 2.0 TO FIX ERRORS AUTOMATICALLY
--------------------------------------------------------------------------------
Merge remote-tracking branch 'doctrine/master' into DBAL-1168-add-default-schema-name
@garex sorry for the delay. Haven't been around here last year very much. The concern I have about the "default schema" topic how it is implemented in DBAL (via platforms) is that there really is no "fixed" default schema for probably all the vendors supporting schemas. In PostgreSQL for example you can configure the default schema via its search path, Oracle uses the user that connects as the default schema and I suppose others like SQL Server let the user define the default schema, too. All that happens at runtime so having the platforms return a default schema name is quite of a misconception IMO and should even be deprecated. Also the term "schema" and "namespace" as used in Doctrine is rather ambiguous and not clearly defined. IMO "schema" / "namespace" is a concept that groups database objects like tables, indexes etc. So in MySQL for example this concept would translate to "database". So what we have to do (rather than relying on the platforms default schema name) is evaluate the runtime default schema name and add it to the table name when creating the schema form entity classes. The problem IMO is this line. While assuming that So maybe this needs reevaluation. I don't think this solution is the best we can achieve. |
Hi @deeky666 , nice to see you here. I think it will be overcomplicated fix that will be merged may be in next century. Current solution is not best, but it will fix issue in 99% of cases. How often you see users, who change default schema names or default root name? I think it's a rare case. Anyway if you want more ideal solution for 1% of users, it could be later improved by evaluating from live connection during schema diff. But as I assume it will be low-priority task that will be never done. |
@garex I get your point and you are possibly completely right about that it fixes the issue for "99%" of the users but I think we already have the possibility to fix this more properly without a lot of effort. The schema manager already has an API for evaluating the runtime schema. The reason I don't like the solution is that it pushes a misconception even further into the wrong direction. Also adding a special visitor for this makes us having to maintain that API which in fact IMO is just a workaround that doesn't even fix all edge cases. Speaking of edge cases, there is murphy's law and from my experience the "1%" edge cases will be requested to be fixed soon after that. So introducing this solution will only put us more into the corner.
That would save us an additional visitor, if I am not completely wrong. |
@deeky666 I will research it and ping back here. |
@deeky666 any plans on solving this? |
@antonmedv you can try to fix it yourself. @deeky666 is only as a reviewer here, not implementer/fixer. |
|
Adds default namespace to schema
Some databases supports namespaces and has default one. For example Postgres has default "public".
When schema created from classes, which has table names without namespaces, but this namespace is assumed, we should add it explicitly, if it not exists yet.
It will help in diffs between real DB and config shemas.
The visitor is skipping platforms that don't support schemas.
This is 1st part of fix DBAL-1168 #1110