aboutsummaryrefslogtreecommitdiffstats
path: root/models/migrations
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-10-18 19:30:39 -0400
committerUnknwon <u@gogs.io>2015-10-18 19:30:39 -0400
commitfc7959d3bc89b172b3e0f2d0c5fcdcbb09e2408e (patch)
tree23a861a3bccec2d8311067008ebd0771bee82858 /models/migrations
parent4dc6285715ccd1e90cb4e437a3c2b1d0b13d47cb (diff)
downloadgitea-fc7959d3bc89b172b3e0f2d0c5fcdcbb09e2408e.tar.gz
gitea-fc7959d3bc89b172b3e0f2d0c5fcdcbb09e2408e.zip
New/reopen PR checks if there is any unmerged and open PR
Diffstat (limited to 'models/migrations')
-rw-r--r--models/migrations/migrations.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go
index 08a503e6da..c3f7a59be9 100644
--- a/models/migrations/migrations.go
+++ b/models/migrations/migrations.go
@@ -65,6 +65,7 @@ var migrations = []Migration{
NewMigration("trim action compare URL prefix", trimCommitActionAppUrlPrefix), // V5 -> V6:v0.6.3
NewMigration("generate issue-label from issue", issueToIssueLabel), // V6 -> V7:v0.6.4
NewMigration("refactor attachment table", attachmentRefactor), // V7 -> V8:v0.6.4
+ NewMigration("rename pull request fields", renamePullRequestFields), // V8 -> V9:v0.6.16
}
// Migrate database to current version
@@ -606,3 +607,49 @@ func attachmentRefactor(x *xorm.Engine) error {
return sess.Commit()
}
+
+func renamePullRequestFields(x *xorm.Engine) (err error) {
+ type PullRequest struct {
+ ID int64 `xorm:"pk autoincr"`
+ PullID int64 `xorm:"INDEX"`
+ PullIndex int64
+ HeadBarcnh string
+
+ IssueID int64 `xorm:"INDEX"`
+ Index int64
+ HeadBranch string
+ }
+
+ if err = x.Sync(new(PullRequest)); err != nil {
+ return fmt.Errorf("sync: %v", err)
+ }
+
+ results, err := x.Query("SELECT `id`,`pull_id`,`pull_index`,`head_barcnh` FROM `pull_request`")
+ if err != nil {
+ if strings.Contains(err.Error(), "no such column") {
+ return nil
+ }
+ return fmt.Errorf("select pull requests: %v", err)
+ }
+
+ sess := x.NewSession()
+ defer sessionRelease(sess)
+ if err = sess.Begin(); err != nil {
+ return err
+ }
+
+ var pull *PullRequest
+ for _, pr := range results {
+ pull = &PullRequest{
+ ID: com.StrTo(pr["id"]).MustInt64(),
+ IssueID: com.StrTo(pr["pull_id"]).MustInt64(),
+ Index: com.StrTo(pr["pull_index"]).MustInt64(),
+ HeadBranch: string(pr["head_barcnh"]),
+ }
+ if _, err = sess.Id(pull.ID).Update(pull); err != nil {
+ return err
+ }
+ }
+
+ return sess.Commit()
+}