Browse Source

增加删除组织用户的历史数据。

Signed-off-by: zouap <zouap@pcl.ac.cn>
tags/v1.21.12.1^2
zouap 4 years ago
parent
commit
c74a8f7636
1 changed files with 19 additions and 0 deletions
  1. +19
    -0
      models/custom_migrations.go

+ 19
- 0
models/custom_migrations.go View File

@@ -1,6 +1,8 @@
package models

import (
"fmt"

"code.gitea.io/gitea/modules/log"
"xorm.io/xorm"
)
@@ -12,6 +14,7 @@ type CustomMigration struct {

var customMigrations = []CustomMigration{
{"Custom v1 Topic struct change to support chinese", syncTopicStruct},
{"Delete zuzhi user history data ", deleteNotDisplayUser},
}

var customMigrationsStatic = []CustomMigration{}
@@ -47,3 +50,19 @@ func syncTopicStruct(x *xorm.Engine) error {
_, err := x.Exec(query)
return err
}

func deleteNotDisplayUser(x *xorm.Engine) error {

sess := x.NewSession()
defer sess.Close()
sess.Select("`user`.*").Table("user").Where("type == 1")
userList := make([]*User, 0)

for i, userRecord := range userList {
log.Info("delete zuzi user, i=" + fmt.Sprint(i) + " userName=" + userRecord.Name)
deleteSql := "delete from user_business_analysis where id=" + fmt.Sprint(userRecord.ID) + " and name='" + userRecord.Name + "'"
xStatistic.Exec(deleteSql)
}

return nil
}

Loading…
Cancel
Save