-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fixed missing schema on MySQL table names #7128
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
base: 4.3.x
Are you sure you want to change the base?
Conversation
…d the whole table as changed instead of the true changes.
…d the whole table as changed instead of the true changes.
Looks like your change broke a lot of existing tests and you didn't add any new tests that would reproduce the issue that you're trying to solve. Are you planning to continue your work? |
Hi, I was hoping for some feedback whether the change is fine this way in general, as I do not know the doctrine code well enough. But I can try to resolve the unit tests first next Monday, if you prefer. |
…d the whole table as changed instead of the true changes.
…d the whole table as changed instead of the true changes.
…d the whole table as changed instead of the true changes.
…d the whole table as changed instead of the true changes.
I got the tests fixed now. As I prepend the schema to the table name only for MySQL (I don't know if that makes sense for other engines as well), I added some ifs to the tests, so in case of MySQL the schema is prepended in the test as well. For the tests/Functional/Schema/SchemaManagerFunctionalTestCase.php I overwrite the problematic tests now inside tests/Functional/Schema/MySQLSchemaManagerTest.php with a version that prepends the schema. As for the change in src, another option would be instead of doing the concat on the database it could be done in the _getPortableTableDefinition() method instead, if that is considered cleaner. But I decided against that, as the method is marked as deprecated. |
The DBAL doesn't support schemas on MySQL since it's a synonym for databases. Furthermore, on those platforms where the DBAL supports schemas (PostgreSQL, SQL Server), the current schema name is omitted from the introspected name. Thus, if the model defines the table name as What makes you think that this change needs to be made in the DBAL? |
We have a project with MySql that has tables on different schemata (or tables in different tables, if schema and table is the same thing). schemaA.table1 On the entities we have: And that is what is not working. For if I now generate the migration using Also using ORM\Table(name: 'schemaA.table1') leads to the same error. The patch I provided fixes this. and generates a correct migration, that only contains the one change I did in the entity. I believe that this is only an issue when a project uses more than one schema. If everything is inside the default schema, then it is no issue and it is enough to say 'table1', but in our case where there are different schemas inside a single project the schema name needs to be prepended to the table name. |
This is not supported. The DBAL can introspect only a single MySQL database (which is a synonym for schema in MySQL) at a time. See the code: dbal/src/Schema/MySQLSchemaManager.php Lines 345 to 351 in a1f4d02
|
Then why not support it? I understand that you can not support it the way you support schemas on other engines. But to me it looks like all that is needed, is to add the schema to the tables names like in this pull request. Then it could be supported. At least in the migrations:diff it works then. I don't have enough overview over the doctrine/dbal to know where else stuff would be affected. |
Summary
The schema was missing on the table name for MySQL.
Because of that "bin/console doctrine:migrations:diff" did not generate correct diffs and always detected the whole table as changed.
See:
doctrine/migrations#1460