gitea源码

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright 2022 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package v1_17
  4. import (
  5. "code.gitea.io/gitea/modules/setting"
  6. "code.gitea.io/gitea/modules/timeutil"
  7. "xorm.io/xorm"
  8. "xorm.io/xorm/schemas"
  9. )
  10. type improveActionTableIndicesAction struct {
  11. ID int64 `xorm:"pk autoincr"`
  12. UserID int64 // Receiver user id.
  13. OpType int
  14. ActUserID int64 // Action user id.
  15. RepoID int64
  16. CommentID int64 `xorm:"INDEX"`
  17. IsDeleted bool `xorm:"NOT NULL DEFAULT false"`
  18. RefName string
  19. IsPrivate bool `xorm:"NOT NULL DEFAULT false"`
  20. Content string `xorm:"TEXT"`
  21. CreatedUnix timeutil.TimeStamp `xorm:"created"`
  22. }
  23. // TableName sets the name of this table
  24. func (*improveActionTableIndicesAction) TableName() string {
  25. return "action"
  26. }
  27. // TableIndices implements xorm's TableIndices interface
  28. func (*improveActionTableIndicesAction) TableIndices() []*schemas.Index {
  29. repoIndex := schemas.NewIndex("r_u_d", schemas.IndexType)
  30. repoIndex.AddColumn("repo_id", "user_id", "is_deleted")
  31. actUserIndex := schemas.NewIndex("au_r_c_u_d", schemas.IndexType)
  32. actUserIndex.AddColumn("act_user_id", "repo_id", "created_unix", "user_id", "is_deleted")
  33. indices := []*schemas.Index{actUserIndex, repoIndex}
  34. if setting.Database.Type.IsPostgreSQL() {
  35. cudIndex := schemas.NewIndex("c_u_d", schemas.IndexType)
  36. cudIndex.AddColumn("created_unix", "user_id", "is_deleted")
  37. indices = append(indices, cudIndex)
  38. }
  39. return indices
  40. }
  41. func ImproveActionTableIndices(x *xorm.Engine) error {
  42. return x.Sync(&improveActionTableIndicesAction{})
  43. }