update upgrade pin list

This commit is contained in:
aichy126
2023-04-25 14:16:51 +08:00
parent 587f0aa1e3
commit 201a776cd6
2 changed files with 39 additions and 0 deletions
+1
View File
@@ -58,6 +58,7 @@ var migrations = []Migration{
NewMigration("add new answer notification", addNewAnswerNotification, true),
NewMigration("add user pin hide features", addRolePinAndHideFeatures, true),
NewMigration("update accept answer rank", updateAcceptAnswerRank, true),
NewMigration("update user pin hide features", updateRolePinAndHideFeatures, true),
}
// GetCurrentDBVersion returns the current db version
+38
View File
@@ -0,0 +1,38 @@
package migrations
import (
"fmt"
"github.com/answerdev/answer/internal/entity"
"github.com/segmentfault/pacman/log"
"xorm.io/xorm"
)
func updateRolePinAndHideFeatures(x *xorm.Engine) error {
defaultConfigTable := []*entity.Config{
{ID: 119, Key: "rank.question.pin", Value: `-1`},
{ID: 120, Key: "rank.question.unpin", Value: `-1`},
{ID: 121, Key: "rank.question.show", Value: `-1`},
{ID: 122, Key: "rank.question.hide", Value: `-1`},
}
for _, c := range defaultConfigTable {
exist, err := x.Get(&entity.Config{ID: c.ID})
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, Value: c.Value}); 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
}