Skip to content

Commit 40e4146

Browse files
committed
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 go-gitea#5318
1 parent 05943eb commit 40e4146

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

models/migrations/v67.go

Lines changed: 9 additions & 0 deletions
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)