HasIndex check has index `name` or not
(value interface{}, name string)
| 881 | |
| 882 | // HasIndex check has index `name` or not |
| 883 | func (m Migrator) HasIndex(value interface{}, name string) bool { |
| 884 | var count int64 |
| 885 | m.RunWithValue(value, func(stmt *gorm.Statement) error { |
| 886 | currentDatabase := m.DB.Migrator().CurrentDatabase() |
| 887 | if stmt.Schema != nil { |
| 888 | if idx := stmt.Schema.LookIndex(name); idx != nil { |
| 889 | name = idx.Name |
| 890 | } |
| 891 | } |
| 892 | |
| 893 | return m.DB.Raw( |
| 894 | "SELECT count(*) FROM information_schema.statistics WHERE table_schema = ? AND table_name = ? AND index_name = ?", |
| 895 | currentDatabase, stmt.Table, name, |
| 896 | ).Row().Scan(&count) |
| 897 | }) |
| 898 | |
| 899 | return count > 0 |
| 900 | } |
| 901 | |
| 902 | // RenameIndex rename index from oldName to newName |
| 903 | func (m Migrator) RenameIndex(value interface{}, oldName, newName string) error { |
nothing calls this directly
no test coverage detected