Skip to content

Commit

Permalink
Fix upgrade failed after ever rollback (#1194)
Browse files Browse the repository at this point in the history
* fix upgrade failed after rollback

* fix upgrade failed after rollback

* fix possible upgrade twice fail after rollback
  • Loading branch information
lunny authored Mar 10, 2017
1 parent f5476bd commit 74cde12
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
6 changes: 6 additions & 0 deletions models/migrations/v16.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ func addUnitsToTables(x *xorm.Engine) error {
}

var repoUnit RepoUnit
if exist, err := sess.IsTableExist(&repoUnit); err != nil {
return fmt.Errorf("IsExist RepoUnit: %v", err)
} else if exist {
return nil
}

if err := sess.CreateTable(&repoUnit); err != nil {
return fmt.Errorf("CreateTable RepoUnit: %v", err)
}
Expand Down
10 changes: 8 additions & 2 deletions models/migrations/v19.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,14 @@ func generateAndMigrateGitHooks(x *xorm.Engine) (err error) {
oldHookPath := filepath.Join(hookDir, hookName)
newHookPath := filepath.Join(hookDir, hookName+".d", "gitea")

if err = os.MkdirAll(filepath.Join(hookDir, hookName+".d"), os.ModePerm); err != nil {
return fmt.Errorf("create hooks dir '%s': %v", filepath.Join(hookDir, hookName+".d"), err)
customHooksDir := filepath.Join(hookDir, hookName+".d")
// if it's exist, that means you have upgraded ever
if com.IsExist(customHooksDir) {
continue
}

if err = os.MkdirAll(customHooksDir, os.ModePerm); err != nil {
return fmt.Errorf("create hooks dir '%s': %v", customHooksDir, err)
}

// WARNING: Old server-side hooks will be moved to sub directory with the same name
Expand Down
4 changes: 3 additions & 1 deletion models/migrations/v20.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"path/filepath"
"strconv"

"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"

"github.com/go-xorm/xorm"
Expand Down Expand Up @@ -40,7 +41,8 @@ func useNewNameAvatars(x *xorm.Engine) error {
for _, name := range names {
userID, err := strconv.ParseInt(name, 10, 64)
if err != nil {
return err
log.Warn("ignore avatar %s rename: %v", name, err)
continue
}

var user User
Expand Down

0 comments on commit 74cde12

Please sign in to comment.