-
-
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
SchemaTool doesn't correctly recognise the current DB state #5661
Comments
Making the changes that are not there is likely caused by the changes not being detected correctly, which is by design and documented. Do you believe it's unrelated? Can you think of a way to address this issue? |
You have a point there; although the docs make it sound that the change detection may fail, not is guaranteed to fail somehow. What to do about it? If the change detection is broken when there is a custom column definition, (1) don't even attempt to detect changes, (2) always consider the current Even without (3) in place, the worst-case scenario is there will be a useless I'm curious what's the reason for allowing the change detection to run if it's known to be broken? |
No idea. If you believe it's important to get it fixed or improved and you know what to do, please file a pull request and we could discuss the needed changes more substantively. |
I'll wait for a reply of someone who has an idea. Don't get me wrong, I think if a seemingly-broken feature made it to the mainline branch, it probably has some purpose there. I may be missing it. Proposing changes when oblivious is not the way I want to help. Thanks for your responses, I appreciate it. |
In my understanding, this feature was introduced to mitigate the inability of the DBAL to declare an arbitrary column on any of the supported platforms (which is an inherent property of any higher-level abstraction compared to the lower-level abstraction that it's built on). This feature is broken by design. because it breaks that barrier of its own abstraction and gives the end-user direct access to the underlying API. |
I don't think it's a bad thing to give power users the power to do things that have the potential to break something. I think the design fault here is that DBAL tries to still "help" the user, even though it should go almost completely out of the way, especially if the column is marked non-insertable, non-updateable, and always auto-generated. My specific use case here is to use fulltext search on various psql tables. I don't want to offload the search functionality to another database. For this I'm trying to utilise an auto-generated column as per the If you say the Adding a custom type? That was my initial approach, but then I found the |
I'm going to close this issue as the observed behavior is by design. Any improvements in the documentation or schema introspection logic related to this are welcome but this is not something that the team plans to work on in foreseeable future. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Bug Report
Summary
Schema tool doesn't correctly detect the current state of the database on PostgreSQLPlatform. I can't speak for other platforms as I have not tested them. This creates issues in components that depend on it, resulting in the SchemaTool proposing changes to the database that should not occur.
Current behaviour
When using
columnDefinition
, the SchemaTool makes up changes that do not occur when updating the schema. I know the docs say "SchemaTool will not detect changes on the column correctly anymore if you use 'columnDefinition'.", but there is a difference between not detecting changes correctly and making up changes that are not there.Considering the Entity below, when running
orm:schema-tool:update
, the first run wants to execute the following expected and well-working queries:When running the update command again, the SQL is just wrong:
There is already a bug report #4111 for the
DROP DEFAULT
itself, including a proposal that the default value checking is incorrect. I agree with that, but instead of removing the condition, I just applied parenthesis to what I think is the correct statement: from$defaultClause = $column->getDefault() === null
to($defaultClause = $column->getDefault()) === null
After doing so, the SchemaTool no longer tries to drop the default column, however, it still wants to run
ALTER TABLE fulltext ALTER fulltext;
, so clearly there are some false-positive changes there.The Column Diff here shows:
So far I tracked it down to the schema comparator being fed incorrect information about the current state of the column - notice how the default value is somehow set to "english", while the column definition is empty.
Dumping the two arrays here https://github.com/doctrine/dbal/blob/3.4.x/src/Schema/Comparator.php#L522 show the below:
I ran out of time for now, I wish I tracked it deeper. I'm hoping someone more familiar with Doctrine's internal can spot quicker where this is going and what needs to be done?
How to reproduce
orm:schema-tool:update
. The point is to get the SchemaTool to try to detect changes.bin/console do:sch:up --force
to create the table and sequencebin/console do:sch:up --dump-sql
to see the broken update queries.Expected behaviour
The schema should only change when there are changes in place, and the changes should not be incorrect. Sorry for being the Cpt Obvious
The text was updated successfully, but these errors were encountered: