gitea源码

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // Copyright 2018 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package v1_6
  4. import (
  5. "fmt"
  6. "time"
  7. "code.gitea.io/gitea/modules/setting"
  8. "xorm.io/xorm"
  9. )
  10. func AddIssueDependencies(x *xorm.Engine) (err error) {
  11. type IssueDependency struct {
  12. ID int64 `xorm:"pk autoincr"`
  13. UserID int64 `xorm:"NOT NULL"`
  14. IssueID int64 `xorm:"NOT NULL"`
  15. DependencyID int64 `xorm:"NOT NULL"`
  16. Created time.Time `xorm:"-"`
  17. CreatedUnix int64 `xorm:"created"`
  18. Updated time.Time `xorm:"-"`
  19. UpdatedUnix int64 `xorm:"updated"`
  20. }
  21. const (
  22. v16UnitTypeCode = iota + 1 // 1 code
  23. v16UnitTypeIssues // 2 issues
  24. v16UnitTypePRs // 3 PRs
  25. v16UnitTypeCommits // 4 Commits
  26. v16UnitTypeReleases // 5 Releases
  27. v16UnitTypeWiki // 6 Wiki
  28. v16UnitTypeSettings // 7 Settings
  29. v16UnitTypeExternalWiki // 8 ExternalWiki
  30. v16UnitTypeExternalTracker // 9 ExternalTracker
  31. )
  32. if err = x.Sync(new(IssueDependency)); err != nil {
  33. return fmt.Errorf("Error creating issue_dependency_table column definition: %w", err)
  34. }
  35. // Update Comment definition
  36. // This (copied) struct does only contain fields used by xorm as the only use here is to update the database
  37. // CommentType defines the comment type
  38. type CommentType int
  39. // TimeStamp defines a timestamp
  40. type TimeStamp int64
  41. type Comment struct {
  42. ID int64 `xorm:"pk autoincr"`
  43. Type CommentType
  44. PosterID int64 `xorm:"INDEX"`
  45. IssueID int64 `xorm:"INDEX"`
  46. LabelID int64
  47. OldMilestoneID int64
  48. MilestoneID int64
  49. OldAssigneeID int64
  50. AssigneeID int64
  51. OldTitle string
  52. NewTitle string
  53. DependentIssueID int64
  54. CommitID int64
  55. Line int64
  56. Content string `xorm:"TEXT"`
  57. CreatedUnix TimeStamp `xorm:"INDEX created"`
  58. UpdatedUnix TimeStamp `xorm:"INDEX updated"`
  59. // Reference issue in commit message
  60. CommitSHA string `xorm:"VARCHAR(40)"`
  61. }
  62. if err = x.Sync(new(Comment)); err != nil {
  63. return fmt.Errorf("Error updating issue_comment table column definition: %w", err)
  64. }
  65. // RepoUnit describes all units of a repository
  66. type RepoUnit struct {
  67. ID int64
  68. RepoID int64 `xorm:"INDEX(s)"`
  69. Type int `xorm:"INDEX(s)"`
  70. Config map[string]any `xorm:"JSON"`
  71. CreatedUnix int64 `xorm:"INDEX CREATED"`
  72. Created time.Time `xorm:"-"`
  73. }
  74. // Updating existing issue units
  75. units := make([]*RepoUnit, 0, 100)
  76. err = x.Where("`type` = ?", v16UnitTypeIssues).Find(&units)
  77. if err != nil {
  78. return fmt.Errorf("Query repo units: %w", err)
  79. }
  80. for _, unit := range units {
  81. if unit.Config == nil {
  82. unit.Config = make(map[string]any)
  83. }
  84. if _, ok := unit.Config["EnableDependencies"]; !ok {
  85. unit.Config["EnableDependencies"] = setting.Service.DefaultEnableDependencies
  86. }
  87. if _, err := x.ID(unit.ID).Cols("config").Update(unit); err != nil {
  88. return err
  89. }
  90. }
  91. return err
  92. }