fix: drop column with table str (#5795)
This commit is contained in:
parent
e61b98d696
commit
a1b7e47e75
@ -55,6 +55,8 @@ func (m Migrator) RunWithValue(value interface{}, fc func(*gorm.Statement) error
|
|||||||
|
|
||||||
if table, ok := value.(string); ok {
|
if table, ok := value.(string); ok {
|
||||||
stmt.Table = table
|
stmt.Table = table
|
||||||
|
// set schema to avoid panic
|
||||||
|
stmt.Schema = &schema.Schema{}
|
||||||
} else if err := stmt.ParseWithSpecialTableName(value, stmt.Table); err != nil {
|
} else if err := stmt.ParseWithSpecialTableName(value, stmt.Table); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -616,7 +616,7 @@ func TestMigrateColumns(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := DB.Table("column_structs").Migrator().DropColumn(&NewColumnStruct{}, "NewName"); err != nil {
|
if err := DB.Table("column_structs").Migrator().DropColumn(&NewColumnStruct{}, "NewName"); err != nil {
|
||||||
t.Fatalf("Failed to add column, got %v", err)
|
t.Fatalf("Failed to drop column, got %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if DB.Table("column_structs").Migrator().HasColumn(&NewColumnStruct{}, "NewName") {
|
if DB.Table("column_structs").Migrator().HasColumn(&NewColumnStruct{}, "NewName") {
|
||||||
@ -628,7 +628,7 @@ func TestMigrateColumns(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := DB.Table("column_structs").Migrator().RenameColumn(&NewColumnStruct{}, "NewName", "new_new_name"); err != nil {
|
if err := DB.Table("column_structs").Migrator().RenameColumn(&NewColumnStruct{}, "NewName", "new_new_name"); err != nil {
|
||||||
t.Fatalf("Failed to add column, got %v", err)
|
t.Fatalf("Failed to rename column, got %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !DB.Table("column_structs").Migrator().HasColumn(&NewColumnStruct{}, "new_new_name") {
|
if !DB.Table("column_structs").Migrator().HasColumn(&NewColumnStruct{}, "new_new_name") {
|
||||||
@ -636,12 +636,28 @@ func TestMigrateColumns(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := DB.Table("column_structs").Migrator().DropColumn(&NewColumnStruct{}, "new_new_name"); err != nil {
|
if err := DB.Table("column_structs").Migrator().DropColumn(&NewColumnStruct{}, "new_new_name"); err != nil {
|
||||||
t.Fatalf("Failed to add column, got %v", err)
|
t.Fatalf("Failed to drop column, got %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if DB.Table("column_structs").Migrator().HasColumn(&NewColumnStruct{}, "new_new_name") {
|
if DB.Table("column_structs").Migrator().HasColumn(&NewColumnStruct{}, "new_new_name") {
|
||||||
t.Fatalf("Found deleted column")
|
t.Fatalf("Found deleted column")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := DB.Table("column_structs").Migrator().AddColumn(&NewColumnStruct{}, "NewName"); err != nil {
|
||||||
|
t.Fatalf("Failed to add column, got %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := DB.Migrator().RenameColumn("column_structs", "new_name", "new_new_name"); err != nil {
|
||||||
|
t.Fatalf("Failed to rename column, got %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !DB.Migrator().HasColumn("column_structs", "new_new_name") {
|
||||||
|
t.Fatalf("Failed to find added column")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := DB.Migrator().DropColumn("column_structs", "new_new_name"); err != nil {
|
||||||
|
t.Fatalf("Failed to drop column, got %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMigrateConstraint(t *testing.T) {
|
func TestMigrateConstraint(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user