test: pgsql alter column from string to boolean
This commit is contained in:
parent
1a2376dba3
commit
f5902558db
@ -1543,21 +1543,23 @@ func TestMigrateView(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMigrateExistingSmallintBoolColumnPG(t *testing.T) {
|
func TestMigrateExistingBoolColumnPG(t *testing.T) {
|
||||||
if DB.Dialector.Name() != "postgres" {
|
if DB.Dialector.Name() != "postgres" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
type ColumnStruct struct {
|
type ColumnStruct struct {
|
||||||
gorm.Model
|
gorm.Model
|
||||||
Name string
|
Name string
|
||||||
IsActive bool `gorm:"type:smallint"`
|
StringBool string
|
||||||
|
SmallintBool int `gorm:"type:smallint"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ColumnStruct2 struct {
|
type ColumnStruct2 struct {
|
||||||
gorm.Model
|
gorm.Model
|
||||||
Name string
|
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{})
|
DB.Migrator().DropTable(&ColumnStruct{})
|
||||||
@ -1582,7 +1584,12 @@ func TestMigrateExistingSmallintBoolColumnPG(t *testing.T) {
|
|||||||
if v, ok := columnType.PrimaryKey(); !ok || !v {
|
if v, ok := columnType.PrimaryKey(); !ok || !v {
|
||||||
t.Fatalf("column id primary key should be correct, name: %v, column: %#v", columnType.Name(), columnType)
|
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()))
|
dataType := DB.Dialector.DataTypeOf(stmt.Schema.LookUpField(columnType.Name()))
|
||||||
if !strings.Contains(strings.ToUpper(dataType), strings.ToUpper(columnType.DatabaseTypeName())) {
|
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)
|
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