mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	Rewrite migrations to not depend on future code changes (#2604)
* v38 migration used an outdated version of RepoUnit model (#2602) * change repoUnit model in migration * fix v16 migration repo_unit table * fix lint error * move type definition inside function Signed-off-by: David Schneiderbauer <dschneiderbauer@gmail.com> * fix lint error Signed-off-by: David Schneiderbauer <dschneiderbauer@gmail.com> * Fix time tracking migration * Refactor code * Fix migration from Gogs * v38 migration used an outdated version of RepoUnit model (#2602) * change repoUnit model in migration * fix v16 migration repo_unit table * fix lint error * move type definition inside function Signed-off-by: David Schneiderbauer <dschneiderbauer@gmail.com> * fix lint error Signed-off-by: David Schneiderbauer <dschneiderbauer@gmail.com> * Fix time tracking migration * Refactor code * Fix migration from Gogs * add error check Signed-off-by: David Schneiderbauer <dschneiderbauer@gmail.com> * Additiomal fixes for migrations * Fix timetracking migration * Add back nil check
This commit is contained in:
		
				
					committed by
					
						
						Lunny Xiao
					
				
			
			
				
	
			
			
			
						parent
						
							92123fe82a
						
					
				
				
					commit
					ebac051e72
				
			@@ -13,17 +13,6 @@ import (
 | 
			
		||||
	"github.com/go-xorm/xorm"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// RepoUnit describes all units of a repository
 | 
			
		||||
type RepoUnit struct {
 | 
			
		||||
	ID          int64
 | 
			
		||||
	RepoID      int64 `xorm:"INDEX(s)"`
 | 
			
		||||
	Type        int   `xorm:"INDEX(s)"`
 | 
			
		||||
	Index       int
 | 
			
		||||
	Config      map[string]interface{} `xorm:"JSON"`
 | 
			
		||||
	CreatedUnix int64                  `xorm:"INDEX CREATED"`
 | 
			
		||||
	Created     time.Time              `xorm:"-"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Enumerate all the unit types
 | 
			
		||||
const (
 | 
			
		||||
	V16UnitTypeCode            = iota + 1 // 1 code
 | 
			
		||||
@@ -37,14 +26,25 @@ const (
 | 
			
		||||
	V16UnitTypeExternalTracker            // 9 ExternalTracker
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// Repo describes a repository
 | 
			
		||||
type Repo struct {
 | 
			
		||||
	ID                                                                               int64
 | 
			
		||||
	EnableWiki, EnableExternalWiki, EnableIssues, EnableExternalTracker, EnablePulls bool
 | 
			
		||||
	ExternalWikiURL, ExternalTrackerURL, ExternalTrackerFormat, ExternalTrackerStyle string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func addUnitsToTables(x *xorm.Engine) error {
 | 
			
		||||
	// RepoUnit describes all units of a repository
 | 
			
		||||
	type RepoUnit struct {
 | 
			
		||||
		ID          int64
 | 
			
		||||
		RepoID      int64 `xorm:"INDEX(s)"`
 | 
			
		||||
		Type        int   `xorm:"INDEX(s)"`
 | 
			
		||||
		Index       int
 | 
			
		||||
		Config      map[string]interface{} `xorm:"JSON"`
 | 
			
		||||
		CreatedUnix int64                  `xorm:"INDEX CREATED"`
 | 
			
		||||
		Created     time.Time              `xorm:"-"`
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Repo describes a repository
 | 
			
		||||
	type Repo struct {
 | 
			
		||||
		ID                                                                               int64
 | 
			
		||||
		EnableWiki, EnableExternalWiki, EnableIssues, EnableExternalTracker, EnablePulls bool
 | 
			
		||||
		ExternalWikiURL, ExternalTrackerURL, ExternalTrackerFormat, ExternalTrackerStyle string
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var repos []Repo
 | 
			
		||||
	err := x.Table("repository").Select("*").Find(&repos)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user