aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Schneiderbauer2017-10-09 15:08:22 +0200
committerLauris BH2017-10-09 16:08:22 +0300
commit74399f333fcb85113ea8490f59880d4d5f7e22ba (patch)
treebd6ea1f38d851daa5610b75e0bd6a9c94b33e5c6
parentd1cec5ecfa55d6a55fff28a9d95e2b7047fe9644 (diff)
Backport of migration fixes (#2604) (#2677)
* 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 * Fix migration from Gogs * Refactor code * add error check * Additiomal fixes for migrations * Add back nil check * replace deprecated .Id with .ID Signed-off-by: David Schneiderbauer <dschneiderbauer@gmail.com> * change string map to interface map Signed-off-by: David Schneiderbauer <dschneiderbauer@gmail.com>
-rw-r--r--models/migrations/v15.go20
-rw-r--r--models/migrations/v16.go8
-rw-r--r--models/migrations/v37.go13
-rw-r--r--models/migrations/v38.go2
4 files changed, 20 insertions, 23 deletions
diff --git a/models/migrations/v15.go b/models/migrations/v15.go
index e29067c98..3492a7190 100644
--- a/models/migrations/v15.go
+++ b/models/migrations/v15.go
@@ -10,21 +10,15 @@ import (
"github.com/go-xorm/xorm"
)
-// UserV15 describes the added field for User
-type UserV15 struct {
- KeepEmailPrivate bool
- AllowCreateOrganization bool
-}
-
-// TableName will be invoked by XORM to customrize the table name
-func (*UserV15) TableName() string {
- return "user"
-}
-
func createAllowCreateOrganizationColumn(x *xorm.Engine) error {
- if err := x.Sync2(new(UserV15)); err != nil {
+ type User struct {
+ KeepEmailPrivate bool
+ AllowCreateOrganization bool
+ }
+
+ if err := x.Sync2(new(User)); err != nil {
return fmt.Errorf("Sync2: %v", err)
- } else if _, err = x.Where("type=0").Cols("allow_create_organization").Update(&UserV15{AllowCreateOrganization: true}); err != nil {
+ } else if _, err = x.Where("`type` = 0").Cols("allow_create_organization").Update(&User{AllowCreateOrganization: true}); err != nil {
return fmt.Errorf("set allow_create_organization: %v", err)
}
return nil
diff --git a/models/migrations/v16.go b/models/migrations/v16.go
index f14b196f2..f6fb76da5 100644
--- a/models/migrations/v16.go
+++ b/models/migrations/v16.go
@@ -33,9 +33,9 @@ func addUnitsToTables(x *xorm.Engine) error {
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:"-"`
+ Config map[string]interface{} `xorm:"JSON"`
+ CreatedUnix int64 `xorm:"INDEX CREATED"`
+ Created time.Time `xorm:"-"`
}
// Repo describes a repository
@@ -95,7 +95,7 @@ func addUnitsToTables(x *xorm.Engine) error {
continue
}
- var config = make(map[string]string)
+ var config = make(map[string]interface{})
switch i {
case V16UnitTypeExternalTracker:
config["ExternalTrackerURL"] = repo.ExternalTrackerURL
diff --git a/models/migrations/v37.go b/models/migrations/v37.go
index aac00e84c..00653a780 100644
--- a/models/migrations/v37.go
+++ b/models/migrations/v37.go
@@ -7,16 +7,19 @@ package migrations
import (
"html"
- "code.gitea.io/gitea/models"
-
"github.com/go-xorm/xorm"
)
func unescapeUserFullNames(x *xorm.Engine) (err error) {
+ type User struct {
+ ID int64 `xorm:"pk autoincr"`
+ FullName string
+ }
+
const batchSize = 100
for start := 0; ; start += batchSize {
- users := make([]*models.User, 0, batchSize)
- if err := x.Limit(start, batchSize).Find(users); err != nil {
+ users := make([]*User, 0, batchSize)
+ if err := x.Limit(batchSize, start).Find(&users); err != nil {
return err
}
if len(users) == 0 {
@@ -24,7 +27,7 @@ func unescapeUserFullNames(x *xorm.Engine) (err error) {
}
for _, user := range users {
user.FullName = html.UnescapeString(user.FullName)
- if _, err := x.Cols("full_name").Update(user); err != nil {
+ if _, err := x.ID(user.ID).Cols("full_name").Update(user); err != nil {
return err
}
}
diff --git a/models/migrations/v38.go b/models/migrations/v38.go
index 216d49935..6f66484b0 100644
--- a/models/migrations/v38.go
+++ b/models/migrations/v38.go
@@ -47,7 +47,7 @@ func removeCommitsUnitType(x *xorm.Engine) (err error) {
}
}
team.UnitTypes = ut
- if _, err := x.Id(team.ID).Cols("unit_types").Update(team); err != nil {
+ if _, err := x.ID(team.ID).Cols("unit_types").Update(team); err != nil {
return err
}
}