You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In go-gorm/sqlite, composite primary keys (i.e., tables with more than one primary key) are not detected correctly. The library recognizes only the first key, failing to mark the other columns as primary keys. This affects table migration and causes incorrect schema interpretation.
GORM Playground Link Recreation with GitHub Actions
I was not able to effectively integrate the gorm playground, so I create my own repository and recreated by GitHub Actions.
Refer This Repository and this GitHub Actions Run
Description
This SQL below creates a table with multiple primary keys.
In gorm, we can use ColumnTypes method in Migrator interface to get primary keys in a table.
Calling ColumnTypes after running the SQL should tell us that column1 and column2 are primary keys, however, go-gorm/sqlite says only column1 is a primary key.
Refer this test case below.
In this testcase, we call .ColumnTypes after creating a table with 2 primary keys. As column1 and column2 are primary keys, this testcase should pass, but this fails.
It tries to match the line with this regex: [(,][`|"|'|\t]?(\w+)[`|"|'|\t]?
This regex can process a line like PRIMARY KEY (column1,column2) , however, it fails to process a line like PRIMARY KEY (column1, column2), as indicated in this screenshot.
Contribution
I would like to contribute to fixing this issue. I'm planning to make pull request for this issue in a few days.
The text was updated successfully, but these errors were encountered:
Summary
In
go-gorm/sqlite
, composite primary keys (i.e., tables with more than one primary key) are not detected correctly. The library recognizes only the first key, failing to mark the other columns as primary keys. This affects table migration and causes incorrect schema interpretation.GORM Playground LinkRecreation with GitHub ActionsI was not able to effectively integrate the gorm playground, so I create my own repository and recreated by GitHub Actions.
Refer This Repository and this GitHub Actions Run
Description
This SQL below creates a table with multiple primary keys.
In gorm, we can use
ColumnTypes
method inMigrator
interface to get primary keys in a table.Calling
ColumnTypes
after running the SQL should tell us thatcolumn1
andcolumn2
are primary keys, however,go-gorm/sqlite
says onlycolumn1
is a primary key.Refer this test case below.
In this testcase, we call
.ColumnTypes
after creating a table with 2 primary keys. Ascolumn1
andcolumn2
are primary keys, this testcase should pass, but this fails.Problem: a flaw in
getAllColumns()
inddlmod.go
parseDDL()
inddlmod.go
loads DDL line by line, if a line start withPRIMARY KEY
, it will be passed togetAllColumns()
and primary key columns are extracted.It tries to match the line with this regex:
[(,][`|"|'|\t]?(\w+)[`|"|'|\t]?
This regex can process a line like
PRIMARY KEY (column1,column2)
, however, it fails to process a line likePRIMARY KEY (column1, column2)
, as indicated in this screenshot.Contribution
I would like to contribute to fixing this issue. I'm planning to make pull request for this issue in a few days.
The text was updated successfully, but these errors were encountered: