-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Report default floats with float type for MySQL #7241
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.4.x
Are you sure you want to change the base?
Conversation
|
Thank you for the PR. Please always add a test that reproduces the issue you're attempting to solve. |
I would attempt to fix that instead. Database drivers represent some numbers as strings for a reason. Using floats for any kind of logic that involves comparison may just exacerbate the problem. Also, if we want to make such a change, it should be implemented and tested consistently across all supported platforms, not only MySQL. |
|
What you're saying is that I should be handling this in doctrine/migrations instead of dbal, right? |
|
Not necessarily. The problem may be in the DBAL itself but not in the schema manager but let's say in the comparator. The best way to facilitate reasoning about the proper fix is to implement a failing scenario in code using the minimum of dependencies (e.g. w/o the ORM). |
|
Thanks for the guidance. I moved the logic to AbstractPlatform::columnsEqual. Is this appropriate? I will of course write tests for the change once a maintainer confirms the code is at the right place. |
Please start with an integration test. |
|
Turns out the test was already there, but the test case was not. I added it here. Thank you for your patience. |
|
Apparently, your new test fails on SQL Server. |
src/Platforms/AbstractPlatform.php
Outdated
| $type1 = $column1Array['type']; | ||
| assert($type1 instanceof Type); | ||
| $type2 = $column2Array['type']; | ||
| assert($type2 instanceof Type); | ||
|
|
||
| if ($type1 instanceof Types\FloatType) { | ||
| $column1Array['default'] = $type1->convertToPHPValue($column1Array['default'], $this); | ||
| } | ||
|
|
||
| if ($type2 instanceof Types\FloatType) { | ||
| $column2Array['default'] = $type2->convertToPHPValue($column2Array['default'], $this); | ||
| } |
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 feels weird that a generic columnsEqual() method contains special treatment for one specific type. We should make sure that columnToArray() already produces comparable arrays.
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 thought so too, but then I remembered being told above:
Database drivers represent some numbers as strings for a reason
Also that means that all database platforms must represent floats in the same way (which I hope they do) so I can just cast them to php values.
If you tell me that's the way to go I would happily do that!
|
Hi again, I implemented @derrabus 's solution instead, moving the logic into Column::toArray . It also fixes the test with mssql. Let me know if there's anything I can do to make this issue move forward. |
Summary
For MySQL databases, the default value is always reported as being a string, which causes doctrine/migrations to be confused sometimes.
It's my first time contributing to Doctrine please be free to request edits.