Fix columnType.Unique() returns true for non-unique index DDL. (#154)

Signed-off-by: Jeff Ortel <jortel@redhat.com>
This commit is contained in:
Jeff Ortel
2023-06-08 21:20:12 -05:00
committed by GitHub
parent cf6cd11e94
commit 397ec6fa8c
2 changed files with 19 additions and 1 deletions

View File

@@ -162,7 +162,7 @@ func parseDDL(strs ...string) (*ddl, error) {
for _, column := range getAllColumns(matches[1]) {
for idx, c := range result.columns {
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
}
}

View File

@@ -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 {