mirror of
https://github.com/glebarez/sqlite.git
synced 2025-10-08 00:50:19 +08:00
Fix columnType.Unique() returns true for non-unique index DDL. (#154)
Signed-off-by: Jeff Ortel <jortel@redhat.com>
This commit is contained in:
@@ -162,7 +162,7 @@ func parseDDL(strs ...string) (*ddl, error) {
|
|||||||
for _, column := range getAllColumns(matches[1]) {
|
for _, column := range getAllColumns(matches[1]) {
|
||||||
for idx, c := range result.columns {
|
for idx, c := range result.columns {
|
||||||
if c.NameValue.String == column {
|
if c.NameValue.String == column {
|
||||||
c.UniqueValue = sql.NullBool{Bool: true, Valid: true}
|
c.UniqueValue = sql.NullBool{Bool: strings.ToUpper(strings.Fields(str)[1]) == "UNIQUE", Valid: true}
|
||||||
result.columns[idx] = c
|
result.columns[idx] = c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -79,6 +79,24 @@ func TestParseDDL(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"non-unique index",
|
||||||
|
[]string{
|
||||||
|
"CREATE TABLE `test-c` (`field` integer NOT NULL)",
|
||||||
|
"CREATE INDEX `idx_uq` ON `test-b`(`field`) WHERE field = 0",
|
||||||
|
},
|
||||||
|
1,
|
||||||
|
[]migrator.ColumnType{
|
||||||
|
{
|
||||||
|
NameValue: sql.NullString{String: "field", Valid: true},
|
||||||
|
DataTypeValue: sql.NullString{String: "integer", Valid: true},
|
||||||
|
ColumnTypeValue: sql.NullString{String: "integer", Valid: true},
|
||||||
|
PrimaryKeyValue: sql.NullBool{Bool: false, Valid: true},
|
||||||
|
UniqueValue: sql.NullBool{Bool: false, Valid: true},
|
||||||
|
NullableValue: sql.NullBool{Bool: false, Valid: true},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, p := range params {
|
for _, p := range params {
|
||||||
|
Reference in New Issue
Block a user