@@ -21,6 +21,9 @@ type UserIndex struct {
21
21
Name7 string `gorm:"index:type"`
22
22
Name8 string `gorm:"index:,length:10;index:,collate:utf8"`
23
23
24
+ CompName1 string `gorm:"index:,unique,composite:idx_compname_1,option:NULLS NOT DISTINCT;not null"`
25
+ CompName2 string `gorm:"index:,composite:idx_compname_1"`
26
+
24
27
// Composite Index: Flattened structure.
25
28
Data0A string `gorm:"index:,composite:comp_id0"`
26
29
Data0B string `gorm:"index:,composite:comp_id0"`
@@ -154,6 +157,15 @@ func TestParseIndex(t *testing.T) {
154
157
Field : & schema.Field {Name : "Data2B" },
155
158
}},
156
159
},
160
+ "idx_user_indices_idx_compname_1" : {
161
+ Class : "UNIQUE" ,
162
+ Name : "idx_user_indices_idx_compname_1" ,
163
+ Option : "NULLS NOT DISTINCT" ,
164
+ Fields : []schema.IndexOption {
165
+ {Field : & schema.Field {Name : "CompName1" , NotNull : true }},
166
+ {Field : & schema.Field {Name : "CompName2" }},
167
+ },
168
+ },
157
169
}
158
170
159
171
CheckIndices (t , results , user .ParseIndexes ())
@@ -253,7 +265,7 @@ func CheckIndices(t *testing.T, expected, actual map[string]schema.Index) {
253
265
}
254
266
for i , ef := range ei .Fields {
255
267
af := ai .Fields [i ]
256
- tests .AssertObjEqual (t , af , ef , "Name" , "Unique" , "UniqueIndex" , "Expression" , "Sort" , "Collate" , "Length" )
268
+ tests .AssertObjEqual (t , af , ef , "Name" , "Unique" , "UniqueIndex" , "Expression" , "Sort" , "Collate" , "Length" , "NotNull" )
257
269
}
258
270
})
259
271
delete (actual , k )
0 commit comments