fix: AUTOINCREMENT flag cannot apply with PRIMARY KEY #167
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What did this pull request do?
Fix #4760. Currently, sqlite dialector can't apply
AUTOINCREMENT
to the field type. The reason this method cannot work is if a field is marked asAutoIncrement
andPrimaryKey
at the same time, when we applyAUTOINCREMENT
to data type, it will create SQL like the following:This can cause
SQL logic error: table "example_table" has more than one primary key (1)
error, because there is twoPRIMARY KEY
definition in this statement. The root cause ishasPrimaryKeyInDataType
doesn't check the result ofDialector.DataTypeOf
method.By checking the result of
Dialector.DataTypeOf
method, a dialector can define its behavior forAUTOINCREMENT & PRIMARY KEY
situation.User Case Description
The following struct:
Used to generate table DDL as:
Which doesn't mark
id
field asAUTOINCREMENT
. Currently, theid
field roughly acts likeAUTOINCREMENT,
but it doesn't in many areas. This implementation may cause some issues like id reusing when deleting rows.Now, it will generate table DDL as (if sqlite dialector is also changed):