mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Virtual columns will always have schema changes when checked with orm:schema-tool:update
#6909
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @villermen on GitHub (Jan 19, 2022).
Bug Report
Summary
A virtual column defined via the new capabilities of v2.11 will always have changes when checked with the
orm:schema-tool:updateconsole command.How to reproduce
Consider the following mapping on a MySQL 8 database:
Running
orm:schema-tool:update --dump-sql --forceconsecutively will always yield the change:Expected behavior
Expected behavior is to either compare the column definition from the database with the schema, or ignore it completely and only check column existence when it has a custom definition. Both situations would lead to the changes being generated only once.
@beberlei commented on GitHub (Jan 19, 2022):
What version of DBAL are you using? Older versions will always cause a change with
columnDefinition, DBAL 3.3 I believe is the first version that checks this differently.@villermen commented on GitHub (Jan 20, 2022):
I'm currently on v2.13.7 so that might explain it. I'll try (force-)updating it to check if it happens in the latest version.
@villermen commented on GitHub (Jan 21, 2022):
@beberlei I've managed to update to doctrine/dbal 3.3.0. The result for the "website" example is still the same. In addition, another column manually defined as
ENUMthat previously existed now exposes the same behavior:orm:schema-tool:update --dump-sql --force && orm:schema-tool:update --dump-sql --force@derrabus commented on GitHub (Jan 21, 2022):
This sounds like the kind of problem @bcremer tried to tackle with #9410.
@bcremer commented on GitHub (Jan 21, 2022):
@villermen For your
$statuscolumn try settinglength=0. That fixed the schema diff for us.@villermen commented on GitHub (Jan 21, 2022):
Adding
length: 0to the attribute on$statusindeed removed it from the schema diff. That doesn't make much sense to me, but I can work with that =)@bcremer commented on GitHub (Jan 21, 2022):
@villermen
I would advice to step into
\Doctrine\DBAL\Schema\Comparator::diffColumnto find out what property of the column is different.In case of the
enumyou will observe that thelengthproperty is different so it can be adjusted in the Entity accordingly.That might help you to find the different property in your generated column case.
On a related note:
It would be super helpful to have a debug/verbose mode for the
\Doctrine\DBAL\Schema\Comparatorthat logs what parts of the table/column is different. One should create a PR for that 🥸@villermen commented on GitHub (Jan 22, 2022):
@bcremer Thanks for the pointer!
Looks like it triggered completely unrelated to
columnDefinition. Instead it's due to a difference in thenotnullproperty. And fair enough, the column is generated as nullable when using the definitionVARCHAR(255) GENERATED ALWAYS AS ('foo') VIRTUALso it's completely right too!I've fixed it by changing
columnDefinition(and the database schema) to:to bring it in line with the
Columnattribute, which is not null by default. I could've also fixed it by changing the attribute tonullable: true, but that made less sense considering the column is neverNULL.Having to figure it out like this is pretty cumbersome, so I'm all in favor of the debug/verbose mode suggested by @bcremer. But this issue is definitely invalid because it has nothing to do with the column being virtual.
Thanks for your help!
@bcremer commented on GitHub (Jan 31, 2022):
Unfortunately the new https://github.com/doctrine/dbal/releases/tag/3.3.1 release and https://github.com/doctrine/dbal/pull/5220 makes it impossible to use
columnDefinitionto validate enum types that are mapped to varchars like described in https://www.doctrine-project.org/projects/doctrine-orm/en/2.11/cookbook/mysql-enums.html#solution-1-mapping-to-varchars.@derrabus commented on GitHub (Jan 31, 2022):
@bcremer: doctrine/dbal#5223