Skip to content

Commit

Permalink
Fixed missing database name with table name. (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
murali-chevuri committed Jun 12, 2024
1 parent 361eb5f commit c829f6e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (m Migrator) AlterColumn(value interface{}, field string) error {

return m.DB.Exec(
"ALTER TABLE ? MODIFY COLUMN ? ?",
clause.Table{Name: stmt.Table}, clause.Column{Name: field.DBName}, fullDataType,
m.CurrentTable(stmt), clause.Column{Name: field.DBName}, fullDataType,
).Error
}
}
Expand Down Expand Up @@ -215,7 +215,7 @@ func (m Migrator) RenameColumn(value interface{}, oldName, newName string) error
if field != nil {
return m.DB.Exec(
"ALTER TABLE ? CHANGE ? ? ?",
clause.Table{Name: stmt.Table}, clause.Column{Name: oldName},
m.CurrentTable(stmt), clause.Column{Name: oldName},
clause.Column{Name: newName}, m.FullDataTypeOf(field),
).Error
}
Expand Down Expand Up @@ -252,7 +252,7 @@ func (m Migrator) RenameIndex(value interface{}, oldName, newName string) error
return m.RunWithValue(value, func(stmt *gorm.Statement) error {
return m.DB.Exec(
"ALTER TABLE ? RENAME INDEX ? TO ?",
clause.Table{Name: stmt.Table}, clause.Column{Name: oldName}, clause.Column{Name: newName},
m.CurrentTable(stmt), clause.Column{Name: oldName}, clause.Column{Name: newName},
).Error
})
}
Expand All @@ -267,7 +267,7 @@ func (m Migrator) RenameIndex(value interface{}, oldName, newName string) error
if idx := stmt.Schema.LookIndex(newName); idx == nil {
if idx = stmt.Schema.LookIndex(oldName); idx != nil {
opts := m.BuildIndexOptions(idx.Fields, stmt)
values := []interface{}{clause.Column{Name: newName}, clause.Table{Name: stmt.Table}, opts}
values := []interface{}{clause.Column{Name: newName}, m.CurrentTable(stmt), opts}

createIndexSQL := "CREATE "
if idx.Class != "" {
Expand Down Expand Up @@ -295,7 +295,7 @@ func (m Migrator) DropTable(values ...interface{}) error {
tx.Exec("SET FOREIGN_KEY_CHECKS = 0;")
for i := len(values) - 1; i >= 0; i-- {
if err := m.RunWithValue(values[i], func(stmt *gorm.Statement) error {
return tx.Exec("DROP TABLE IF EXISTS ? CASCADE", clause.Table{Name: stmt.Table}).Error
return tx.Exec("DROP TABLE IF EXISTS ? CASCADE", m.CurrentTable(stmt)).Error
}); err != nil {
return err
}
Expand Down

0 comments on commit c829f6e

Please sign in to comment.