diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2019-03-21 00:37:50 +0800 |
---|---|---|
committer | zeripath <art27@cantab.net> | 2019-03-20 16:37:50 +0000 |
commit | 3bb123e90e84ceb7e9762fd187b79f80e97e470f (patch) | |
tree | 59dfb7b0b2ff2b5c8256d29b5b779df2095d9a7a | |
parent | b78cbbcaa25d03d07b77a010a26568182682c6f1 (diff) | |
download | gitea-3bb123e90e84ceb7e9762fd187b79f80e97e470f.tar.gz gitea-3bb123e90e84ceb7e9762fd187b79f80e97e470f.zip |
fix migrations 82 to ignore unsynced tags between database and git data and missing is_archived on repository table (#6387)
-rw-r--r-- | models/migrations/v82.go | 46 |
1 files changed, 40 insertions, 6 deletions
diff --git a/models/migrations/v82.go b/models/migrations/v82.go index 6c62a8e24a..be9e71fd83 100644 --- a/models/migrations/v82.go +++ b/models/migrations/v82.go @@ -5,8 +5,11 @@ package migrations import ( + "fmt" + "code.gitea.io/git" "code.gitea.io/gitea/models" + "github.com/go-xorm/xorm" ) @@ -18,6 +21,17 @@ func fixReleaseSha1OnReleaseTable(x *xorm.Engine) error { TagName string } + type Repository struct { + ID int64 + OwnerID int64 + Name string + } + + type User struct { + ID int64 + Name string + } + // Update release sha1 const batchSize = 100 sess := x.NewSession() @@ -27,7 +41,8 @@ func fixReleaseSha1OnReleaseTable(x *xorm.Engine) error { err error count int gitRepoCache = make(map[int64]*git.Repository) - repoCache = make(map[int64]*models.Repository) + repoCache = make(map[int64]*Repository) + userCache = make(map[int64]*User) ) if err = sess.Begin(); err != nil { @@ -48,14 +63,31 @@ func fixReleaseSha1OnReleaseTable(x *xorm.Engine) error { if !ok { repo, ok := repoCache[release.RepoID] if !ok { - repo, err = models.GetRepositoryByID(release.RepoID) + repo = new(Repository) + has, err := sess.ID(release.RepoID).Get(repo) if err != nil { return err + } else if !has { + return fmt.Errorf("Repository %d is not exist", release.RepoID) } + repoCache[release.RepoID] = repo } - gitRepo, err = git.OpenRepository(repo.RepoPath()) + user, ok := userCache[repo.OwnerID] + if !ok { + user = new(User) + has, err := sess.ID(repo.OwnerID).Get(user) + if err != nil { + return err + } else if !has { + return fmt.Errorf("User %d is not exist", repo.OwnerID) + } + + userCache[repo.OwnerID] = user + } + + gitRepo, err = git.OpenRepository(models.RepoPath(user.Name, repo.Name)) if err != nil { return err } @@ -63,12 +95,14 @@ func fixReleaseSha1OnReleaseTable(x *xorm.Engine) error { } release.Sha1, err = gitRepo.GetTagCommitID(release.TagName) - if err != nil { + if err != nil && !git.IsErrNotExist(err) { return err } - if _, err = sess.ID(release.ID).Cols("sha1").Update(release); err != nil { - return err + if err == nil { + if _, err = sess.ID(release.ID).Cols("sha1").Update(release); err != nil { + return err + } } count++ |