From 870d07377ddb9decc2cf5fa2b44ca9231b5fab81 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 12 Mar 2024 16:24:32 +0800 Subject: [PATCH] Support not drop index when sync --- sync.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sync.go b/sync.go index adc2d859..f1b5e59f 100644 --- a/sync.go +++ b/sync.go @@ -17,6 +17,8 @@ type SyncOptions struct { IgnoreConstrains bool // IgnoreIndices will not add or delete indices IgnoreIndices bool + // IgnoreDropIndices will not delete indices + IgnoreDropIndices bool } type SyncResult struct{} @@ -55,6 +57,7 @@ func (session *Session) Sync(beans ...interface{}) error { WarnIfDatabaseColumnMissed: false, IgnoreConstrains: false, IgnoreIndices: false, + IgnoreDropIndices: false, }, beans...) return err } @@ -244,7 +247,7 @@ func (session *Session) SyncWithOptions(opts SyncOptions, beans ...interface{}) for name2, index2 := range oriTable.Indexes { if _, ok := foundIndexNames[name2]; !ok { // 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) { // make sure we do not add a index with same name later delete(addedNames, name2)