-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
DBAL-669 - Update SQL generated by the schema tool will also create schemas #444
Conversation
@chrisramakers ping |
@Ocramius What about Create SQL Listener? Does he create the schema as well? |
This is not the correct approach, as we don't create schemas as well when doing |
Hm, it seems we have changed that some time ago, reopening to evaluate |
@beberlei we had some schema creation support in platforms in master since @ea0254731d42c94ccd9ebfba48f72adbafbe5232 dbal/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php Lines 142 to 147 in ea02547
2.4.1 does not have this |
Problem in this PR:
|
@beberlei I think this is a good idea. I was very confused lately about namespaces in table objects. If you retrieve a table from database with schema manager you get different objects depending on whether you specify the full qualified table name including namespace or not. // Schema manager
$qualifiedTable = $sm->listTableDetails('namespace.table');
$unqualifiedTable = $sm->listTableDetails('table'); // automatically uses platform's default namespace
$qualifiedTable->getNamespaceName(); // returns "namespace"
$unqualifiedTable->getNamespaceName() // returns null
$this->assertEquals($qualifiedTable, $unqualifiedTable); // false IMO the above comparison should be true. I don't know the background of why it was implemented this way. |
@beberlei @Ocramius How does this patch solve DBAL-669? The hardcoded schema names in the postgresqlPlatform file continue to be an issue since these "existing" schema's should be retrieved from the live database, not based on hardcoded strings ... https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php#L659-L665 |
@chrisramakers can those schemas actually be changed? (didn't check) |
What do you mean? Those schema's don't need to be changed. The If I'd call this method with "data" as argument What needs to be done here imho is replace the
PS: there might be some naming confusion between a database schema describing tables and a postgresql schema being a container for tables, views, ... |
@chrisramakers I was asking if postgres schemas You're right on this PR not solving the problem of DDC-669, where different schemas are being created, but the schema only does introspection on the tables in the default/public schema afaik (doesn't check other schemas for table existence), so the PR should at least generate the correct diff. I'll mark the PR as WIP since it obviously isn't ready for merging. |
@Ocramius: at least for public I can say no it's not enforced. You can freely delete it. |
the |
@Ocramius We have to implement the namespaces introspection suggested by @beberlei in order for the schema tool to calculate the differences in namespaces correctly. Also IMO |
@Ocramius @chrisramakers Okay the implementation is finished now from my side. Can you please review. |
@@ -30,7 +29,7 @@ | |||
/** | |||
* Abstract Visitor with empty methods for easy extension. | |||
*/ | |||
class AbstractVisitor implements Visitor | |||
class AbstractVisitor implements Visitor, NamespaceVisitor |
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.
@beberlei you mentioned that the "Visitor" is used here. Is it such a big deal that we cannot simply add the NamespaceVisitor
to the Visitor
interface instead? Wouldn't a BC break here be ok?
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.
adding new methods in an interface is a BC break, as classes implementing the interface now throw a fatal error because of the missing method
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.
Yes, and I was saying that this interface is not commonly used...
Needs a rebase, but IMO it is good to be merged. @deeky666 thoughts? |
@Ocramius yep it can be merged IMO. Do I have to rebase? |
@deeky666 if you can, then I'll merge |
Updating a schema should introduce also schema creation statements in the generated SQL
DBAL-669 - Update SQL generated by the schema tool will also create schemas
Follow up on this one, the fix is in use now but the problem stays the same. In our application we use the What should be done is use the connection to first check if the namespace exists, if not add the "CREATE NAMESPACE" query, else only add the appropriate table queries. |
@chrisramakers I think you are just using the API wrong. // declare $platform
// declare $schemaManager
$offlineSchema = new \Doctrine\DBAL\Schema\Schema();
// declare $offlineSchema
$onlineSchema = $schemaManager->createSchema();
$comparator = new \Doctrine\DBAL\Schema\Comparator();
$schemaDiff = $comparator->compare($onlineSchema, $offlineSchema);
if ($schemaDiff) {
$sql = $schemaDiff->toSql($platform);
}
// execute SQL |
@deeky666 the thing is that i'm not updating any schema's. The app we built requires us to create tables for certain entities (not doctrine entities) in our app. For example when a new "Car"-type is added a "Cars" table is created (very simplistic). This is a slightly altered snippet of the code we currently use
I think the problem is related to the fact i'm not using the schemaManager to create the table but rather execute the raw queries. I've just tried and used the active SchemaManager from the DBAL Connection to create the table and the code below seems to work as expected.
|
@chrisramakers yes you use the wrong API for your use-case. The second approach is the proper one. If you just want to create a single table, use the schema manager. |
DBAL-669 - Updating a schema should introduce also schema creation statements in the generated SQL