-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix #7271 - SQLite - composite keys wrongly introspected as autoincrement #7273
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.5.x
Are you sure you want to change the base?
Conversation
morozov
left a comment
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.
The fix looks fine to me. I don't think there's a BC break other than "it used to work the other way previously". Maintainers, please speak up if you disagree.
| ); | ||
| } | ||
|
|
||
| public function testIntrospectPrimaryKeyAutoincrement(): void |
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.
This tests seems to combine three independent tests. Would it make sense to separate them?
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.
The three assertions are all testing the same logic, so it seemed clearer (to me) to have them in a single test.
I can split them up if desired, but I prefer them together.
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.
With the current approach, if the first assertion fails, the other two will be skipped, however they shouldn't.
|
From #7271 (comment) (emphasis mine)
|
When I requested this analysis, I assumed that the complete fix would somehow resemble #6862, which is a BC break. My own assessment of the actual changes in this PR is:
I don't see an obvious BC break here, it's just a different more correct behavior, which is more appropriate for a minor release. |
Summary
In SQLite, integer primary keys are implicitly autoincrement columns, and dbal contains logic for this.
However, this logic fails when a composite primary key contains an integer and also other non-integer columns. The integer column part of the composite PK becomes wrongly flagged as autoincrement.
(A consequence of this is that when calling
getAlterSchemaSQL(), the non-integer columns are removed from the primary key. For example, a PK consisting ofINTEGER, VARCHARgets changed to justINTEGER. This causes loss of data as the rows saved to the temporary table cannot be re-inserted.)This happens because the code filters the existing PK columns by "is integer" instead of filtering the column under consideration by "is integer".
Moving this "is integer" check fixes the issue.
A new test case was added containing three assertions. Two of these assert that the existing functionality isn't broken. The third would fail under the old code, but passes under the new code.
NOTE: I have submitted this PR against the 4.5.x branch (as requested by @morozov).
However, the code is the same in the 4.4.x branch, and could be backported if desired.