Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,10 @@ func (m Migrator) CreateIndex(value interface{}, name string) error {

func (m Migrator) RenameIndex(value interface{}, oldName, newName string) error {
return m.RunWithValue(value, func(stmt *gorm.Statement) error {
currentSchema, _ := m.CurrentSchema(stmt, stmt.Table)
return m.DB.Exec(
"ALTER INDEX ? RENAME TO ?",
clause.Column{Name: oldName}, clause.Column{Name: newName},
"ALTER INDEX ?.? RENAME TO ?",
currentSchema, clause.Column{Name: oldName}, clause.Column{Name: newName},
).Error
})
}
Expand All @@ -187,7 +188,8 @@ func (m Migrator) DropIndex(value interface{}, name string) error {
}
}

return m.DB.Exec("DROP INDEX ?", clause.Column{Name: name}).Error
currentSchema, _ := m.CurrentSchema(stmt, stmt.Table)
return m.DB.Exec("DROP INDEX ?.?", currentSchema, clause.Column{Name: name}).Error
})
}

Expand Down Expand Up @@ -743,7 +745,8 @@ func (m Migrator) GetIndexes(value interface{}) ([]gorm.Index, error) {

err := m.RunWithValue(value, func(stmt *gorm.Statement) error {
result := make([]*Index, 0)
scanErr := m.queryRaw(indexSql, stmt.Table).Scan(&result).Error
currentSchema, curTable := m.CurrentSchema(stmt, stmt.Table)
scanErr := m.queryRaw(indexSql+" AND ct.relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = ?)", curTable, currentSchema).Scan(&result).Error
if scanErr != nil {
return scanErr
}
Expand Down
Loading