Add tests for alter column type

This commit is contained in:
Jinzhu
2022-10-08 16:04:57 +08:00
parent 34fbe84580
commit 983e96f142
3 changed files with 19 additions and 3 deletions
+16
View File
@@ -8,6 +8,7 @@ import (
"github.com/lib/pq"
"gorm.io/gorm"
"gorm.io/gorm/clause"
. "gorm.io/gorm/utils/tests"
)
func TestPostgresReturningIDWhichHasStringType(t *testing.T) {
@@ -199,3 +200,18 @@ func TestPostgresOnConstraint(t *testing.T) {
t.Errorf("expected 1 thing got more")
}
}
type CompanyNew struct {
ID int
Name int
}
func TestAlterColumnDataType(t *testing.T) {
DB.AutoMigrate(Company{})
if err := DB.Table("companies").Migrator().AlterColumn(CompanyNew{}, "name"); err != nil {
t.Fatalf("failed to alter column from string to int, got error %v", err)
}
DB.AutoMigrate(Company{})
}