@@ -1945,66 +1945,3 @@ func TestMigrateWithUniqueIndexAndUnique(t *testing.T) {
1945
1945
}
1946
1946
}
1947
1947
}
1948
-
1949
- func TestSmartMigrateColumnNullable (t * testing.T ) {
1950
- fullSupported := map [string ]bool {"mysql" : true , "postgres" : true }[DB .Dialector .Name ()]
1951
-
1952
- type UserMigrateColumn struct {
1953
- ID uint
1954
- Name string
1955
- Salary float64
1956
- Bonus float64 `gorm:"not null"`
1957
- Stock float64
1958
- Birthday time.Time `gorm:"precision:4"`
1959
- }
1960
-
1961
- DB .Migrator ().DropTable (& UserMigrateColumn {})
1962
-
1963
- DB .AutoMigrate (& UserMigrateColumn {})
1964
-
1965
- type UserMigrateColumn2 struct {
1966
- ID uint
1967
- Name string `gorm:"size:128"`
1968
- Salary float64 `gorm:"precision:2"`
1969
- Bonus float64
1970
- Stock float64 `gorm:"not null"`
1971
- Birthday time.Time `gorm:"precision:2"`
1972
- NameIgnoreMigration string `gorm:"size:100"`
1973
- }
1974
-
1975
- if err := DB .Table ("user_migrate_columns" ).AutoMigrate (& UserMigrateColumn2 {}); err != nil {
1976
- t .Fatalf ("failed to auto migrate, got error: %v" , err )
1977
- }
1978
-
1979
- columnTypes , err := DB .Table ("user_migrate_columns" ).Migrator ().ColumnTypes (& UserMigrateColumn {})
1980
- if err != nil {
1981
- t .Fatalf ("failed to get column types, got error: %v" , err )
1982
- }
1983
-
1984
- for _ , columnType := range columnTypes {
1985
- switch columnType .Name () {
1986
- case "name" :
1987
- if length , _ := columnType .Length (); (fullSupported || length != 0 ) && length != 128 {
1988
- t .Fatalf ("name's length should be 128, but got %v" , length )
1989
- }
1990
- case "salary" :
1991
- if precision , o , _ := columnType .DecimalSize (); (fullSupported || precision != 0 ) && precision != 2 {
1992
- t .Fatalf ("salary's precision should be 2, but got %v %v" , precision , o )
1993
- }
1994
- case "bonus" :
1995
- // allow to change non-nullable to nullable
1996
- if nullable , _ := columnType .Nullable (); ! nullable {
1997
- t .Fatalf ("bonus's nullable should be true, bug got %t" , nullable )
1998
- }
1999
- case "stock" :
2000
- // do not allow to change nullable to non-nullable
2001
- if nullable , _ := columnType .Nullable (); ! nullable {
2002
- t .Fatalf ("stock's nullable should be true, bug got %t" , nullable )
2003
- }
2004
- case "birthday" :
2005
- if precision , _ , _ := columnType .DecimalSize (); (fullSupported || precision != 0 ) && precision != 2 {
2006
- t .Fatalf ("birthday's precision should be 2, but got %v" , precision )
2007
- }
2008
- }
2009
- }
2010
- }
0 commit comments