Support not drop index when sync
This commit is contained in:
parent
63222312b2
commit
870d07377d
5
sync.go
5
sync.go
|
@ -17,6 +17,8 @@ type SyncOptions struct {
|
||||||
IgnoreConstrains bool
|
IgnoreConstrains bool
|
||||||
// IgnoreIndices will not add or delete indices
|
// IgnoreIndices will not add or delete indices
|
||||||
IgnoreIndices bool
|
IgnoreIndices bool
|
||||||
|
// IgnoreDropIndices will not delete indices
|
||||||
|
IgnoreDropIndices bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type SyncResult struct{}
|
type SyncResult struct{}
|
||||||
|
@ -55,6 +57,7 @@ func (session *Session) Sync(beans ...interface{}) error {
|
||||||
WarnIfDatabaseColumnMissed: false,
|
WarnIfDatabaseColumnMissed: false,
|
||||||
IgnoreConstrains: false,
|
IgnoreConstrains: false,
|
||||||
IgnoreIndices: false,
|
IgnoreIndices: false,
|
||||||
|
IgnoreDropIndices: false,
|
||||||
}, beans...)
|
}, beans...)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -244,7 +247,7 @@ func (session *Session) SyncWithOptions(opts SyncOptions, beans ...interface{})
|
||||||
for name2, index2 := range oriTable.Indexes {
|
for name2, index2 := range oriTable.Indexes {
|
||||||
if _, ok := foundIndexNames[name2]; !ok {
|
if _, ok := foundIndexNames[name2]; !ok {
|
||||||
// ignore based on there type
|
// ignore based on there type
|
||||||
if (index2.Type == schemas.IndexType && opts.IgnoreIndices) ||
|
if (index2.Type == schemas.IndexType && (opts.IgnoreIndices || opts.IgnoreDropIndices)) ||
|
||||||
(index2.Type == schemas.UniqueType && opts.IgnoreConstrains) {
|
(index2.Type == schemas.UniqueType && opts.IgnoreConstrains) {
|
||||||
// make sure we do not add a index with same name later
|
// make sure we do not add a index with same name later
|
||||||
delete(addedNames, name2)
|
delete(addedNames, name2)
|
||||||
|
|
Loading…
Reference in New Issue