fix(migrations): add question rank default level

This commit is contained in:
LinkinStar 2022-12-07 18:29:16 +08:00
parent 3f88ba097d
commit 0fa30bbbaa
1 changed files with 25 additions and 0 deletions

View File

@ -1,8 +1,11 @@
package migrations
import (
"fmt"
"github.com/answerdev/answer/internal/entity"
"github.com/answerdev/answer/internal/service/permission"
"github.com/segmentfault/pacman/log"
"xorm.io/xorm"
)
@ -183,5 +186,27 @@ func addRoleFeatures(x *xorm.Engine) error {
return err
}
}
defaultConfigTable := []*entity.Config{
{ID: 115, Key: "rank.question.close", Value: `-1`},
{ID: 116, Key: "rank.question.reopen", Value: `-1`},
}
for _, c := range defaultConfigTable {
exist, err := x.Get(&entity.Config{ID: c.ID, Key: c.Key})
if err != nil {
return fmt.Errorf("get config failed: %w", err)
}
if exist {
if _, err = x.Update(c, &entity.Config{ID: c.ID, Key: c.Key}); err != nil {
log.Errorf("update %+v config failed: %s", c, err)
return fmt.Errorf("update config failed: %w", err)
}
continue
}
if _, err = x.Insert(&entity.Config{ID: c.ID, Key: c.Key, Value: c.Value}); err != nil {
log.Errorf("insert %+v config failed: %s", c, err)
return fmt.Errorf("add config failed: %w", err)
}
}
return nil
}