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.

100 lines
2.7 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. "github.com/go-xorm/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. if err = x.Sync(new(IssueDependency)); err != nil {
  23. return fmt.Errorf("Error creating issue_dependency_table column definition: %v", err)
  24. }
  25. // Update Comment definition
  26. // This (copied) struct does only contain fields used by xorm as the only use here is to update the database
  27. // CommentType defines the comment type
  28. type CommentType int
  29. // TimeStamp defines a timestamp
  30. type TimeStamp int64
  31. type Comment struct {
  32. ID int64 `xorm:"pk autoincr"`
  33. Type CommentType
  34. PosterID int64 `xorm:"INDEX"`
  35. IssueID int64 `xorm:"INDEX"`
  36. LabelID int64
  37. OldMilestoneID int64
  38. MilestoneID int64
  39. OldAssigneeID int64
  40. AssigneeID int64
  41. OldTitle string
  42. NewTitle string
  43. DependentIssueID int64
  44. CommitID int64
  45. Line int64
  46. Content string `xorm:"TEXT"`
  47. CreatedUnix TimeStamp `xorm:"INDEX created"`
  48. UpdatedUnix TimeStamp `xorm:"INDEX updated"`
  49. // Reference issue in commit message
  50. CommitSHA string `xorm:"VARCHAR(40)"`
  51. }
  52. if err = x.Sync(new(Comment)); err != nil {
  53. return fmt.Errorf("Error updating issue_comment table column definition: %v", err)
  54. }
  55. // RepoUnit describes all units of a repository
  56. type RepoUnit struct {
  57. ID int64
  58. RepoID int64 `xorm:"INDEX(s)"`
  59. Type int `xorm:"INDEX(s)"`
  60. Config map[string]interface{} `xorm:"JSON"`
  61. CreatedUnix int64 `xorm:"INDEX CREATED"`
  62. Created time.Time `xorm:"-"`
  63. }
  64. //Updating existing issue units
  65. units := make([]*RepoUnit, 0, 100)
  66. err = x.Where("`type` = ?", V16UnitTypeIssues).Find(&units)
  67. if err != nil {
  68. return fmt.Errorf("Query repo units: %v", err)
  69. }
  70. for _, unit := range units {
  71. if unit.Config == nil {
  72. unit.Config = make(map[string]interface{})
  73. }
  74. if _, ok := unit.Config["EnableDependencies"]; !ok {
  75. unit.Config["EnableDependencies"] = setting.Service.DefaultEnableDependencies
  76. }
  77. if _, err := x.ID(unit.ID).Cols("config").Update(unit); err != nil {
  78. return err
  79. }
  80. }
  81. return err
  82. }