From 05943ebce11e36af53b2e11772e06a6f83f31cb1 Mon Sep 17 00:00:00 2001 From: Florian Eitel Date: Thu, 15 Nov 2018 15:38:46 +0100 Subject: [PATCH 1/2] 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 --- models/migrations/v64.go | 1 - 1 file changed, 1 deletion(-) diff --git a/models/migrations/v64.go b/models/migrations/v64.go index 5958cd8f8259f..5bc7e36b516e7 100644 --- a/models/migrations/v64.go +++ b/models/migrations/v64.go @@ -26,7 +26,6 @@ func addMultipleAssignees(x *xorm.Engine) error { IsClosed bool `xorm:"INDEX"` IsPull bool `xorm:"INDEX"` // Indicates whether is a pull request or not. NumComments int - Ref string DeadlineUnix util.TimeStamp `xorm:"INDEX"` CreatedUnix util.TimeStamp `xorm:"INDEX created"` From 40e4146218bbe0be81246fb857ee8a6eb8f1ecb4 Mon Sep 17 00:00:00 2001 From: Florian Eitel Date: Thu, 15 Nov 2018 15:43:42 +0100 Subject: [PATCH 2/2] 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 --- models/migrations/v67.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/models/migrations/v67.go b/models/migrations/v67.go index 27822191911ef..d4a7497ec91b3 100644 --- a/models/migrations/v67.go +++ b/models/migrations/v67.go @@ -5,6 +5,8 @@ package migrations import ( + "fmt" + "code.gitea.io/gitea/modules/setting" "github.com/go-xorm/xorm" @@ -70,6 +72,13 @@ func removeStaleWatches(x *xorm.Engine) error { return err } + var issueWatch IssueWatch + if exist, err := sess.IsTableExist(&issueWatch); err != nil { + return fmt.Errorf("IsExist IssueWatch: %v", err) + } else if !exist { + return nil + } + repoCache := make(map[int64]*Repository) err := x.BufferSize(setting.IterateBufferSize).Iterate(new(Watch), func(idx int, bean interface{}) error {