test: pgsql alter column from string to boolean
This commit is contained in:
parent
1a2376dba3
commit
f5902558db
@ -1543,7 +1543,7 @@ func TestMigrateView(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMigrateExistingSmallintBoolColumnPG(t *testing.T) {
|
||||
func TestMigrateExistingBoolColumnPG(t *testing.T) {
|
||||
if DB.Dialector.Name() != "postgres" {
|
||||
return
|
||||
}
|
||||
@ -1551,13 +1551,15 @@ func TestMigrateExistingSmallintBoolColumnPG(t *testing.T) {
|
||||
type ColumnStruct struct {
|
||||
gorm.Model
|
||||
Name string
|
||||
IsActive bool `gorm:"type:smallint"`
|
||||
StringBool string
|
||||
SmallintBool int `gorm:"type:smallint"`
|
||||
}
|
||||
|
||||
type ColumnStruct2 struct {
|
||||
gorm.Model
|
||||
Name string
|
||||
IsActive bool // change existing boolean column from smallint or other to boolean
|
||||
StringBool bool // change existing boolean column from string to boolean
|
||||
SmallintBool bool // change existing boolean column from smallint or other to boolean
|
||||
}
|
||||
|
||||
DB.Migrator().DropTable(&ColumnStruct{})
|
||||
@ -1582,7 +1584,12 @@ func TestMigrateExistingSmallintBoolColumnPG(t *testing.T) {
|
||||
if v, ok := columnType.PrimaryKey(); !ok || !v {
|
||||
t.Fatalf("column id primary key should be correct, name: %v, column: %#v", columnType.Name(), columnType)
|
||||
}
|
||||
case "is_active":
|
||||
case "string_bool":
|
||||
dataType := DB.Dialector.DataTypeOf(stmt.Schema.LookUpField(columnType.Name()))
|
||||
if !strings.Contains(strings.ToUpper(dataType), strings.ToUpper(columnType.DatabaseTypeName())) {
|
||||
t.Fatalf("column name type should be correct, name: %v, length: %v, expects: %v, column: %#v", columnType.Name(), columnType.DatabaseTypeName(), dataType, columnType)
|
||||
}
|
||||
case "smallint_bool":
|
||||
dataType := DB.Dialector.DataTypeOf(stmt.Schema.LookUpField(columnType.Name()))
|
||||
if !strings.Contains(strings.ToUpper(dataType), strings.ToUpper(columnType.DatabaseTypeName())) {
|
||||
t.Fatalf("column name type should be correct, name: %v, length: %v, expects: %v, column: %#v", columnType.Name(), columnType.DatabaseTypeName(), dataType, columnType)
|
||||
|
Loading…
x
Reference in New Issue
Block a user