bug fixed for sync2
This commit is contained in:
parent
76eef59c8f
commit
2ee7de9fa5
27
session.go
27
session.go
|
@ -3889,6 +3889,7 @@ func (s *Session) Sync2(beans ...interface{}) error {
|
|||
}
|
||||
|
||||
var foundIndexNames = make(map[string]bool)
|
||||
var addedNames = make(map[string]*core.Index)
|
||||
|
||||
for name, index := range table.Indexes {
|
||||
var oriIndex *core.Index
|
||||
|
@ -3912,6 +3913,21 @@ func (s *Session) Sync2(beans ...interface{}) error {
|
|||
}
|
||||
|
||||
if oriIndex == nil {
|
||||
addedNames[name] = index
|
||||
}
|
||||
}
|
||||
|
||||
for name2, index2 := range oriTable.Indexes {
|
||||
if _, ok := foundIndexNames[name2]; !ok {
|
||||
sql := engine.dialect.DropIndexSql(table.Name, index2)
|
||||
_, err = engine.Exec(sql)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for name, index := range addedNames {
|
||||
if index.Type == core.UniqueType {
|
||||
session := engine.NewSession()
|
||||
session.Statement.RefTable = table
|
||||
|
@ -3928,17 +3944,6 @@ func (s *Session) Sync2(beans ...interface{}) error {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
for name2, index2 := range oriTable.Indexes {
|
||||
if _, ok := foundIndexNames[name2]; !ok {
|
||||
sql := engine.dialect.DropIndexSql(table.Name, index2)
|
||||
_, err = engine.Exec(sql)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, table := range tables {
|
||||
|
|
Loading…
Reference in New Issue