From c74a8f76369ec13ddf3ab7c72cce526b3a716751 Mon Sep 17 00:00:00 2001 From: zouap Date: Mon, 15 Nov 2021 10:40:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=88=A0=E9=99=A4=E7=BB=84?= =?UTF-8?q?=E7=BB=87=E7=94=A8=E6=88=B7=E7=9A=84=E5=8E=86=E5=8F=B2=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- models/custom_migrations.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/models/custom_migrations.go b/models/custom_migrations.go index 0b9a0d552..9cb0545b7 100644 --- a/models/custom_migrations.go +++ b/models/custom_migrations.go @@ -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 +}