Fork to maintain patches against the official gitea for https://code.ceondo.com https://github.com/go-gitea/gitea

v46.go 1000B

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package migrations
  5. import (
  6. "github.com/go-xorm/xorm"
  7. )
  8. func removeOrganizationWatchRepo(x *xorm.Engine) error {
  9. // UserType defines the user type
  10. type UserType int
  11. const (
  12. // UserTypeIndividual defines an individual user
  13. UserTypeIndividual UserType = iota // Historic reason to make it starts at 0.
  14. // UserTypeOrganization defines an organization
  15. UserTypeOrganization
  16. )
  17. sess := x.NewSession()
  18. defer sess.Close()
  19. if err := sess.Begin(); err != nil {
  20. return err
  21. }
  22. if _, err := sess.Exec("DELETE FROM `watch` WHERE `user_id` IN (SELECT `id` FROM `user` WHERE `type` = ?)", UserTypeOrganization); err != nil {
  23. return err
  24. }
  25. if _, err := sess.Exec("UPDATE `repository` SET num_watches = (SELECT count(*) FROM watch WHERE `repository`.`id` = watch.repo_id)"); err != nil {
  26. return err
  27. }
  28. return sess.Commit()
  29. }