@@ -107,7 +107,7 @@ func (m Migrator) CreateIndex(value interface{}, name string) error {
107107 return m .RunWithValue (value , func (stmt * gorm.Statement ) error {
108108 if idx := stmt .Schema .LookIndex (name ); idx != nil {
109109 opts := m .BuildIndexOptions (idx .Fields , stmt )
110- values := []interface {}{clause.Column {Name : idx .Name }, clause. Table { Name : stmt . Table } , opts }
110+ values := []interface {}{clause.Column {Name : idx .Name }, m . CurrentTable ( stmt ) , opts }
111111
112112 createIndexSQL := "CREATE "
113113 if idx .Class != "" {
@@ -167,7 +167,7 @@ func (m Migrator) DropTable(values ...interface{}) error {
167167 tx := m .DB .Session (& gorm.Session {})
168168 for i := len (values ) - 1 ; i >= 0 ; i -- {
169169 if err := m .RunWithValue (values [i ], func (stmt * gorm.Statement ) error {
170- return tx .Exec ("DROP TABLE IF EXISTS ? CASCADE" , clause. Table { Name : stmt . Table } ).Error
170+ return tx .Exec ("DROP TABLE IF EXISTS ? CASCADE" , m . CurrentTable ( stmt ) ).Error
171171 }); err != nil {
172172 return err
173173 }
@@ -250,3 +250,10 @@ func (m Migrator) CurrentSchema(stmt *gorm.Statement) interface{} {
250250 }
251251 return clause.Expr {SQL : "CURRENT_SCHEMA()" }
252252}
253+
254+ func (m Migrator ) CurrentTable (stmt * gorm.Statement ) interface {} {
255+ if stmt .TableExpr != nil {
256+ return * stmt .TableExpr
257+ }
258+ return clause.Table {Name : stmt .Table }
259+ }
0 commit comments