Skip to content

Commit

Permalink
fix: RenameIndex should drop old index (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
black-06 committed Jun 7, 2023
1 parent cb7f946 commit 9ac07d2
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,9 @@ func (m Migrator) RenameIndex(value interface{}, oldName, newName string) error
var sql string
m.DB.Raw("SELECT sql FROM sqlite_master WHERE type = ? AND tbl_name = ? AND name = ?", "index", stmt.Table, oldName).Row().Scan(&sql)
if sql != "" {
if err := m.DropIndex(value, oldName); err != nil {
return err
}
return m.DB.Exec(strings.Replace(sql, oldName, newName, 1)).Error
}
return fmt.Errorf("failed to find index with name %v", oldName)
Expand Down

0 comments on commit 9ac07d2

Please sign in to comment.