From 13120b6d55942252b02608ac1393dc4d6df32895 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sat, 16 Sep 2023 14:41:02 +0000 Subject: [PATCH] Remove dead code from session.SyncWithOptions() (#2323) https://gitea.com/xorm/xorm/src/commit/db7c2640627d24539aa4607f50bcba7037ddd9e6/sync.go#L229-L231 as oriIndex only is **not** nil if index.Equal(index2) and index.Equal(index2) check if `oriIndex.Type == index.Type` ... so it always is false Co-authored-by: Lunny Xiao Reviewed-on: https://gitea.com/xorm/xorm/pulls/2323 Reviewed-by: Lunny Xiao Co-authored-by: 6543 <6543@obermui.de> Co-committed-by: 6543 <6543@obermui.de> (cherry picked from commit e5be0f4129217de60b5dcf0976a282fb1b781690) --- sync.go | 9 --------- tests/sync_test.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 tests/sync_test.go diff --git a/sync.go b/sync.go index 9e1cb8c1..adc2d859 100644 --- a/sync.go +++ b/sync.go @@ -235,15 +235,6 @@ func (session *Session) SyncWithOptions(opts SyncOptions, beans ...interface{}) } } - if oriIndex != nil && oriIndex.Type != index.Type { - sql := engine.dialect.DropIndexSQL(tbNameWithSchema, oriIndex) - _, err = session.exec(sql) - if err != nil { - return nil, err - } - oriIndex = nil - } - if oriIndex == nil { addedNames[name] = index } diff --git a/tests/sync_test.go b/tests/sync_test.go new file mode 100644 index 00000000..dedd3343 --- /dev/null +++ b/tests/sync_test.go @@ -0,0 +1,34 @@ +// Copyright 2023 The Xorm Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package tests + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +type TestSync1 struct { + Id int64 + ClassId int64 `xorm:"index"` +} + +func (TestSync1) TableName() string { + return "test_sync" +} + +type TestSync2 struct { + Id int64 + ClassId int64 `xorm:"unique"` +} + +func (TestSync2) TableName() string { + return "test_sync" +} + +func TestSync(t *testing.T) { + assert.NoError(t, testEngine.Sync(new(TestSync1))) + assert.NoError(t, testEngine.Sync(new(TestSync2))) +}