Skip to content

Migration fixes for gogs (0.11.66) to gitea (1.6.0) #5318

Closed
@nougad

Description

@nougad
  • Gitea version (or commit ref): 4c1f1f9
  • Git version: 2.19.1
  • Operating system: archlinux
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant
  • Log gist:

Description

I was able (with minimal modifications) to upgrade from gogs (0.11.66) to gitea (1.6.0) in one step. I'm aware that the recommended approach is to do multiple intermediate steps with different gitea versions and one step migration is not supported. But it worked pretty nicely so I want to share my outcome. Maybe you can consider taking the two hunks for 1.6.0 to make it easier.

Steps taken

initial state: starting with gogs migration version v19 (0.11.66 - from arch linux aur) and latest gitea release 1.5.3 - from arch linux repo)

[I] Migration: add primary key to external login user

[...itea/routers/init.go:60 GlobalInit()] [E] Failed to initialize ORM engine: migrate: do migrate: Find: pq: relation "external_login_user" does not exist 

--> reset version in database: update version set version = 13;

[I] Migration: add primary key to external login user

[...itea/routers/init.go:60 GlobalInit()] [E] Failed to initialize ORM engine: migrate: do migrate: select repos [offset: 0]: pq: column "is_fsck_enabled" does not exist  

-> already fixed in #4495 -- I used the latest 1.6.0rc2 release from the github release page instead

[I] Migration: add multiple assignees

[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 

Migration v64 fails - added in da230a2 on 2017-08-24

Ref column in issues table was never added via a migration --> Remove it from migration v64 since it's not required:

diff --git a/models/migrations/v64.go b/models/migrations/v64.go
index 5958cd8f8..8af71db73 100644
--- a/models/migrations/v64.go
+++ b/models/migrations/v64.go
@@ -26,7 +26,7 @@ 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"`

[I] Migration: remove stale watches

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 

Table issue_watch does not exist in gogs and was never added in a migration. Making the migration optional and skipping it if the table does not exist helps:

diff --git a/models/migrations/v67.go b/models/migrations/v67.go
index 278221919..d4a7497ec 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 {

Final state: I can run (patched) gitea 1.6 on my staging system. I don't have real data but logging in and clicking around works just fine. I will do more testing on production system soon and will report here new finding

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/bugtype/docsThis PR mainly updates/creates documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions