-
-
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
Fix "bigint" type introspection for PK column with AI for SQLite #6411
base: 3.9.x
Are you sure you want to change the base?
Conversation
9352375
to
b6a65d9
Compare
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 would seem that this is going to cause the opposite problem: a primary key with type INTEGER
is wrongly going to be introspected as BIGINT, isn't it?
@@ -379,6 +379,12 @@ protected function _getPortableTableColumnDefinition($tableColumn) | |||
$default = null; | |||
} | |||
|
|||
// https://github.com/doctrine/dbal/blob/3.8.4/src/Platforms/SqlitePlatform.php#L271-L274 | |||
// https://dbfiddle.uk/yyXvHV-6 | |||
if (strtolower($type) === 'integer' && ($tableColumn['pk'] !== 0 && $tableColumn['pk'] !== '0')) { |
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 don't understand why $tableColumn['pk'] !== 0 && $tableColumn['pk'] !== '0'
should mean this is an auto increment column. Couldn't it be an integer column that is part of the primary key?
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 coded the "auto increment" detection based on existing https://github.com/doctrine/dbal/blob/b6a65d9ef8/src/Schema/SqliteSchemaManager.php#L295-L319. Is that right?
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 also noticed that code block, but I don't know why it is right (if it is).
This is unavoidable because of #5107 and expected - |
The auto increment are in the sequence table and these are integers probably. You could select from this table to check if there is auto increment. |
Is it really wanted to do additional query in |
I'm not comfortable with merging this change into 3.8, tbh. As you've already noticed, SQLite's implementation of integer PKs is a bit odd. The main issue is that SQLite does not allow you to create BIGINT PKs which is why the DBAL creates an This also means that when introspecting, we cannot tell the difference between a column that was created by DBAL from a |
You could also solve this in documentation: say in sqlite primary keys are just ints, not bigints and do nothing about the code or throw an exception when a primary key is not an int in sqlite |
We probably don't want this. If someone uses BIGINT PKs on their entity model, e.g. because they're using MySQL in production, they should still be able to deploy their model to SQLite for testing purposes. |
Yes and testing a big int number will fail |
I think the point was that it shouldn't fail. Prod uses MySQL and a Test environment SQLite. It would break projects if SQLite would suddenly throw an exception. If it would stay that way, I wouldn't expect such a change in 3.8 or 4.0. |
There hasn't been any activity on this pull request in the past 90 days, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days. |
I will work on this. |
Summary
Because SQLite does not support
AUTOINCREMENT
keyword on any other type thanINTEGER
[1] [2],bigint
type is mapped toINTEGER
SQLite database column by DBAL already [3].As we remap the type on table creation, we need to remap the type also on table introspection. The reason, we remap
integer
tobigint
, isbigint
is subtype ofinteger
- PK defined/created originally asbigint
must be always introspected asbigint
.[1] https://www.sqlite.org/autoinc.html
[2] https://dbfiddle.uk/yyXvHV-6
[3] https://github.com/doctrine/dbal/blob/3.8.4/src/Platforms/SqlitePlatform.php#L271-L274