Skip to content

Commit c829f6e

Browse files
Fixed missing database name with table name. (#153)
1 parent 361eb5f commit c829f6e

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

migrator.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func (m Migrator) AlterColumn(value interface{}, field string) error {
155155

156156
return m.DB.Exec(
157157
"ALTER TABLE ? MODIFY COLUMN ? ?",
158-
clause.Table{Name: stmt.Table}, clause.Column{Name: field.DBName}, fullDataType,
158+
m.CurrentTable(stmt), clause.Column{Name: field.DBName}, fullDataType,
159159
).Error
160160
}
161161
}
@@ -215,7 +215,7 @@ func (m Migrator) RenameColumn(value interface{}, oldName, newName string) error
215215
if field != nil {
216216
return m.DB.Exec(
217217
"ALTER TABLE ? CHANGE ? ? ?",
218-
clause.Table{Name: stmt.Table}, clause.Column{Name: oldName},
218+
m.CurrentTable(stmt), clause.Column{Name: oldName},
219219
clause.Column{Name: newName}, m.FullDataTypeOf(field),
220220
).Error
221221
}
@@ -252,7 +252,7 @@ func (m Migrator) RenameIndex(value interface{}, oldName, newName string) error
252252
return m.RunWithValue(value, func(stmt *gorm.Statement) error {
253253
return m.DB.Exec(
254254
"ALTER TABLE ? RENAME INDEX ? TO ?",
255-
clause.Table{Name: stmt.Table}, clause.Column{Name: oldName}, clause.Column{Name: newName},
255+
m.CurrentTable(stmt), clause.Column{Name: oldName}, clause.Column{Name: newName},
256256
).Error
257257
})
258258
}
@@ -267,7 +267,7 @@ func (m Migrator) RenameIndex(value interface{}, oldName, newName string) error
267267
if idx := stmt.Schema.LookIndex(newName); idx == nil {
268268
if idx = stmt.Schema.LookIndex(oldName); idx != nil {
269269
opts := m.BuildIndexOptions(idx.Fields, stmt)
270-
values := []interface{}{clause.Column{Name: newName}, clause.Table{Name: stmt.Table}, opts}
270+
values := []interface{}{clause.Column{Name: newName}, m.CurrentTable(stmt), opts}
271271

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

0 commit comments

Comments
 (0)