Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport of migration fixes (#2604) #2677

Merged
merged 3 commits into from
Oct 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions models/migrations/v15.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions models/migrations/v16.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions models/migrations/v37.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,27 @@ 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 {
return nil
}
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
}
}
Expand Down
2 changes: 1 addition & 1 deletion models/migrations/v38.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down