Skip to content

Commit d9b51a7

Browse files
nougadlafriks
authored andcommitted
Migration fixes for gogs (0.11.66) to gitea (1.6.0) #5318 (#5341)
* Remove field from migration to support upgrades from older version That will ensure the field does not get queried in the Select if it does not exist yet: ``` [I] [SQL] SELECT "id", "repo_id", "index", "poster_id", "name", "content", "milestone_id", "priority", "assignee_id", "is_closed", "is_pull", "num_comments", "ref", "deadline_unix", "created_unix", "updated_unix [...itea/routers/init.go:60 GlobalInit()] [E] Failed to initialize ORM engine: migrate: do migrate: pq: column "ref" does not exist ``` see #5318 * Skip remove stale watcher migration if not required Otherwise the migration will fail if executed from a older database version without multiple IssueWatch feature. ``` 2018/11/11 23:51:14 [I] [SQL] SELECT DISTINCT "issue_watch"."user_id", "issue"."repo_id" FROM "issue_watch" INNER JOIN issue ON issue_watch.issue_id = issue.id WHERE (issue_watch.is_watching = $1) LIMIT 50 []int [...itea/routers/init.go:60 GlobalInit()] [E] Failed to initialize ORM engine: migrate: do migrate: pq: relation "issue_watch" does not exist ``` see #5318
1 parent 241ee79 commit d9b51a7

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

models/migrations/v64.go

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ func addMultipleAssignees(x *xorm.Engine) error {
2626
IsClosed bool `xorm:"INDEX"`
2727
IsPull bool `xorm:"INDEX"` // Indicates whether is a pull request or not.
2828
NumComments int
29-
Ref string
3029

3130
DeadlineUnix util.TimeStamp `xorm:"INDEX"`
3231
CreatedUnix util.TimeStamp `xorm:"INDEX created"`

models/migrations/v67.go

+9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
package migrations
66

77
import (
8+
"fmt"
9+
810
"code.gitea.io/gitea/modules/setting"
911

1012
"github.com/go-xorm/xorm"
@@ -70,6 +72,13 @@ func removeStaleWatches(x *xorm.Engine) error {
7072
return err
7173
}
7274

75+
var issueWatch IssueWatch
76+
if exist, err := sess.IsTableExist(&issueWatch); err != nil {
77+
return fmt.Errorf("IsExist IssueWatch: %v", err)
78+
} else if !exist {
79+
return nil
80+
}
81+
7382
repoCache := make(map[int64]*Repository)
7483
err := x.BufferSize(setting.IterateBufferSize).Iterate(new(Watch),
7584
func(idx int, bean interface{}) error {

0 commit comments

Comments
 (0)