You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

v46.go 989B

123456789101112131415161718192021222324252627282930313233343536
  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. "xorm.io/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. }