@@ -148,6 +148,8 @@ func TestSmartMigrateColumn(t *testing.T) {
148
148
ID uint
149
149
Name string
150
150
Salary float64
151
+ Bonus float64 `gorm:"not null"`
152
+ Stock float64
151
153
Birthday time.Time `gorm:"precision:4"`
152
154
}
153
155
@@ -157,8 +159,10 @@ func TestSmartMigrateColumn(t *testing.T) {
157
159
158
160
type UserMigrateColumn2 struct {
159
161
ID uint
160
- Name string `gorm:"size:128"`
161
- Salary float64 `gorm:"precision:2"`
162
+ Name string `gorm:"size:128"`
163
+ Salary float64 `gorm:"precision:2"`
164
+ Bonus float64
165
+ Stock float64 `gorm:"not null"`
162
166
Birthday time.Time `gorm:"precision:2"`
163
167
NameIgnoreMigration string `gorm:"size:100"`
164
168
}
@@ -182,6 +186,16 @@ func TestSmartMigrateColumn(t *testing.T) {
182
186
if precision , o , _ := columnType .DecimalSize (); (fullSupported || precision != 0 ) && precision != 2 {
183
187
t .Fatalf ("salary's precision should be 2, but got %v %v" , precision , o )
184
188
}
189
+ case "bonus" :
190
+ // allow to change non-nullable to nullable
191
+ if nullable , _ := columnType .Nullable (); ! nullable {
192
+ t .Fatalf ("bonus's nullable should be true, bug got %t" , nullable )
193
+ }
194
+ case "stock" :
195
+ // do not allow to change nullable to non-nullable
196
+ if nullable , _ := columnType .Nullable (); ! nullable {
197
+ t .Fatalf ("stock's nullable should be true, bug got %t" , nullable )
198
+ }
185
199
case "birthday" :
186
200
if precision , _ , _ := columnType .DecimalSize (); (fullSupported || precision != 0 ) && precision != 2 {
187
201
t .Fatalf ("birthday's precision should be 2, but got %v" , precision )
0 commit comments