gitea源码

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright 2024 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package v1_23
  4. import (
  5. "code.gitea.io/gitea/modules/timeutil"
  6. "xorm.io/xorm"
  7. "xorm.io/xorm/schemas"
  8. )
  9. type improveNotificationTableIndicesAction struct {
  10. ID int64 `xorm:"pk autoincr"`
  11. UserID int64 `xorm:"NOT NULL"`
  12. RepoID int64 `xorm:"NOT NULL"`
  13. Status uint8 `xorm:"SMALLINT NOT NULL"`
  14. Source uint8 `xorm:"SMALLINT NOT NULL"`
  15. IssueID int64 `xorm:"NOT NULL"`
  16. CommitID string
  17. CommentID int64
  18. UpdatedBy int64 `xorm:"NOT NULL"`
  19. CreatedUnix timeutil.TimeStamp `xorm:"created NOT NULL"`
  20. UpdatedUnix timeutil.TimeStamp `xorm:"updated NOT NULL"`
  21. }
  22. // TableName sets the name of this table
  23. func (*improveNotificationTableIndicesAction) TableName() string {
  24. return "notification"
  25. }
  26. // TableIndices implements xorm's TableIndices interface
  27. func (*improveNotificationTableIndicesAction) TableIndices() []*schemas.Index {
  28. indices := make([]*schemas.Index, 0, 8)
  29. usuuIndex := schemas.NewIndex("u_s_uu", schemas.IndexType)
  30. usuuIndex.AddColumn("user_id", "status", "updated_unix")
  31. indices = append(indices, usuuIndex)
  32. // Add the individual indices that were previously defined in struct tags
  33. userIDIndex := schemas.NewIndex("idx_notification_user_id", schemas.IndexType)
  34. userIDIndex.AddColumn("user_id")
  35. indices = append(indices, userIDIndex)
  36. repoIDIndex := schemas.NewIndex("idx_notification_repo_id", schemas.IndexType)
  37. repoIDIndex.AddColumn("repo_id")
  38. indices = append(indices, repoIDIndex)
  39. statusIndex := schemas.NewIndex("idx_notification_status", schemas.IndexType)
  40. statusIndex.AddColumn("status")
  41. indices = append(indices, statusIndex)
  42. sourceIndex := schemas.NewIndex("idx_notification_source", schemas.IndexType)
  43. sourceIndex.AddColumn("source")
  44. indices = append(indices, sourceIndex)
  45. issueIDIndex := schemas.NewIndex("idx_notification_issue_id", schemas.IndexType)
  46. issueIDIndex.AddColumn("issue_id")
  47. indices = append(indices, issueIDIndex)
  48. commitIDIndex := schemas.NewIndex("idx_notification_commit_id", schemas.IndexType)
  49. commitIDIndex.AddColumn("commit_id")
  50. indices = append(indices, commitIDIndex)
  51. updatedByIndex := schemas.NewIndex("idx_notification_updated_by", schemas.IndexType)
  52. updatedByIndex.AddColumn("updated_by")
  53. indices = append(indices, updatedByIndex)
  54. return indices
  55. }
  56. func ImproveNotificationTableIndices(x *xorm.Engine) error {
  57. return x.Sync(&improveNotificationTableIndicesAction{})
  58. }