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.

33 lines
848 B

  1. // Copyright 2018 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/builder"
  7. "xorm.io/xorm"
  8. )
  9. func clearNonusedData(x *xorm.Engine) error {
  10. condDelete := func(colName string) builder.Cond {
  11. return builder.NotIn(colName, builder.Select("id").From("`user`"))
  12. }
  13. if _, err := x.Exec(builder.Delete(condDelete("uid")).From("team_user")); err != nil {
  14. return err
  15. }
  16. if _, err := x.Exec(builder.Delete(condDelete("user_id")).From("collaboration")); err != nil {
  17. return err
  18. }
  19. if _, err := x.Exec(builder.Delete(condDelete("user_id")).From("stopwatch")); err != nil {
  20. return err
  21. }
  22. if _, err := x.Exec(builder.Delete(condDelete("owner_id")).From("gpg_key")); err != nil {
  23. return err
  24. }
  25. return nil
  26. }