增加websocket支持
This commit is contained in:
		
							
								
								
									
										241
									
								
								vendor/gorm.io/gorm/migrator/migrator.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										241
									
								
								vendor/gorm.io/gorm/migrator/migrator.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -7,7 +7,6 @@ import ( | ||||
| 	"fmt" | ||||
| 	"reflect" | ||||
| 	"regexp" | ||||
| 	"strconv" | ||||
| 	"strings" | ||||
| 	"time" | ||||
|  | ||||
| @@ -28,8 +27,6 @@ var regFullDataType = regexp.MustCompile(`\D*(\d+)\D?`) | ||||
|  | ||||
| // TODO:? Create const vars for raw sql queries ? | ||||
|  | ||||
| var _ gorm.Migrator = (*Migrator)(nil) | ||||
|  | ||||
| // Migrator m struct | ||||
| type Migrator struct { | ||||
| 	Config | ||||
| @@ -94,6 +91,10 @@ func (m Migrator) FullDataTypeOf(field *schema.Field) (expr clause.Expr) { | ||||
| 		expr.SQL += " NOT NULL" | ||||
| 	} | ||||
|  | ||||
| 	if field.Unique { | ||||
| 		expr.SQL += " UNIQUE" | ||||
| 	} | ||||
|  | ||||
| 	if field.HasDefaultValue && (field.DefaultValueInterface != nil || field.DefaultValue != "") { | ||||
| 		if field.DefaultValueInterface != nil { | ||||
| 			defaultStmt := &gorm.Statement{Vars: []interface{}{field.DefaultValueInterface}} | ||||
| @@ -107,31 +108,21 @@ func (m Migrator) FullDataTypeOf(field *schema.Field) (expr clause.Expr) { | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (m Migrator) GetQueryAndExecTx() (queryTx, execTx *gorm.DB) { | ||||
| 	queryTx = m.DB.Session(&gorm.Session{}) | ||||
| 	execTx = queryTx | ||||
| 	if m.DB.DryRun { | ||||
| 		queryTx.DryRun = false | ||||
| 		execTx = m.DB.Session(&gorm.Session{Logger: &printSQLLogger{Interface: m.DB.Logger}}) | ||||
| 	} | ||||
| 	return queryTx, execTx | ||||
| } | ||||
|  | ||||
| // AutoMigrate auto migrate values | ||||
| func (m Migrator) AutoMigrate(values ...interface{}) error { | ||||
| 	for _, value := range m.ReorderModels(values, true) { | ||||
| 		queryTx, execTx := m.GetQueryAndExecTx() | ||||
| 		queryTx := m.DB.Session(&gorm.Session{}) | ||||
| 		execTx := queryTx | ||||
| 		if m.DB.DryRun { | ||||
| 			queryTx.DryRun = false | ||||
| 			execTx = m.DB.Session(&gorm.Session{Logger: &printSQLLogger{Interface: m.DB.Logger}}) | ||||
| 		} | ||||
| 		if !queryTx.Migrator().HasTable(value) { | ||||
| 			if err := execTx.Migrator().CreateTable(value); err != nil { | ||||
| 				return err | ||||
| 			} | ||||
| 		} else { | ||||
| 			if err := m.RunWithValue(value, func(stmt *gorm.Statement) error { | ||||
|  | ||||
| 				if stmt.Schema == nil { | ||||
| 					return errors.New("failed to get schema") | ||||
| 				} | ||||
|  | ||||
| 				columnTypes, err := queryTx.Migrator().ColumnTypes(value) | ||||
| 				if err != nil { | ||||
| 					return err | ||||
| @@ -216,11 +207,6 @@ func (m Migrator) CreateTable(values ...interface{}) error { | ||||
| 	for _, value := range m.ReorderModels(values, false) { | ||||
| 		tx := m.DB.Session(&gorm.Session{}) | ||||
| 		if err := m.RunWithValue(value, func(stmt *gorm.Statement) (err error) { | ||||
|  | ||||
| 			if stmt.Schema == nil { | ||||
| 				return errors.New("failed to get schema") | ||||
| 			} | ||||
|  | ||||
| 			var ( | ||||
| 				createTableSQL          = "CREATE TABLE ? (" | ||||
| 				values                  = []interface{}{m.CurrentTable(stmt)} | ||||
| @@ -280,7 +266,7 @@ func (m Migrator) CreateTable(values ...interface{}) error { | ||||
| 					} | ||||
| 					if constraint := rel.ParseConstraint(); constraint != nil { | ||||
| 						if constraint.Schema == stmt.Schema { | ||||
| 							sql, vars := constraint.Build() | ||||
| 							sql, vars := buildConstraint(constraint) | ||||
| 							createTableSQL += sql + "," | ||||
| 							values = append(values, vars...) | ||||
| 						} | ||||
| @@ -288,11 +274,6 @@ func (m Migrator) CreateTable(values ...interface{}) error { | ||||
| 				} | ||||
| 			} | ||||
|  | ||||
| 			for _, uni := range stmt.Schema.ParseUniqueConstraints() { | ||||
| 				createTableSQL += "CONSTRAINT ? UNIQUE (?)," | ||||
| 				values = append(values, clause.Column{Name: uni.Name}, clause.Expr{SQL: stmt.Quote(uni.Field.DBName)}) | ||||
| 			} | ||||
|  | ||||
| 			for _, chk := range stmt.Schema.ParseCheckConstraints() { | ||||
| 				createTableSQL += "CONSTRAINT ? CHECK (?)," | ||||
| 				values = append(values, clause.Column{Name: chk.Name}, clause.Expr{SQL: chk.Constraint}) | ||||
| @@ -373,9 +354,6 @@ func (m Migrator) RenameTable(oldName, newName interface{}) error { | ||||
| func (m Migrator) AddColumn(value interface{}, name string) error { | ||||
| 	return m.RunWithValue(value, func(stmt *gorm.Statement) error { | ||||
| 		// avoid using the same name field | ||||
| 		if stmt.Schema == nil { | ||||
| 			return errors.New("failed to get schema") | ||||
| 		} | ||||
| 		f := stmt.Schema.LookUpField(name) | ||||
| 		if f == nil { | ||||
| 			return fmt.Errorf("failed to look up field with name: %s", name) | ||||
| @@ -395,10 +373,8 @@ func (m Migrator) AddColumn(value interface{}, name string) error { | ||||
| // DropColumn drop value's `name` column | ||||
| func (m Migrator) DropColumn(value interface{}, name string) error { | ||||
| 	return m.RunWithValue(value, func(stmt *gorm.Statement) error { | ||||
| 		if stmt.Schema != nil { | ||||
| 			if field := stmt.Schema.LookUpField(name); field != nil { | ||||
| 				name = field.DBName | ||||
| 			} | ||||
| 		if field := stmt.Schema.LookUpField(name); field != nil { | ||||
| 			name = field.DBName | ||||
| 		} | ||||
|  | ||||
| 		return m.DB.Exec( | ||||
| @@ -410,15 +386,13 @@ func (m Migrator) DropColumn(value interface{}, name string) error { | ||||
| // AlterColumn alter value's `field` column' type based on schema definition | ||||
| func (m Migrator) AlterColumn(value interface{}, field string) error { | ||||
| 	return m.RunWithValue(value, func(stmt *gorm.Statement) error { | ||||
| 		if stmt.Schema != nil { | ||||
| 			if field := stmt.Schema.LookUpField(field); field != nil { | ||||
| 				fileType := m.FullDataTypeOf(field) | ||||
| 				return m.DB.Exec( | ||||
| 					"ALTER TABLE ? ALTER COLUMN ? TYPE ?", | ||||
| 					m.CurrentTable(stmt), clause.Column{Name: field.DBName}, fileType, | ||||
| 				).Error | ||||
| 		if field := stmt.Schema.LookUpField(field); field != nil { | ||||
| 			fileType := m.FullDataTypeOf(field) | ||||
| 			return m.DB.Exec( | ||||
| 				"ALTER TABLE ? ALTER COLUMN ? TYPE ?", | ||||
| 				m.CurrentTable(stmt), clause.Column{Name: field.DBName}, fileType, | ||||
| 			).Error | ||||
|  | ||||
| 			} | ||||
| 		} | ||||
| 		return fmt.Errorf("failed to look up field with name: %s", field) | ||||
| 	}) | ||||
| @@ -430,10 +404,8 @@ func (m Migrator) HasColumn(value interface{}, field string) bool { | ||||
| 	m.RunWithValue(value, func(stmt *gorm.Statement) error { | ||||
| 		currentDatabase := m.DB.Migrator().CurrentDatabase() | ||||
| 		name := field | ||||
| 		if stmt.Schema != nil { | ||||
| 			if field := stmt.Schema.LookUpField(field); field != nil { | ||||
| 				name = field.DBName | ||||
| 			} | ||||
| 		if field := stmt.Schema.LookUpField(field); field != nil { | ||||
| 			name = field.DBName | ||||
| 		} | ||||
|  | ||||
| 		return m.DB.Raw( | ||||
| @@ -448,14 +420,12 @@ func (m Migrator) HasColumn(value interface{}, field string) bool { | ||||
| // RenameColumn rename value's field name from oldName to newName | ||||
| func (m Migrator) RenameColumn(value interface{}, oldName, newName string) error { | ||||
| 	return m.RunWithValue(value, func(stmt *gorm.Statement) error { | ||||
| 		if stmt.Schema != nil { | ||||
| 			if field := stmt.Schema.LookUpField(oldName); field != nil { | ||||
| 				oldName = field.DBName | ||||
| 			} | ||||
| 		if field := stmt.Schema.LookUpField(oldName); field != nil { | ||||
| 			oldName = field.DBName | ||||
| 		} | ||||
|  | ||||
| 			if field := stmt.Schema.LookUpField(newName); field != nil { | ||||
| 				newName = field.DBName | ||||
| 			} | ||||
| 		if field := stmt.Schema.LookUpField(newName); field != nil { | ||||
| 			newName = field.DBName | ||||
| 		} | ||||
|  | ||||
| 		return m.DB.Exec( | ||||
| @@ -467,10 +437,6 @@ func (m Migrator) RenameColumn(value interface{}, oldName, newName string) error | ||||
|  | ||||
| // MigrateColumn migrate column | ||||
| func (m Migrator) MigrateColumn(value interface{}, field *schema.Field, columnType gorm.ColumnType) error { | ||||
| 	if field.IgnoreMigration { | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	// found, smart migrate | ||||
| 	fullDataType := strings.TrimSpace(strings.ToLower(m.DB.Migrator().FullDataTypeOf(field).SQL)) | ||||
| 	realDataType := strings.ToLower(columnType.DatabaseTypeName()) | ||||
| @@ -530,6 +496,14 @@ func (m Migrator) MigrateColumn(value interface{}, field *schema.Field, columnTy | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	// check unique | ||||
| 	if unique, ok := columnType.Unique(); ok && unique != field.Unique { | ||||
| 		// not primary key | ||||
| 		if !field.PrimaryKey { | ||||
| 			alterColumn = true | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	// check default value | ||||
| 	if !field.PrimaryKey { | ||||
| 		currentDefaultNotNull := field.HasDefaultValue && (field.DefaultValueInterface != nil || !strings.EqualFold(field.DefaultValue, "NULL")) | ||||
| @@ -540,18 +514,12 @@ func (m Migrator) MigrateColumn(value interface{}, field *schema.Field, columnTy | ||||
| 		} else if !dvNotNull && currentDefaultNotNull { | ||||
| 			// null -> default value | ||||
| 			alterColumn = true | ||||
| 		} else if currentDefaultNotNull || dvNotNull { | ||||
| 			switch field.GORMDataType { | ||||
| 			case schema.Time: | ||||
| 				if !strings.EqualFold(strings.TrimSuffix(dv, "()"), strings.TrimSuffix(field.DefaultValue, "()")) { | ||||
| 					alterColumn = true | ||||
| 				} | ||||
| 			case schema.Bool: | ||||
| 				v1, _ := strconv.ParseBool(dv) | ||||
| 				v2, _ := strconv.ParseBool(field.DefaultValue) | ||||
| 				alterColumn = v1 != v2 | ||||
| 			default: | ||||
| 				alterColumn = dv != field.DefaultValue | ||||
| 		} else if (field.GORMDataType != schema.Time && dv != field.DefaultValue) || | ||||
| 			(field.GORMDataType == schema.Time && !strings.EqualFold(strings.TrimSuffix(dv, "()"), strings.TrimSuffix(field.DefaultValue, "()"))) { | ||||
| 			// default value not equal | ||||
| 			// not both null | ||||
| 			if currentDefaultNotNull || dvNotNull { | ||||
| 				alterColumn = true | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| @@ -564,39 +532,13 @@ func (m Migrator) MigrateColumn(value interface{}, field *schema.Field, columnTy | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if alterColumn { | ||||
| 		if err := m.DB.Migrator().AlterColumn(value, field.DBName); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if err := m.DB.Migrator().MigrateColumnUnique(value, field, columnType); err != nil { | ||||
| 		return err | ||||
| 	if alterColumn && !field.IgnoreMigration { | ||||
| 		return m.DB.Migrator().AlterColumn(value, field.DBName) | ||||
| 	} | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func (m Migrator) MigrateColumnUnique(value interface{}, field *schema.Field, columnType gorm.ColumnType) error { | ||||
| 	unique, ok := columnType.Unique() | ||||
| 	if !ok || field.PrimaryKey { | ||||
| 		return nil // skip primary key | ||||
| 	} | ||||
| 	// By default, ColumnType's Unique is not affected by UniqueIndex, so we don't care about UniqueIndex. | ||||
| 	return m.RunWithValue(value, func(stmt *gorm.Statement) error { | ||||
| 		// We're currently only receiving boolean values on `Unique` tag, | ||||
| 		// so the UniqueConstraint name is fixed | ||||
| 		constraint := m.DB.NamingStrategy.UniqueName(stmt.Table, field.DBName) | ||||
| 		if unique && !field.Unique { | ||||
| 			return m.DB.Migrator().DropConstraint(value, constraint) | ||||
| 		} | ||||
| 		if !unique && field.Unique { | ||||
| 			return m.DB.Migrator().CreateConstraint(value, constraint) | ||||
| 		} | ||||
| 		return nil | ||||
| 	}) | ||||
| } | ||||
|  | ||||
| // ColumnTypes return columnTypes []gorm.ColumnType and execErr error | ||||
| func (m Migrator) ColumnTypes(value interface{}) ([]gorm.ColumnType, error) { | ||||
| 	columnTypes := make([]gorm.ColumnType, 0) | ||||
| @@ -666,36 +608,37 @@ func (m Migrator) DropView(name string) error { | ||||
| 	return m.DB.Exec("DROP VIEW IF EXISTS ?", clause.Table{Name: name}).Error | ||||
| } | ||||
|  | ||||
| // GuessConstraintAndTable guess statement's constraint and it's table based on name | ||||
| // | ||||
| // Deprecated: use GuessConstraintInterfaceAndTable instead. | ||||
| func (m Migrator) GuessConstraintAndTable(stmt *gorm.Statement, name string) (*schema.Constraint, *schema.CheckConstraint, string) { | ||||
| 	constraint, table := m.GuessConstraintInterfaceAndTable(stmt, name) | ||||
| 	switch c := constraint.(type) { | ||||
| 	case *schema.Constraint: | ||||
| 		return c, nil, table | ||||
| 	case *schema.CheckConstraint: | ||||
| 		return nil, c, table | ||||
| 	default: | ||||
| 		return nil, nil, table | ||||
| func buildConstraint(constraint *schema.Constraint) (sql string, results []interface{}) { | ||||
| 	sql = "CONSTRAINT ? FOREIGN KEY ? REFERENCES ??" | ||||
| 	if constraint.OnDelete != "" { | ||||
| 		sql += " ON DELETE " + constraint.OnDelete | ||||
| 	} | ||||
|  | ||||
| 	if constraint.OnUpdate != "" { | ||||
| 		sql += " ON UPDATE " + constraint.OnUpdate | ||||
| 	} | ||||
|  | ||||
| 	var foreignKeys, references []interface{} | ||||
| 	for _, field := range constraint.ForeignKeys { | ||||
| 		foreignKeys = append(foreignKeys, clause.Column{Name: field.DBName}) | ||||
| 	} | ||||
|  | ||||
| 	for _, field := range constraint.References { | ||||
| 		references = append(references, clause.Column{Name: field.DBName}) | ||||
| 	} | ||||
| 	results = append(results, clause.Table{Name: constraint.Name}, foreignKeys, clause.Table{Name: constraint.ReferenceSchema.Table}, references) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| // GuessConstraintInterfaceAndTable guess statement's constraint and it's table based on name | ||||
| // nolint:cyclop | ||||
| func (m Migrator) GuessConstraintInterfaceAndTable(stmt *gorm.Statement, name string) (_ schema.ConstraintInterface, table string) { | ||||
| // GuessConstraintAndTable guess statement's constraint and it's table based on name | ||||
| func (m Migrator) GuessConstraintAndTable(stmt *gorm.Statement, name string) (_ *schema.Constraint, _ *schema.Check, table string) { | ||||
| 	if stmt.Schema == nil { | ||||
| 		return nil, stmt.Table | ||||
| 		return nil, nil, stmt.Table | ||||
| 	} | ||||
|  | ||||
| 	checkConstraints := stmt.Schema.ParseCheckConstraints() | ||||
| 	if chk, ok := checkConstraints[name]; ok { | ||||
| 		return &chk, stmt.Table | ||||
| 	} | ||||
|  | ||||
| 	uniqueConstraints := stmt.Schema.ParseUniqueConstraints() | ||||
| 	if uni, ok := uniqueConstraints[name]; ok { | ||||
| 		return &uni, stmt.Table | ||||
| 		return nil, &chk, stmt.Table | ||||
| 	} | ||||
|  | ||||
| 	getTable := func(rel *schema.Relationship) string { | ||||
| @@ -710,7 +653,7 @@ func (m Migrator) GuessConstraintInterfaceAndTable(stmt *gorm.Statement, name st | ||||
|  | ||||
| 	for _, rel := range stmt.Schema.Relationships.Relations { | ||||
| 		if constraint := rel.ParseConstraint(); constraint != nil && constraint.Name == name { | ||||
| 			return constraint, getTable(rel) | ||||
| 			return constraint, nil, getTable(rel) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| @@ -718,39 +661,40 @@ func (m Migrator) GuessConstraintInterfaceAndTable(stmt *gorm.Statement, name st | ||||
| 		for k := range checkConstraints { | ||||
| 			if checkConstraints[k].Field == field { | ||||
| 				v := checkConstraints[k] | ||||
| 				return &v, stmt.Table | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		for k := range uniqueConstraints { | ||||
| 			if uniqueConstraints[k].Field == field { | ||||
| 				v := uniqueConstraints[k] | ||||
| 				return &v, stmt.Table | ||||
| 				return nil, &v, stmt.Table | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		for _, rel := range stmt.Schema.Relationships.Relations { | ||||
| 			if constraint := rel.ParseConstraint(); constraint != nil && rel.Field == field { | ||||
| 				return constraint, getTable(rel) | ||||
| 				return constraint, nil, getTable(rel) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return nil, stmt.Schema.Table | ||||
| 	return nil, nil, stmt.Schema.Table | ||||
| } | ||||
|  | ||||
| // CreateConstraint create constraint | ||||
| func (m Migrator) CreateConstraint(value interface{}, name string) error { | ||||
| 	return m.RunWithValue(value, func(stmt *gorm.Statement) error { | ||||
| 		constraint, table := m.GuessConstraintInterfaceAndTable(stmt, name) | ||||
| 		constraint, chk, table := m.GuessConstraintAndTable(stmt, name) | ||||
| 		if chk != nil { | ||||
| 			return m.DB.Exec( | ||||
| 				"ALTER TABLE ? ADD CONSTRAINT ? CHECK (?)", | ||||
| 				m.CurrentTable(stmt), clause.Column{Name: chk.Name}, clause.Expr{SQL: chk.Constraint}, | ||||
| 			).Error | ||||
| 		} | ||||
|  | ||||
| 		if constraint != nil { | ||||
| 			vars := []interface{}{clause.Table{Name: table}} | ||||
| 			if stmt.TableExpr != nil { | ||||
| 				vars[0] = stmt.TableExpr | ||||
| 			} | ||||
| 			sql, values := constraint.Build() | ||||
| 			sql, values := buildConstraint(constraint) | ||||
| 			return m.DB.Exec("ALTER TABLE ? ADD "+sql, append(vars, values...)...).Error | ||||
| 		} | ||||
|  | ||||
| 		return nil | ||||
| 	}) | ||||
| } | ||||
| @@ -758,9 +702,11 @@ func (m Migrator) CreateConstraint(value interface{}, name string) error { | ||||
| // DropConstraint drop constraint | ||||
| func (m Migrator) DropConstraint(value interface{}, name string) error { | ||||
| 	return m.RunWithValue(value, func(stmt *gorm.Statement) error { | ||||
| 		constraint, table := m.GuessConstraintInterfaceAndTable(stmt, name) | ||||
| 		constraint, chk, table := m.GuessConstraintAndTable(stmt, name) | ||||
| 		if constraint != nil { | ||||
| 			name = constraint.GetName() | ||||
| 			name = constraint.Name | ||||
| 		} else if chk != nil { | ||||
| 			name = chk.Name | ||||
| 		} | ||||
| 		return m.DB.Exec("ALTER TABLE ? DROP CONSTRAINT ?", clause.Table{Name: table}, clause.Column{Name: name}).Error | ||||
| 	}) | ||||
| @@ -771,9 +717,11 @@ func (m Migrator) HasConstraint(value interface{}, name string) bool { | ||||
| 	var count int64 | ||||
| 	m.RunWithValue(value, func(stmt *gorm.Statement) error { | ||||
| 		currentDatabase := m.DB.Migrator().CurrentDatabase() | ||||
| 		constraint, table := m.GuessConstraintInterfaceAndTable(stmt, name) | ||||
| 		constraint, chk, table := m.GuessConstraintAndTable(stmt, name) | ||||
| 		if constraint != nil { | ||||
| 			name = constraint.GetName() | ||||
| 			name = constraint.Name | ||||
| 		} else if chk != nil { | ||||
| 			name = chk.Name | ||||
| 		} | ||||
|  | ||||
| 		return m.DB.Raw( | ||||
| @@ -815,9 +763,6 @@ type BuildIndexOptionsInterface interface { | ||||
| // CreateIndex create index `name` | ||||
| func (m Migrator) CreateIndex(value interface{}, name string) error { | ||||
| 	return m.RunWithValue(value, func(stmt *gorm.Statement) error { | ||||
| 		if stmt.Schema == nil { | ||||
| 			return errors.New("failed to get schema") | ||||
| 		} | ||||
| 		if idx := stmt.Schema.LookIndex(name); idx != nil { | ||||
| 			opts := m.DB.Migrator().(BuildIndexOptionsInterface).BuildIndexOptions(idx.Fields, stmt) | ||||
| 			values := []interface{}{clause.Column{Name: idx.Name}, m.CurrentTable(stmt), opts} | ||||
| @@ -850,10 +795,8 @@ func (m Migrator) CreateIndex(value interface{}, name string) error { | ||||
| // DropIndex drop index `name` | ||||
| func (m Migrator) DropIndex(value interface{}, name string) error { | ||||
| 	return m.RunWithValue(value, func(stmt *gorm.Statement) error { | ||||
| 		if stmt.Schema != nil { | ||||
| 			if idx := stmt.Schema.LookIndex(name); idx != nil { | ||||
| 				name = idx.Name | ||||
| 			} | ||||
| 		if idx := stmt.Schema.LookIndex(name); idx != nil { | ||||
| 			name = idx.Name | ||||
| 		} | ||||
|  | ||||
| 		return m.DB.Exec("DROP INDEX ? ON ?", clause.Column{Name: name}, m.CurrentTable(stmt)).Error | ||||
| @@ -865,10 +808,8 @@ func (m Migrator) HasIndex(value interface{}, name string) bool { | ||||
| 	var count int64 | ||||
| 	m.RunWithValue(value, func(stmt *gorm.Statement) error { | ||||
| 		currentDatabase := m.DB.Migrator().CurrentDatabase() | ||||
| 		if stmt.Schema != nil { | ||||
| 			if idx := stmt.Schema.LookIndex(name); idx != nil { | ||||
| 				name = idx.Name | ||||
| 			} | ||||
| 		if idx := stmt.Schema.LookIndex(name); idx != nil { | ||||
| 			name = idx.Name | ||||
| 		} | ||||
|  | ||||
| 		return m.DB.Raw( | ||||
|   | ||||
		Reference in New Issue
	
	Block a user