Skip to content

Commit

Permalink
Merge branch 'feat/1.4.0/badge' into test
Browse files Browse the repository at this point in the history
  • Loading branch information
LinkinStars committed Aug 27, 2024
2 parents 16605ea + 9082623 commit 49db6e7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
21 changes: 0 additions & 21 deletions internal/migrations/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func (m *Mentor) InitDB() error {
m.do("init version table", m.initVersionTable)
m.do("init admin user", m.initAdminUser)
m.do("init config", m.initConfig)
m.do("init badge", m.initBadge)
m.do("init default privileges config", m.initDefaultRankPrivileges)
m.do("init role", m.initRole)
m.do("init power", m.initPower)
Expand Down Expand Up @@ -128,26 +127,6 @@ func (m *Mentor) initConfig() {
_, m.err = m.engine.Context(m.ctx).Insert(defaultConfigTable)
}

// initBadge init badge's table and data
func (m *Mentor) initBadge() {
uniqueIDRepo := unique.NewUniqueIDRepo(&data.Data{DB: m.engine})
_, m.err = m.engine.Context(m.ctx).Insert(defaultBadgeGroupTable)
if m.err != nil {
return
}

for _, badge := range defaultBadgeTable {
badge.ID, m.err = uniqueIDRepo.GenUniqueIDStr(m.ctx, new(entity.Badge).TableName())
if m.err != nil {
return
}
_, m.err = m.engine.Context(m.ctx).Insert(badge)
if m.err != nil {
return
}
}
}

func (m *Mentor) initDefaultRankPrivileges() {
chooseOption := schema.DefaultPrivilegeOptions.Choose(schema.PrivilegeLevel2)
for _, privilege := range chooseOption.Privileges {
Expand Down
5 changes: 4 additions & 1 deletion internal/migrations/v22.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,14 @@ func addBadges(ctx context.Context, x *xorm.Engine) (err error) {
}

for _, badge := range defaultBadgeTable {
exist, err := x.Context(ctx).Get(&entity.Badge{Name: badge.Name})
beans := &entity.Badge{Name: badge.Name}
exist, err := x.Context(ctx).Get(beans)
if err != nil {
return err
}
if exist {
badge.ID = beans.ID
_, err = x.Context(ctx).ID(beans.ID).Update(badge)
continue
}
badge.ID, err = uniqueIDRepo.GenUniqueIDStr(ctx, new(entity.Badge).TableName())
Expand Down

0 comments on commit 49db6e7

Please sign in to comment.