code.gitea.io/gitea@v1.21.7/models/migrations/v1_12/v126.go (about) 1 // Copyright 2020 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package v1_12 //nolint 5 6 import ( 7 "xorm.io/builder" 8 "xorm.io/xorm" 9 ) 10 11 func FixTopicRepositoryCount(x *xorm.Engine) error { 12 _, err := x.Exec(builder.Delete(builder.NotIn("`repo_id`", builder.Select("`id`").From("`repository`"))).From("`repo_topic`")) 13 if err != nil { 14 return err 15 } 16 17 _, err = x.Exec(builder.Update( 18 builder.Eq{ 19 "`repo_count`": builder.Select("count(*)").From("`repo_topic`").Where(builder.Eq{ 20 "`repo_topic`.`topic_id`": builder.Expr("`topic`.`id`"), 21 }), 22 }).From("`topic`").Where(builder.Eq{"'1'": "1"})) 23 return err 24 }