diff --git a/ddlmod.go b/ddlmod.go index 246f616..39cc13a 100644 --- a/ddlmod.go +++ b/ddlmod.go @@ -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 } } diff --git a/ddlmod_test.go b/ddlmod_test.go index f6fc6e7..763c3ce 100644 --- a/ddlmod_test.go +++ b/ddlmod_test.go @@ -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 {