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.

112 lines
3.2 KiB

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