From 708d85763c12c8ebf4d52410d02595df76da959d Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Mon, 9 Mar 2015 21:33:25 +0800 Subject: [PATCH] Dialect Index first, before AddIndex --- scope_private.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scope_private.go b/scope_private.go index 40aeaca8..3745f0fc 100644 --- a/scope_private.go +++ b/scope_private.go @@ -492,6 +492,10 @@ func (scope *Scope) dropColumn(column string) { } func (scope *Scope) addIndex(unique bool, indexName string, column ...string) { + if scope.Dialect().HasIndex(scope, scope.TableName(), indexName) { + return + } + var columns []string for _, name := range column { columns = append(columns, scope.Quote(name)) @@ -559,15 +563,11 @@ func (scope *Scope) autoIndex() *Scope { } for name, columns := range indexes { - if !scope.Dialect().HasIndex(scope, scope.TableName(), name) { - scope.addIndex(false, name, columns...) - } + scope.addIndex(false, name, columns...) } for name, columns := range uniqueIndexes { - if !scope.Dialect().HasIndex(scope, scope.TableName(), name) { - scope.addIndex(true, name, columns...) - } + scope.addIndex(true, name, columns...) } return scope