(t *testing.T)
| 270 | } |
| 271 | |
| 272 | func TestSmartMigrateColumnGaussDB(t *testing.T) { |
| 273 | fullSupported := map[string]bool{"mysql": true, "gaussdb": true}[DB.Dialector.Name()] |
| 274 | |
| 275 | type UserMigrateColumn struct { |
| 276 | ID uint |
| 277 | Name string |
| 278 | Salary float64 |
| 279 | Birthday time.Time `gorm:"precision:4"` |
| 280 | } |
| 281 | |
| 282 | DB.Migrator().DropTable(&UserMigrateColumn{}) |
| 283 | |
| 284 | DB.AutoMigrate(&UserMigrateColumn{}) |
| 285 | |
| 286 | type UserMigrateColumn2 struct { |
| 287 | ID uint |
| 288 | Name string `gorm:"size:128"` |
| 289 | Salary float64 `gorm:"precision:2"` |
| 290 | Birthday time.Time `gorm:"precision:2"` |
| 291 | NameIgnoreMigration string `gorm:"size:100"` |
| 292 | } |
| 293 | |
| 294 | if err := DB.Table("user_migrate_columns").AutoMigrate(&UserMigrateColumn2{}); err != nil { |
| 295 | t.Fatalf("failed to auto migrate, got error: %v", err) |
| 296 | } |
| 297 | |
| 298 | columnTypes, err := DB.Table("user_migrate_columns").Migrator().ColumnTypes(&UserMigrateColumn{}) |
| 299 | if err != nil { |
| 300 | t.Fatalf("failed to get column types, got error: %v", err) |
| 301 | } |
| 302 | |
| 303 | for _, columnType := range columnTypes { |
| 304 | switch columnType.Name() { |
| 305 | case "name": |
| 306 | if length, _ := columnType.Length(); (fullSupported || length != 0) && length != 128 { |
| 307 | t.Fatalf("name's length should be 128, but got %v", length) |
| 308 | } |
| 309 | case "salary": |
| 310 | if precision, o, _ := columnType.DecimalSize(); (fullSupported || precision != 0) && precision != 2 { |
| 311 | t.Fatalf("salary's precision should be 2, but got %v %v", precision, o) |
| 312 | } |
| 313 | case "birthday": |
| 314 | if precision, _, _ := columnType.DecimalSize(); (fullSupported || precision != 0) && precision != 2 { |
| 315 | t.Fatalf("birthday's precision should be 2, but got %v", precision) |
| 316 | } |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | type UserMigrateColumn3 struct { |
| 321 | ID uint |
| 322 | Name string `gorm:"size:256"` |
| 323 | Salary float64 `gorm:"precision:3"` |
| 324 | Birthday time.Time `gorm:"precision:3"` |
| 325 | NameIgnoreMigration string `gorm:"size:128;-:migration"` |
| 326 | } |
| 327 | |
| 328 | if err := DB.Table("user_migrate_columns").AutoMigrate(&UserMigrateColumn3{}); err != nil { |
| 329 | t.Fatalf("failed to auto migrate, got error: %v", err) |
nothing calls this directly
no test coverage detected