From 4c9bf91a2c7fc55544a6e8ea522d7f2fd4db029d Mon Sep 17 00:00:00 2001
From: David Schneiderbauer <daviian@users.noreply.github.com>
Date: Mon, 25 Sep 2017 18:53:55 +0200
Subject: [PATCH] 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>
---
 models/migrations/v16.go | 36 ++++++++++++++++++------------------
 models/migrations/v38.go | 14 ++++++++++++++
 2 files changed, 32 insertions(+), 18 deletions(-)

diff --git a/models/migrations/v16.go b/models/migrations/v16.go
index a2d0d9e04..f14b196f2 100644
--- a/models/migrations/v16.go
+++ b/models/migrations/v16.go
@@ -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]string `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]string `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 {
diff --git a/models/migrations/v38.go b/models/migrations/v38.go
index 69c346335..216d49935 100644
--- a/models/migrations/v38.go
+++ b/models/migrations/v38.go
@@ -5,12 +5,26 @@
 package migrations
 
 import (
+	"time"
+
 	"code.gitea.io/gitea/models"
 
+	"github.com/go-xorm/core"
 	"github.com/go-xorm/xorm"
 )
 
 func removeCommitsUnitType(x *xorm.Engine) (err 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      core.Conversion `xorm:"TEXT"`
+		CreatedUnix int64           `xorm:"INDEX CREATED"`
+		Created     time.Time       `xorm:"-"`
+	}
+
 	// Update team unit types
 	const batchSize = 100
 	for start := 0; ; start += batchSize {