Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
2 of 7 tasks
nougad opened this issue Nov 11, 2018 · 5 comments
Closed
2 of 7 tasks

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

nougad opened this issue Nov 11, 2018 · 5 comments
Labels
type/bug type/docs This PR mainly updates/creates documentation

Comments

@nougad
Copy link
Contributor

nougad commented Nov 11, 2018

  • 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

@lunny lunny added the type/docs This PR mainly updates/creates documentation label Nov 12, 2018
@lafriks lafriks added the type/enhancement An improvement of existing functionality label Nov 12, 2018
@lafriks
Copy link
Member

lafriks commented Nov 12, 2018

We could probably fix migrations so that it would work out of box

@nougad
Copy link
Contributor Author

nougad commented Nov 13, 2018

Awesome. Good to hear you can integrate the patches. Do I require to open a pull request or can you just take the two small patches into 1.6.0?

@lafriks
Copy link
Member

lafriks commented Nov 13, 2018

Yes please submit PR to master branch first

@lafriks lafriks added type/bug and removed type/enhancement An improvement of existing functionality labels Nov 13, 2018
nougad added a commit to nougad/gitea that referenced this issue Nov 15, 2018
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 go-gitea#5318
nougad added a commit to nougad/gitea that referenced this issue Nov 15, 2018
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
lafriks pushed a commit that referenced this issue Nov 18, 2018
* 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
nougad added a commit to nougad/gitea that referenced this issue Nov 18, 2018
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 go-gitea#5318
nougad added a commit to nougad/gitea that referenced this issue Nov 18, 2018
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
lafriks pushed a commit that referenced this issue Nov 18, 2018
* 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
@nougad
Copy link
Contributor Author

nougad commented Nov 18, 2018

change merged to master and backported to 1.6 branch. thx for your work.

resolving

@bygreencn
Copy link

bygreencn commented Jun 18, 2020

change merged to master and backported to 1.6 branch. thx for your work.

resolving

@nougad Then which released 1.6 binary package include this patch? I used 1.6.4, it still have this error result.

@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type/bug type/docs This PR mainly updates/creates documentation
Projects
None yet
Development

No branches or pull requests

4 participants