diff options
author | Lauris BH <lauris@nix.lv> | 2018-05-10 04:18:01 +0300 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2018-05-10 09:18:01 +0800 |
commit | 382e7276b82d747f5282357ff62fef01d3b48f6a (patch) | |
tree | 030d63fff65921d6409d4c0418a3e88d0d5dd272 /models | |
parent | 95f2e2b57beedcdeb2b9623dc86e26f252fdd7bd (diff) | |
download | gitea-382e7276b82d747f5282357ff62fef01d3b48f6a.tar.gz gitea-382e7276b82d747f5282357ff62fef01d3b48f6a.zip |
Fix multiple asssingee table migration (#3931)
Diffstat (limited to 'models')
-rw-r--r-- | models/migrations/v64.go | 76 |
1 files changed, 39 insertions, 37 deletions
diff --git a/models/migrations/v64.go b/models/migrations/v64.go index a281ac67e4..67ce3a9196 100644 --- a/models/migrations/v64.go +++ b/models/migrations/v64.go @@ -34,42 +34,6 @@ func addMultipleAssignees(x *xorm.Engine) error { ClosedUnix util.TimeStamp `xorm:"INDEX"` } - allIssues := []Issue{} - err := x.Find(&allIssues) - if err != nil { - return err - } - - // Create the table - type IssueAssignees struct { - ID int64 `xorm:"pk autoincr"` - AssigneeID int64 `xorm:"INDEX"` - IssueID int64 `xorm:"INDEX"` - } - err = x.Sync2(IssueAssignees{}) - if err != nil { - return err - } - - // Range over all issues and insert a new entry for each issue/assignee - sess := x.NewSession() - defer sess.Close() - - err = sess.Begin() - if err != nil { - return err - } - - for _, issue := range allIssues { - if issue.AssigneeID != 0 { - _, err := sess.Insert(IssueAssignees{IssueID: issue.ID, AssigneeID: issue.AssigneeID}) - if err != nil { - sess.Rollback() - return err - } - } - } - // Updated the comment table type Comment struct { ID int64 `xorm:"pk autoincr"` @@ -96,10 +60,45 @@ func addMultipleAssignees(x *xorm.Engine) error { // Reference issue in commit message CommitSHA string `xorm:"VARCHAR(40)"` } + + // Create the table + type IssueAssignees struct { + ID int64 `xorm:"pk autoincr"` + AssigneeID int64 `xorm:"INDEX"` + IssueID int64 `xorm:"INDEX"` + } + + if err := x.Sync2(IssueAssignees{}); err != nil { + return err + } + if err := x.Sync2(Comment{}); err != nil { return err } + // Range over all issues and insert a new entry for each issue/assignee + sess := x.NewSession() + defer sess.Close() + + if err := sess.Begin(); err != nil { + return err + } + + allIssues := []Issue{} + if err := sess.Find(&allIssues); err != nil { + return err + } + + for _, issue := range allIssues { + if issue.AssigneeID != 0 { + _, err := sess.Insert(IssueAssignees{IssueID: issue.ID, AssigneeID: issue.AssigneeID}) + if err != nil { + sess.Rollback() + return err + } + } + } + // Migrate comments // First update everything to not have nulls in db if _, err := sess.Where("type = ?", 9).Cols("removed_assignee").Update(Comment{RemovedAssignee: false}); err != nil { @@ -114,7 +113,10 @@ func addMultipleAssignees(x *xorm.Engine) error { for _, comment := range allAssignementComments { // Everytime where OldAssigneeID is > 0, the assignement was removed. if comment.OldAssigneeID > 0 { - _, err = sess.ID(comment.ID).Update(Comment{RemovedAssignee: true}) + _, err := sess.ID(comment.ID).Update(Comment{RemovedAssignee: true}) + if err != nil { + return err + } } } |