mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 12:37:14 -04:00 
			
		
		
		
	* Changed migration calling so that migrations can use models package
This commit is contained in:
		| @@ -120,6 +120,8 @@ var migrations = []Migration{ | ||||
| 	NewMigration("give all units to owner teams", giveAllUnitsToOwnerTeams), | ||||
| 	// v35 -> v36 | ||||
| 	NewMigration("adds comment to an action", addCommentIDToAction), | ||||
| 	// v36 -> v37 | ||||
| 	NewMigration("regenerate git hooks", regenerateGitHooks36), | ||||
| } | ||||
|  | ||||
| // Migrate database to current version | ||||
|   | ||||
							
								
								
									
										15
									
								
								models/migrations/v36.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								models/migrations/v36.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,15 @@ | ||||
| // Copyright 2017 The Gitea Authors. All rights reserved. | ||||
| // Use of this source code is governed by a MIT-style | ||||
| // license that can be found in the LICENSE file. | ||||
|  | ||||
| package migrations | ||||
|  | ||||
| import ( | ||||
| 	"code.gitea.io/gitea/models" | ||||
|  | ||||
| 	"github.com/go-xorm/xorm" | ||||
| ) | ||||
|  | ||||
| func regenerateGitHooks36(x *xorm.Engine) (err error) { | ||||
| 	return models.SyncRepositoryHooks() | ||||
| } | ||||
| @@ -24,7 +24,6 @@ import ( | ||||
| 	// Needed for the MSSSQL driver | ||||
| 	_ "github.com/denisenkom/go-mssqldb" | ||||
|  | ||||
| 	"code.gitea.io/gitea/models/migrations" | ||||
| 	"code.gitea.io/gitea/modules/log" | ||||
| 	"code.gitea.io/gitea/modules/setting" | ||||
| ) | ||||
| @@ -259,7 +258,7 @@ func SetEngine() (err error) { | ||||
| } | ||||
|  | ||||
| // NewEngine initializes a new xorm.Engine | ||||
| func NewEngine() (err error) { | ||||
| func NewEngine(migrateFunc func(*xorm.Engine) error) (err error) { | ||||
| 	if err = SetEngine(); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| @@ -268,7 +267,7 @@ func NewEngine() (err error) { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	if err = migrations.Migrate(x); err != nil { | ||||
| 	if err = migrateFunc(x); err != nil { | ||||
| 		return fmt.Errorf("migrate: %v", err) | ||||
| 	} | ||||
|  | ||||
|   | ||||
| @@ -948,8 +948,12 @@ func cleanUpMigrateGitConfig(configPath string) error { | ||||
| // createDelegateHooks creates all the hooks scripts for the repo | ||||
| func createDelegateHooks(repoPath string) (err error) { | ||||
| 	var ( | ||||
| 		hookNames     = []string{"pre-receive", "update", "post-receive"} | ||||
| 		hookTpl       = fmt.Sprintf("#!/usr/bin/env %s\ndata=$(cat)\nexitcodes=\"\"\nhookname=$(basename $0)\nGIT_DIR=${GIT_DIR:-$(dirname $0)}\n\nfor hook in ${GIT_DIR}/hooks/${hookname}.d/*; do\ntest -x \"${hook}\" || continue\necho \"${data}\" | \"${hook}\"\nexitcodes=\"${exitcodes} $?\"\ndone\n\nfor i in ${exitcodes}; do\n[ ${i} -eq 0 ] || exit ${i}\ndone\n", setting.ScriptType) | ||||
| 		hookNames = []string{"pre-receive", "update", "post-receive"} | ||||
| 		hookTpls  = []string{ | ||||
| 			fmt.Sprintf("#!/usr/bin/env %s\ndata=$(cat)\nexitcodes=\"\"\nhookname=$(basename $0)\nGIT_DIR=${GIT_DIR:-$(dirname $0)}\n\nfor hook in ${GIT_DIR}/hooks/${hookname}.d/*; do\ntest -x \"${hook}\" || continue\necho \"${data}\" | \"${hook}\"\nexitcodes=\"${exitcodes} $?\"\ndone\n\nfor i in ${exitcodes}; do\n[ ${i} -eq 0 ] || exit ${i}\ndone\n", setting.ScriptType), | ||||
| 			fmt.Sprintf("#!/usr/bin/env %s\nexitcodes=\"\"\nhookname=$(basename $0)\nGIT_DIR=${GIT_DIR:-$(dirname $0)}\n\nfor hook in ${GIT_DIR}/hooks/${hookname}.d/*; do\ntest -x \"${hook}\" || continue\n\"${hook}\" $1 $2 $3\nexitcodes=\"${exitcodes} $?\"\ndone\n\nfor i in ${exitcodes}; do\n[ ${i} -eq 0 ] || exit ${i}\ndone\n", setting.ScriptType), | ||||
| 			fmt.Sprintf("#!/usr/bin/env %s\ndata=$(cat)\nexitcodes=\"\"\nhookname=$(basename $0)\nGIT_DIR=${GIT_DIR:-$(dirname $0)}\n\nfor hook in ${GIT_DIR}/hooks/${hookname}.d/*; do\ntest -x \"${hook}\" || continue\necho \"${data}\" | \"${hook}\"\nexitcodes=\"${exitcodes} $?\"\ndone\n\nfor i in ${exitcodes}; do\n[ ${i} -eq 0 ] || exit ${i}\ndone\n", setting.ScriptType), | ||||
| 		} | ||||
| 		giteaHookTpls = []string{ | ||||
| 			fmt.Sprintf("#!/usr/bin/env %s\n\"%s\" hook --config='%s' pre-receive\n", setting.ScriptType, setting.AppPath, setting.CustomConf), | ||||
| 			fmt.Sprintf("#!/usr/bin/env %s\n\"%s\" hook --config='%s' update $1 $2 $3\n", setting.ScriptType, setting.AppPath, setting.CustomConf), | ||||
| @@ -968,7 +972,7 @@ func createDelegateHooks(repoPath string) (err error) { | ||||
| 		} | ||||
|  | ||||
| 		// WARNING: This will override all old server-side hooks | ||||
| 		if err = ioutil.WriteFile(oldHookPath, []byte(hookTpl), 0777); err != nil { | ||||
| 		if err = ioutil.WriteFile(oldHookPath, []byte(hookTpls[i]), 0777); err != nil { | ||||
| 			return fmt.Errorf("write old hook file '%s': %v", oldHookPath, err) | ||||
| 		} | ||||
|  | ||||
|   | ||||
| @@ -10,6 +10,7 @@ import ( | ||||
|  | ||||
| 	"code.gitea.io/git" | ||||
| 	"code.gitea.io/gitea/models" | ||||
| 	"code.gitea.io/gitea/models/migrations" | ||||
| 	"code.gitea.io/gitea/modules/cron" | ||||
| 	"code.gitea.io/gitea/modules/highlight" | ||||
| 	"code.gitea.io/gitea/modules/indexer" | ||||
| @@ -50,7 +51,7 @@ func GlobalInit() { | ||||
| 	if setting.InstallLock { | ||||
| 		highlight.NewContext() | ||||
| 		markdown.NewSanitizer() | ||||
| 		if err := models.NewEngine(); err != nil { | ||||
| 		if err := models.NewEngine(migrations.Migrate); err != nil { | ||||
| 			log.Fatal(4, "Failed to initialize ORM engine: %v", err) | ||||
| 		} | ||||
| 		models.HasEngine = true | ||||
|   | ||||
		Reference in New Issue
	
	Block a user