From 076e9777eec30f285c6adce269052ebbce23ab76 Mon Sep 17 00:00:00 2001 From: qqxhb <1252905006@qq.com> Date: Thu, 16 Jun 2022 19:36:14 +0800 Subject: [PATCH] feat: add method GetIndexes --- migrator.go | 9 +++++++++ migrator/migrator.go | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/migrator.go b/migrator.go index 52443877..39c4871b 100644 --- a/migrator.go +++ b/migrator.go @@ -50,6 +50,14 @@ type ColumnType interface { Comment() (value string, ok bool) DefaultValue() (value string, ok bool) } +type Index interface { + Table() string + Name() string + Columns() []string + PrimaryKey() (isPrimaryKey bool, ok bool) + Unique() (unique bool, ok bool) + Option() string +} // Migrator migrator interface type Migrator interface { @@ -90,4 +98,5 @@ type Migrator interface { DropIndex(dst interface{}, name string) error HasIndex(dst interface{}, name string) bool RenameIndex(dst interface{}, oldName, newName string) error + GetIndexes(dst interface{}) ([]Index, error) } diff --git a/migrator/migrator.go b/migrator/migrator.go index 4acc9df6..f20bf513 100644 --- a/migrator/migrator.go +++ b/migrator/migrator.go @@ -3,6 +3,7 @@ package migrator import ( "context" "database/sql" + "errors" "fmt" "reflect" "regexp" @@ -854,3 +855,8 @@ func (m Migrator) CurrentTable(stmt *gorm.Statement) interface{} { } return clause.Table{Name: stmt.Table} } + +// GetIndexes return Indexes []gorm.Index and execErr error +func (m Migrator) GetIndexes(dst interface{}) ([]gorm.Index, error) { + return nil, errors.New("not support") +}