gitea源码

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