From b870cfc93b90f999547e1a285dc81d098837caf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=8D=EC=84=B1=EC=9A=B1?= Date: Thu, 7 Nov 2024 16:40:49 +0900 Subject: [PATCH 01/10] [#6372] Fixed nullable constraint bug for columns during auto migration --- migrator/migrator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrator/migrator.go b/migrator/migrator.go index 189a141f56..7bdfa448c7 100644 --- a/migrator/migrator.go +++ b/migrator/migrator.go @@ -525,7 +525,7 @@ func (m Migrator) MigrateColumn(value interface{}, field *schema.Field, columnTy // check nullable if nullable, ok := columnType.Nullable(); ok && nullable == field.NotNull { // not primary key & database is nullable - if !field.PrimaryKey && nullable { + if !field.PrimaryKey && !nullable { alterColumn = true } } From 697195d4e555366dd6f46bfe0030f7522f7a19d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=8D=EC=84=B1=EC=9A=B1?= Date: Thu, 7 Nov 2024 16:43:22 +0900 Subject: [PATCH 02/10] [#6372] fix comment --- migrator/migrator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrator/migrator.go b/migrator/migrator.go index 7bdfa448c7..cec4e30fc2 100644 --- a/migrator/migrator.go +++ b/migrator/migrator.go @@ -524,7 +524,7 @@ func (m Migrator) MigrateColumn(value interface{}, field *schema.Field, columnTy // check nullable if nullable, ok := columnType.Nullable(); ok && nullable == field.NotNull { - // not primary key & database is nullable + // not primary key & current database is non-nullable(to be nullable) if !field.PrimaryKey && !nullable { alterColumn = true } From 2c10b8b58c54aab26a5dc81895b408a67a8e343b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=8D=EC=84=B1=EC=9A=B1?= Date: Thu, 7 Nov 2024 17:46:44 +0900 Subject: [PATCH 03/10] [#6372] Add test code --- tests/migrate_test.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/migrate_test.go b/tests/migrate_test.go index d955c8d7f2..850f63a86f 100644 --- a/tests/migrate_test.go +++ b/tests/migrate_test.go @@ -148,6 +148,8 @@ func TestSmartMigrateColumn(t *testing.T) { ID uint Name string Salary float64 + Bonus float64 `gorm:"not null"` + Stock float64 Birthday time.Time `gorm:"precision:4"` } @@ -157,8 +159,10 @@ func TestSmartMigrateColumn(t *testing.T) { type UserMigrateColumn2 struct { ID uint - Name string `gorm:"size:128"` - Salary float64 `gorm:"precision:2"` + Name string `gorm:"size:128"` + Salary float64 `gorm:"precision:2"` + Bonus float64 + Stock float64 `gorm:"not null"` Birthday time.Time `gorm:"precision:2"` NameIgnoreMigration string `gorm:"size:100"` } @@ -182,6 +186,16 @@ func TestSmartMigrateColumn(t *testing.T) { if precision, o, _ := columnType.DecimalSize(); (fullSupported || precision != 0) && precision != 2 { t.Fatalf("salary's precision should be 2, but got %v %v", precision, o) } + case "bonus": + // allow to change non-nullable to nullable + if nullable, _ := columnType.Nullable(); !nullable { + t.Fatalf("bonus's nullable should be true, bug got %t", nullable) + } + case "stock": + // do not allow to change nullable to non-nullable + if nullable, _ := columnType.Nullable(); !nullable { + t.Fatalf("stock's nullable should be true, bug got %t", nullable) + } case "birthday": if precision, _, _ := columnType.DecimalSize(); (fullSupported || precision != 0) && precision != 2 { t.Fatalf("birthday's precision should be 2, but got %v", precision) From 68dccca07982f656f7c1b267770e8489869e6d96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=8D=EC=84=B1=EC=9A=B1?= Date: Thu, 7 Nov 2024 18:03:44 +0900 Subject: [PATCH 04/10] [#6372] Add test code --- tests/migrate_test.go | 81 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 65 insertions(+), 16 deletions(-) diff --git a/tests/migrate_test.go b/tests/migrate_test.go index 850f63a86f..ac2d64b0d3 100644 --- a/tests/migrate_test.go +++ b/tests/migrate_test.go @@ -148,8 +148,6 @@ func TestSmartMigrateColumn(t *testing.T) { ID uint Name string Salary float64 - Bonus float64 `gorm:"not null"` - Stock float64 Birthday time.Time `gorm:"precision:4"` } @@ -159,10 +157,8 @@ func TestSmartMigrateColumn(t *testing.T) { type UserMigrateColumn2 struct { ID uint - Name string `gorm:"size:128"` - Salary float64 `gorm:"precision:2"` - Bonus float64 - Stock float64 `gorm:"not null"` + Name string `gorm:"size:128"` + Salary float64 `gorm:"precision:2"` Birthday time.Time `gorm:"precision:2"` NameIgnoreMigration string `gorm:"size:100"` } @@ -186,16 +182,6 @@ func TestSmartMigrateColumn(t *testing.T) { if precision, o, _ := columnType.DecimalSize(); (fullSupported || precision != 0) && precision != 2 { t.Fatalf("salary's precision should be 2, but got %v %v", precision, o) } - case "bonus": - // allow to change non-nullable to nullable - if nullable, _ := columnType.Nullable(); !nullable { - t.Fatalf("bonus's nullable should be true, bug got %t", nullable) - } - case "stock": - // do not allow to change nullable to non-nullable - if nullable, _ := columnType.Nullable(); !nullable { - t.Fatalf("stock's nullable should be true, bug got %t", nullable) - } case "birthday": if precision, _, _ := columnType.DecimalSize(); (fullSupported || precision != 0) && precision != 2 { t.Fatalf("birthday's precision should be 2, but got %v", precision) @@ -1959,3 +1945,66 @@ func TestMigrateWithUniqueIndexAndUnique(t *testing.T) { } } } + +func TestSmartMigrateColumnNullable(t *testing.T) { + fullSupported := map[string]bool{"mysql": true, "postgres": true}[DB.Dialector.Name()] + + type UserMigrateColumn struct { + ID uint + Name string + Salary float64 + Bonus float64 `gorm:"not null"` + Stock float64 + Birthday time.Time `gorm:"precision:4"` + } + + DB.Migrator().DropTable(&UserMigrateColumn{}) + + DB.AutoMigrate(&UserMigrateColumn{}) + + type UserMigrateColumn2 struct { + ID uint + Name string `gorm:"size:128"` + Salary float64 `gorm:"precision:2"` + Bonus float64 + Stock float64 `gorm:"not null"` + Birthday time.Time `gorm:"precision:2"` + NameIgnoreMigration string `gorm:"size:100"` + } + + if err := DB.Table("user_migrate_columns").AutoMigrate(&UserMigrateColumn2{}); err != nil { + t.Fatalf("failed to auto migrate, got error: %v", err) + } + + columnTypes, err := DB.Table("user_migrate_columns").Migrator().ColumnTypes(&UserMigrateColumn{}) + if err != nil { + t.Fatalf("failed to get column types, got error: %v", err) + } + + for _, columnType := range columnTypes { + switch columnType.Name() { + case "name": + if length, _ := columnType.Length(); (fullSupported || length != 0) && length != 128 { + t.Fatalf("name's length should be 128, but got %v", length) + } + case "salary": + if precision, o, _ := columnType.DecimalSize(); (fullSupported || precision != 0) && precision != 2 { + t.Fatalf("salary's precision should be 2, but got %v %v", precision, o) + } + case "bonus": + // allow to change non-nullable to nullable + if nullable, _ := columnType.Nullable(); !nullable { + t.Fatalf("bonus's nullable should be true, bug got %t", nullable) + } + case "stock": + // do not allow to change nullable to non-nullable + if nullable, _ := columnType.Nullable(); !nullable { + t.Fatalf("stock's nullable should be true, bug got %t", nullable) + } + case "birthday": + if precision, _, _ := columnType.DecimalSize(); (fullSupported || precision != 0) && precision != 2 { + t.Fatalf("birthday's precision should be 2, but got %v", precision) + } + } + } +} From 72695c50875fde18eb19703452e2dd39e787e0d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=8D=EC=84=B1=EC=9A=B1?= Date: Thu, 7 Nov 2024 18:14:35 +0900 Subject: [PATCH 05/10] [#6372] Fix failed test case --- tests/automigration_test.go | 69 +++++++++++++++++++++++++++++++++++++ tests/migrate_test.go | 63 --------------------------------- 2 files changed, 69 insertions(+), 63 deletions(-) create mode 100644 tests/automigration_test.go diff --git a/tests/automigration_test.go b/tests/automigration_test.go new file mode 100644 index 0000000000..0d6cfe5ab9 --- /dev/null +++ b/tests/automigration_test.go @@ -0,0 +1,69 @@ +package tests_test + +import ( + "testing" + "time" +) + +func TestSmartAutoMigrateColumnNullable(t *testing.T) { + fullSupported := map[string]bool{"mysql": true, "postgres": true}[DB.Dialector.Name()] + + type UserMigrateColumn struct { + ID uint + Name string + Salary float64 + Bonus float64 `gorm:"not null"` + Stock float64 + Birthday time.Time `gorm:"precision:4"` + } + + DB.Migrator().DropTable(&UserMigrateColumn{}) + + DB.AutoMigrate(&UserMigrateColumn{}) + + type UserMigrateColumn2 struct { + ID uint + Name string `gorm:"size:128"` + Salary float64 `gorm:"precision:2"` + Bonus float64 + Stock float64 `gorm:"not null"` + Birthday time.Time `gorm:"precision:2"` + NameIgnoreMigration string `gorm:"size:100"` + } + + if err := DB.Table("user_migrate_columns").AutoMigrate(&UserMigrateColumn2{}); err != nil { + t.Fatalf("failed to auto migrate, got error: %v", err) + } + + columnTypes, err := DB.Table("user_migrate_columns").Migrator().ColumnTypes(&UserMigrateColumn{}) + if err != nil { + t.Fatalf("failed to get column types, got error: %v", err) + } + + for _, columnType := range columnTypes { + switch columnType.Name() { + case "name": + if length, _ := columnType.Length(); (fullSupported || length != 0) && length != 128 { + t.Fatalf("name's length should be 128, but got %v", length) + } + case "salary": + if precision, o, _ := columnType.DecimalSize(); (fullSupported || precision != 0) && precision != 2 { + t.Fatalf("salary's precision should be 2, but got %v %v", precision, o) + } + case "bonus": + // allow to change non-nullable to nullable + if nullable, _ := columnType.Nullable(); !nullable { + t.Fatalf("bonus's nullable should be true, bug got %t", nullable) + } + case "stock": + // do not allow to change nullable to non-nullable + if nullable, _ := columnType.Nullable(); !nullable { + t.Fatalf("stock's nullable should be true, bug got %t", nullable) + } + case "birthday": + if precision, _, _ := columnType.DecimalSize(); (fullSupported || precision != 0) && precision != 2 { + t.Fatalf("birthday's precision should be 2, but got %v", precision) + } + } + } +} diff --git a/tests/migrate_test.go b/tests/migrate_test.go index ac2d64b0d3..d955c8d7f2 100644 --- a/tests/migrate_test.go +++ b/tests/migrate_test.go @@ -1945,66 +1945,3 @@ func TestMigrateWithUniqueIndexAndUnique(t *testing.T) { } } } - -func TestSmartMigrateColumnNullable(t *testing.T) { - fullSupported := map[string]bool{"mysql": true, "postgres": true}[DB.Dialector.Name()] - - type UserMigrateColumn struct { - ID uint - Name string - Salary float64 - Bonus float64 `gorm:"not null"` - Stock float64 - Birthday time.Time `gorm:"precision:4"` - } - - DB.Migrator().DropTable(&UserMigrateColumn{}) - - DB.AutoMigrate(&UserMigrateColumn{}) - - type UserMigrateColumn2 struct { - ID uint - Name string `gorm:"size:128"` - Salary float64 `gorm:"precision:2"` - Bonus float64 - Stock float64 `gorm:"not null"` - Birthday time.Time `gorm:"precision:2"` - NameIgnoreMigration string `gorm:"size:100"` - } - - if err := DB.Table("user_migrate_columns").AutoMigrate(&UserMigrateColumn2{}); err != nil { - t.Fatalf("failed to auto migrate, got error: %v", err) - } - - columnTypes, err := DB.Table("user_migrate_columns").Migrator().ColumnTypes(&UserMigrateColumn{}) - if err != nil { - t.Fatalf("failed to get column types, got error: %v", err) - } - - for _, columnType := range columnTypes { - switch columnType.Name() { - case "name": - if length, _ := columnType.Length(); (fullSupported || length != 0) && length != 128 { - t.Fatalf("name's length should be 128, but got %v", length) - } - case "salary": - if precision, o, _ := columnType.DecimalSize(); (fullSupported || precision != 0) && precision != 2 { - t.Fatalf("salary's precision should be 2, but got %v %v", precision, o) - } - case "bonus": - // allow to change non-nullable to nullable - if nullable, _ := columnType.Nullable(); !nullable { - t.Fatalf("bonus's nullable should be true, bug got %t", nullable) - } - case "stock": - // do not allow to change nullable to non-nullable - if nullable, _ := columnType.Nullable(); !nullable { - t.Fatalf("stock's nullable should be true, bug got %t", nullable) - } - case "birthday": - if precision, _, _ := columnType.DecimalSize(); (fullSupported || precision != 0) && precision != 2 { - t.Fatalf("birthday's precision should be 2, but got %v", precision) - } - } - } -} From b091b56cd23352700026014064bad48babf1efb2 Mon Sep 17 00:00:00 2001 From: wookie0 Date: Thu, 7 Nov 2024 22:15:34 +0900 Subject: [PATCH 06/10] [#6372] Fix failed test case --- tests/automigration_test.go | 69 ------------------------------------- tests/migrate_test.go | 18 ++++++++-- 2 files changed, 16 insertions(+), 71 deletions(-) delete mode 100644 tests/automigration_test.go diff --git a/tests/automigration_test.go b/tests/automigration_test.go deleted file mode 100644 index 0d6cfe5ab9..0000000000 --- a/tests/automigration_test.go +++ /dev/null @@ -1,69 +0,0 @@ -package tests_test - -import ( - "testing" - "time" -) - -func TestSmartAutoMigrateColumnNullable(t *testing.T) { - fullSupported := map[string]bool{"mysql": true, "postgres": true}[DB.Dialector.Name()] - - type UserMigrateColumn struct { - ID uint - Name string - Salary float64 - Bonus float64 `gorm:"not null"` - Stock float64 - Birthday time.Time `gorm:"precision:4"` - } - - DB.Migrator().DropTable(&UserMigrateColumn{}) - - DB.AutoMigrate(&UserMigrateColumn{}) - - type UserMigrateColumn2 struct { - ID uint - Name string `gorm:"size:128"` - Salary float64 `gorm:"precision:2"` - Bonus float64 - Stock float64 `gorm:"not null"` - Birthday time.Time `gorm:"precision:2"` - NameIgnoreMigration string `gorm:"size:100"` - } - - if err := DB.Table("user_migrate_columns").AutoMigrate(&UserMigrateColumn2{}); err != nil { - t.Fatalf("failed to auto migrate, got error: %v", err) - } - - columnTypes, err := DB.Table("user_migrate_columns").Migrator().ColumnTypes(&UserMigrateColumn{}) - if err != nil { - t.Fatalf("failed to get column types, got error: %v", err) - } - - for _, columnType := range columnTypes { - switch columnType.Name() { - case "name": - if length, _ := columnType.Length(); (fullSupported || length != 0) && length != 128 { - t.Fatalf("name's length should be 128, but got %v", length) - } - case "salary": - if precision, o, _ := columnType.DecimalSize(); (fullSupported || precision != 0) && precision != 2 { - t.Fatalf("salary's precision should be 2, but got %v %v", precision, o) - } - case "bonus": - // allow to change non-nullable to nullable - if nullable, _ := columnType.Nullable(); !nullable { - t.Fatalf("bonus's nullable should be true, bug got %t", nullable) - } - case "stock": - // do not allow to change nullable to non-nullable - if nullable, _ := columnType.Nullable(); !nullable { - t.Fatalf("stock's nullable should be true, bug got %t", nullable) - } - case "birthday": - if precision, _, _ := columnType.DecimalSize(); (fullSupported || precision != 0) && precision != 2 { - t.Fatalf("birthday's precision should be 2, but got %v", precision) - } - } - } -} diff --git a/tests/migrate_test.go b/tests/migrate_test.go index d955c8d7f2..850f63a86f 100644 --- a/tests/migrate_test.go +++ b/tests/migrate_test.go @@ -148,6 +148,8 @@ func TestSmartMigrateColumn(t *testing.T) { ID uint Name string Salary float64 + Bonus float64 `gorm:"not null"` + Stock float64 Birthday time.Time `gorm:"precision:4"` } @@ -157,8 +159,10 @@ func TestSmartMigrateColumn(t *testing.T) { type UserMigrateColumn2 struct { ID uint - Name string `gorm:"size:128"` - Salary float64 `gorm:"precision:2"` + Name string `gorm:"size:128"` + Salary float64 `gorm:"precision:2"` + Bonus float64 + Stock float64 `gorm:"not null"` Birthday time.Time `gorm:"precision:2"` NameIgnoreMigration string `gorm:"size:100"` } @@ -182,6 +186,16 @@ func TestSmartMigrateColumn(t *testing.T) { if precision, o, _ := columnType.DecimalSize(); (fullSupported || precision != 0) && precision != 2 { t.Fatalf("salary's precision should be 2, but got %v %v", precision, o) } + case "bonus": + // allow to change non-nullable to nullable + if nullable, _ := columnType.Nullable(); !nullable { + t.Fatalf("bonus's nullable should be true, bug got %t", nullable) + } + case "stock": + // do not allow to change nullable to non-nullable + if nullable, _ := columnType.Nullable(); !nullable { + t.Fatalf("stock's nullable should be true, bug got %t", nullable) + } case "birthday": if precision, _, _ := columnType.DecimalSize(); (fullSupported || precision != 0) && precision != 2 { t.Fatalf("birthday's precision should be 2, but got %v", precision) From 60f2107394b796d6e2e1f80be02b38770d9f732d Mon Sep 17 00:00:00 2001 From: wookie0 Date: Fri, 8 Nov 2024 11:22:16 +0900 Subject: [PATCH 07/10] [#6372] wip --- tests/migrate_test.go | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/migrate_test.go b/tests/migrate_test.go index 850f63a86f..b23c6714ac 100644 --- a/tests/migrate_test.go +++ b/tests/migrate_test.go @@ -145,11 +145,11 @@ func TestSmartMigrateColumn(t *testing.T) { fullSupported := map[string]bool{"mysql": true, "postgres": true}[DB.Dialector.Name()] type UserMigrateColumn struct { - ID uint - Name string - Salary float64 - Bonus float64 `gorm:"not null"` - Stock float64 + ID uint + Name string + Salary float64 + //Bonus float64 `gorm:"not null"` + //Stock float64 Birthday time.Time `gorm:"precision:4"` } @@ -158,11 +158,11 @@ func TestSmartMigrateColumn(t *testing.T) { DB.AutoMigrate(&UserMigrateColumn{}) type UserMigrateColumn2 struct { - ID uint - Name string `gorm:"size:128"` - Salary float64 `gorm:"precision:2"` - Bonus float64 - Stock float64 `gorm:"not null"` + ID uint + Name string `gorm:"size:128"` + Salary float64 `gorm:"precision:2"` + //Bonus float64 + //Stock float64 `gorm:"not null"` Birthday time.Time `gorm:"precision:2"` NameIgnoreMigration string `gorm:"size:100"` } @@ -186,16 +186,16 @@ func TestSmartMigrateColumn(t *testing.T) { if precision, o, _ := columnType.DecimalSize(); (fullSupported || precision != 0) && precision != 2 { t.Fatalf("salary's precision should be 2, but got %v %v", precision, o) } - case "bonus": - // allow to change non-nullable to nullable - if nullable, _ := columnType.Nullable(); !nullable { - t.Fatalf("bonus's nullable should be true, bug got %t", nullable) - } - case "stock": - // do not allow to change nullable to non-nullable - if nullable, _ := columnType.Nullable(); !nullable { - t.Fatalf("stock's nullable should be true, bug got %t", nullable) - } + //case "bonus": + // // allow to change non-nullable to nullable + // if nullable, _ := columnType.Nullable(); !nullable { + // t.Fatalf("bonus's nullable should be true, bug got %t", nullable) + // } + //case "stock": + // // do not allow to change nullable to non-nullable + // if nullable, _ := columnType.Nullable(); !nullable { + // t.Fatalf("stock's nullable should be true, bug got %t", nullable) + // } case "birthday": if precision, _, _ := columnType.DecimalSize(); (fullSupported || precision != 0) && precision != 2 { t.Fatalf("birthday's precision should be 2, but got %v", precision) From d148cb2e6ddbe653b64a384def6ef04076ae5387 Mon Sep 17 00:00:00 2001 From: wookie0 Date: Fri, 8 Nov 2024 13:44:10 +0900 Subject: [PATCH 08/10] [#6372] wip --- tests/migrate_test.go | 68 ++++++++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 20 deletions(-) diff --git a/tests/migrate_test.go b/tests/migrate_test.go index b23c6714ac..51ebc8448d 100644 --- a/tests/migrate_test.go +++ b/tests/migrate_test.go @@ -141,15 +141,55 @@ func TestAutoMigrateSelfReferential(t *testing.T) { } } +func TestAutoMigrateNullable(t *testing.T) { + type UserMigrateColumn struct { + ID uint + Bonus float64 `gorm:"not null"` + Stock float64 + } + + DB.Migrator().DropTable(&UserMigrateColumn{}) + + DB.AutoMigrate(&UserMigrateColumn{}) + + type UserMigrateColumn2 struct { + ID uint + Bonus float64 + Stock float64 `gorm:"not null"` + } + + if err := DB.Table("user_migrate_columns").AutoMigrate(&UserMigrateColumn2{}); err != nil { + t.Fatalf("failed to auto migrate, got error: %v", err) + } + + columnTypes, err := DB.Table("user_migrate_columns").Migrator().ColumnTypes(&UserMigrateColumn{}) + if err != nil { + t.Fatalf("failed to get column types, got error: %v", err) + } + + for _, columnType := range columnTypes { + switch columnType.Name() { + case "bonus": + // allow to change non-nullable to nullable + if nullable, _ := columnType.Nullable(); !nullable { + t.Fatalf("bonus's nullable should be true, bug got %t", nullable) + } + case "stock": + // do not allow to change nullable to non-nullable + if nullable, _ := columnType.Nullable(); !nullable { + t.Fatalf("stock's nullable should be true, bug got %t", nullable) + } + } + } +} + func TestSmartMigrateColumn(t *testing.T) { fullSupported := map[string]bool{"mysql": true, "postgres": true}[DB.Dialector.Name()] type UserMigrateColumn struct { - ID uint - Name string - Salary float64 - //Bonus float64 `gorm:"not null"` - //Stock float64 + ID uint + Name string + Salary float64 Birthday time.Time `gorm:"precision:4"` } @@ -158,11 +198,9 @@ func TestSmartMigrateColumn(t *testing.T) { DB.AutoMigrate(&UserMigrateColumn{}) type UserMigrateColumn2 struct { - ID uint - Name string `gorm:"size:128"` - Salary float64 `gorm:"precision:2"` - //Bonus float64 - //Stock float64 `gorm:"not null"` + ID uint + Name string `gorm:"size:128"` + Salary float64 `gorm:"precision:2"` Birthday time.Time `gorm:"precision:2"` NameIgnoreMigration string `gorm:"size:100"` } @@ -186,16 +224,6 @@ func TestSmartMigrateColumn(t *testing.T) { if precision, o, _ := columnType.DecimalSize(); (fullSupported || precision != 0) && precision != 2 { t.Fatalf("salary's precision should be 2, but got %v %v", precision, o) } - //case "bonus": - // // allow to change non-nullable to nullable - // if nullable, _ := columnType.Nullable(); !nullable { - // t.Fatalf("bonus's nullable should be true, bug got %t", nullable) - // } - //case "stock": - // // do not allow to change nullable to non-nullable - // if nullable, _ := columnType.Nullable(); !nullable { - // t.Fatalf("stock's nullable should be true, bug got %t", nullable) - // } case "birthday": if precision, _, _ := columnType.DecimalSize(); (fullSupported || precision != 0) && precision != 2 { t.Fatalf("birthday's precision should be 2, but got %v", precision) From 90dd2236537379a1b1d2a0bf2514dbe5cbcff6db Mon Sep 17 00:00:00 2001 From: wookie0 Date: Fri, 8 Nov 2024 14:15:22 +0900 Subject: [PATCH 09/10] [#6372] wip --- tests/migrate_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/migrate_test.go b/tests/migrate_test.go index 51ebc8448d..6c8a4216de 100644 --- a/tests/migrate_test.go +++ b/tests/migrate_test.go @@ -142,27 +142,27 @@ func TestAutoMigrateSelfReferential(t *testing.T) { } func TestAutoMigrateNullable(t *testing.T) { - type UserMigrateColumn struct { + type MigrateNullableColumn struct { ID uint Bonus float64 `gorm:"not null"` Stock float64 } - DB.Migrator().DropTable(&UserMigrateColumn{}) + DB.Migrator().DropTable(&MigrateNullableColumn{}) - DB.AutoMigrate(&UserMigrateColumn{}) + DB.AutoMigrate(&MigrateNullableColumn{}) - type UserMigrateColumn2 struct { + type MigrateNullableColumn2 struct { ID uint Bonus float64 Stock float64 `gorm:"not null"` } - if err := DB.Table("user_migrate_columns").AutoMigrate(&UserMigrateColumn2{}); err != nil { + if err := DB.Table("migrate_nullable_columns").AutoMigrate(&MigrateNullableColumn2{}); err != nil { t.Fatalf("failed to auto migrate, got error: %v", err) } - columnTypes, err := DB.Table("user_migrate_columns").Migrator().ColumnTypes(&UserMigrateColumn{}) + columnTypes, err := DB.Table("migrate_nullable_columns").Migrator().ColumnTypes(&MigrateNullableColumn{}) if err != nil { t.Fatalf("failed to get column types, got error: %v", err) } From 4cedb1381decc7f00a5d1f93636d93a7438d6049 Mon Sep 17 00:00:00 2001 From: wookie0 Date: Fri, 8 Nov 2024 16:03:41 +0900 Subject: [PATCH 10/10] [#6372] wip --- tests/go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/go.mod b/tests/go.mod index ba8a84a868..3728611017 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -10,7 +10,7 @@ require ( gorm.io/driver/mysql v1.5.7 gorm.io/driver/postgres v1.5.9 gorm.io/driver/sqlite v1.5.6 - gorm.io/driver/sqlserver v1.5.3 + gorm.io/driver/sqlserver v1.5.4 gorm.io/gorm v1.25.12 )