mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 21:28:11 +09:00 
			
		
		
		
	Mulitple Gitea Doctor improvements (#10943)
* Add `gitea doctor --list` flag to list the checks that will be run, including those by default * Add `gitea doctor --run` to run specific checks * Add `gitea doctor --all` to run all checks * Add db version checker * Add non-default recalculate merge bases check/fixer to doctor * Add hook checker (Fix #9878) and ensure hooks are executable (Fix #6319) * Fix authorized_keys checker - slight change of functionality here because parsing the command is fragile and we should just check if the authorized_keys file is essentially the same as what gitea would produce. (This is still not perfect as order matters - we should probably just md5sum the two files.) * Add SCRIPT_TYPE check (Fix #10977) * Add `gitea doctor --fix` to attempt to fix what is possible to easily fix * Add `gitea doctor --log-file` to set the log-file, be it a file, stdout or to switch off completely. (Fixes previously undetected bug with certain xorm logging configurations - see @6543 comment.) Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
		| @@ -206,6 +206,52 @@ var migrations = []Migration{ | ||||
| 	NewMigration("Add OrgID column to Labels table", addOrgIDLabelColumn), | ||||
| } | ||||
|  | ||||
| // GetCurrentDBVersion returns the current db version | ||||
| func GetCurrentDBVersion(x *xorm.Engine) (int64, error) { | ||||
| 	if err := x.Sync(new(Version)); err != nil { | ||||
| 		return -1, fmt.Errorf("sync: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	currentVersion := &Version{ID: 1} | ||||
| 	has, err := x.Get(currentVersion) | ||||
| 	if err != nil { | ||||
| 		return -1, fmt.Errorf("get: %v", err) | ||||
| 	} | ||||
| 	if !has { | ||||
| 		return -1, nil | ||||
| 	} | ||||
| 	return currentVersion.Version, nil | ||||
| } | ||||
|  | ||||
| // ExpectedVersion returns the expected db version | ||||
| func ExpectedVersion() int64 { | ||||
| 	return int64(minDBVersion + len(migrations)) | ||||
| } | ||||
|  | ||||
| // EnsureUpToDate will check if the db is at the correct version | ||||
| func EnsureUpToDate(x *xorm.Engine) error { | ||||
| 	currentDB, err := GetCurrentDBVersion(x) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	if currentDB < 0 { | ||||
| 		return fmt.Errorf("Database has not been initialised") | ||||
| 	} | ||||
|  | ||||
| 	if minDBVersion > currentDB { | ||||
| 		return fmt.Errorf("DB version %d (<= %d) is too old for auto-migration. Upgrade to Gitea 1.6.4 first then upgrade to this version", currentDB, minDBVersion) | ||||
| 	} | ||||
|  | ||||
| 	expected := ExpectedVersion() | ||||
|  | ||||
| 	if currentDB != expected { | ||||
| 		return fmt.Errorf(`Current database version %d is not equal to the expected version %d. Please run "gitea [--config /path/to/app.ini] migrate" to update the database version`, currentDB, expected) | ||||
| 	} | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // Migrate database to current version | ||||
| func Migrate(x *xorm.Engine) error { | ||||
| 	if err := x.Sync(new(Version)); err != nil { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user