Browse Source

Fix upgrade failed after ever rollback (#1194)

* fix upgrade failed after rollback

* fix upgrade failed after rollback

* fix possible upgrade twice fail after rollback
Lunny Xiao 3 years ago
parent
commit
74cde12677
3 changed files with 17 additions and 3 deletions
  1. 6 0
      models/migrations/v16.go
  2. 8 2
      models/migrations/v19.go
  3. 3 1
      models/migrations/v20.go

+ 6 - 0
models/migrations/v16.go

@@ -59,6 +59,12 @@ func addUnitsToTables(x *xorm.Engine) error {
59 59
 	}
60 60
 
61 61
 	var repoUnit RepoUnit
62
+	if exist, err := sess.IsTableExist(&repoUnit); err != nil {
63
+		return fmt.Errorf("IsExist RepoUnit: %v", err)
64
+	} else if exist {
65
+		return nil
66
+	}
67
+
62 68
 	if err := sess.CreateTable(&repoUnit); err != nil {
63 69
 		return fmt.Errorf("CreateTable RepoUnit: %v", err)
64 70
 	}

+ 8 - 2
models/migrations/v19.go

@@ -60,8 +60,14 @@ func generateAndMigrateGitHooks(x *xorm.Engine) (err error) {
60 60
 				oldHookPath := filepath.Join(hookDir, hookName)
61 61
 				newHookPath := filepath.Join(hookDir, hookName+".d", "gitea")
62 62
 
63
-				if err = os.MkdirAll(filepath.Join(hookDir, hookName+".d"), os.ModePerm); err != nil {
64
-					return fmt.Errorf("create hooks dir '%s': %v", filepath.Join(hookDir, hookName+".d"), err)
63
+				customHooksDir := filepath.Join(hookDir, hookName+".d")
64
+				// if it's exist, that means you have upgraded ever
65
+				if com.IsExist(customHooksDir) {
66
+					continue
67
+				}
68
+
69
+				if err = os.MkdirAll(customHooksDir, os.ModePerm); err != nil {
70
+					return fmt.Errorf("create hooks dir '%s': %v", customHooksDir, err)
65 71
 				}
66 72
 
67 73
 				// WARNING: Old server-side hooks will be moved to sub directory with the same name

+ 3 - 1
models/migrations/v20.go

@@ -13,6 +13,7 @@ import (
13 13
 	"path/filepath"
14 14
 	"strconv"
15 15
 
16
+	"code.gitea.io/gitea/modules/log"
16 17
 	"code.gitea.io/gitea/modules/setting"
17 18
 
18 19
 	"github.com/go-xorm/xorm"
@@ -40,7 +41,8 @@ func useNewNameAvatars(x *xorm.Engine) error {
40 41
 	for _, name := range names {
41 42
 		userID, err := strconv.ParseInt(name, 10, 64)
42 43
 		if err != nil {
43
-			return err
44
+			log.Warn("ignore avatar %s rename: %v", name, err)
45
+			continue
44 46
 		}
45 47
 
46 48
 		var user User