Backport #28243
Setting the same value should not trigger DuplicateKey error, and the
"version" should be increased
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
(cherry picked from commit ea9f5a57e4
)
This commit is contained in:
parent
ce5260565c
commit
b63749b94c
2 changed files with 13 additions and 1 deletions
|
@ -81,7 +81,7 @@ func SetSettings(ctx context.Context, settings map[string]string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for k, v := range settings {
|
for k, v := range settings {
|
||||||
res, err := e.Exec("UPDATE system_setting SET setting_value=? WHERE setting_key=?", v, k)
|
res, err := e.Exec("UPDATE system_setting SET version=version+1, setting_value=? WHERE setting_key=?", v, k)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,4 +39,16 @@ func TestSettings(t *testing.T) {
|
||||||
assert.EqualValues(t, 3, rev)
|
assert.EqualValues(t, 3, rev)
|
||||||
assert.Len(t, settings, 2)
|
assert.Len(t, settings, 2)
|
||||||
assert.EqualValues(t, "false", settings[keyName])
|
assert.EqualValues(t, "false", settings[keyName])
|
||||||
|
|
||||||
|
// setting the same value should not trigger DuplicateKey error, and the "version" should be increased
|
||||||
|
setting := &system.Setting{SettingKey: keyName}
|
||||||
|
_, err = db.GetByBean(db.DefaultContext, setting)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.EqualValues(t, 2, setting.Version)
|
||||||
|
err = system.SetSettings(db.DefaultContext, map[string]string{keyName: "false"})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
setting = &system.Setting{SettingKey: keyName}
|
||||||
|
_, err = db.GetByBean(db.DefaultContext, setting)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.EqualValues(t, 3, setting.Version)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue