Skip to content

Commit dd48773

Browse files
lafriksdaviian
authored andcommitted
Fix migration from Gogs
1 parent fb73cb0 commit dd48773

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

models/migrations/v15.go

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,15 @@ import (
1010
"github.com/go-xorm/xorm"
1111
)
1212

13-
// UserV15 describes the added field for User
14-
type UserV15 struct {
15-
KeepEmailPrivate bool
16-
AllowCreateOrganization bool
17-
}
18-
19-
// TableName will be invoked by XORM to customrize the table name
20-
func (*UserV15) TableName() string {
21-
return "user"
22-
}
23-
2413
func createAllowCreateOrganizationColumn(x *xorm.Engine) error {
25-
if err := x.Sync2(new(UserV15)); err != nil {
14+
type User struct {
15+
KeepEmailPrivate bool
16+
AllowCreateOrganization bool
17+
}
18+
19+
if err := x.Sync2(new(User)); err != nil {
2620
return fmt.Errorf("Sync2: %v", err)
27-
} else if _, err = x.Where("type=0").Cols("allow_create_organization").Update(&UserV15{AllowCreateOrganization: true}); err != nil {
21+
} else if _, err = x.Where("`type`=0").Cols("allow_create_organization").Update(&User{AllowCreateOrganization: true}); err != nil {
2822
return fmt.Errorf("set allow_create_organization: %v", err)
2923
}
3024
return nil

models/migrations/v37.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@ package migrations
77
import (
88
"html"
99

10-
"code.gitea.io/gitea/models"
11-
1210
"github.com/go-xorm/xorm"
1311
)
1412

1513
func unescapeUserFullNames(x *xorm.Engine) (err error) {
14+
type User struct {
15+
ID int64 `xorm:"pk autoincr"`
16+
FullName string
17+
}
18+
1619
const batchSize = 100
1720
for start := 0; ; start += batchSize {
18-
users := make([]*models.User, 0, batchSize)
21+
users := make([]*User, 0, batchSize)
1922
if err := x.Limit(start, batchSize).Find(users); err != nil {
2023
return err
2124
}
@@ -24,7 +27,7 @@ func unescapeUserFullNames(x *xorm.Engine) (err error) {
2427
}
2528
for _, user := range users {
2629
user.FullName = html.UnescapeString(user.FullName)
27-
if _, err := x.Cols("full_name").Update(user); err != nil {
30+
if _, err := x.Where("`id` = ?", user.ID).Cols("full_name").Update(user); err != nil {
2831
return err
2932
}
3033
}

models/migrations/v39.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ func addTimetracking(x *xorm.Engine) error {
6969
return fmt.Errorf("Sync2: %v", err)
7070
}
7171
//Updating existing issue units
72-
var units []*RepoUnit
73-
x.Where("type = ?", V16UnitTypeIssues).Find(&units)
72+
units := make([]*RepoUnit, 0, 100)
73+
x.Where("`type` = ?", V16UnitTypeIssues).Find(units)
7474
for _, unit := range units {
7575
if unit.Config != nil {
7676
continue

0 commit comments

Comments
 (0)