| 184 | } |
| 185 | |
| 186 | func TestGaussDBOnConstraint(t *testing.T) { |
| 187 | t.Skipf("This test case skipped, because of gaussdb not support 'ON CONSTRAINT' statement") |
| 188 | if DB.Dialector.Name() != "gaussdb" { |
| 189 | t.Skip() |
| 190 | } |
| 191 | |
| 192 | type Thing struct { |
| 193 | gorm.Model |
| 194 | SomeID string |
| 195 | OtherID string |
| 196 | Data string |
| 197 | } |
| 198 | |
| 199 | DB.Migrator().DropTable(&Thing{}) |
| 200 | DB.Migrator().CreateTable(&Thing{}) |
| 201 | if err := DB.Exec("ALTER TABLE things ADD CONSTRAINT some_id_other_id_unique UNIQUE (some_id, other_id)").Error; err != nil { |
| 202 | t.Error(err) |
| 203 | } |
| 204 | |
| 205 | thing := Thing{ |
| 206 | SomeID: "1234", |
| 207 | OtherID: "1234", |
| 208 | Data: "something", |
| 209 | } |
| 210 | |
| 211 | DB.Create(&thing) |
| 212 | |
| 213 | thing2 := Thing{ |
| 214 | SomeID: "1234", |
| 215 | OtherID: "1234", |
| 216 | Data: "something else", |
| 217 | } |
| 218 | |
| 219 | result := DB.Clauses(clause.OnConflict{ |
| 220 | OnConstraint: "some_id_other_id_unique", |
| 221 | UpdateAll: true, |
| 222 | }).Create(&thing2) |
| 223 | if result.Error != nil { |
| 224 | t.Errorf("creating second thing: %v", result.Error) |
| 225 | } |
| 226 | |
| 227 | var things []Thing |
| 228 | if err := DB.Find(&things).Error; err != nil { |
| 229 | t.Errorf("Failed, got error: %v", err) |
| 230 | } |
| 231 | |
| 232 | if len(things) > 1 { |
| 233 | t.Errorf("expected 1 thing got more") |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | func TestGaussDBAlterColumnDataType(t *testing.T) { |
| 238 | if DB.Dialector.Name() != "gaussdb" { |