Skip to content

Commit

Permalink
(error preview)
Browse files Browse the repository at this point in the history
  • Loading branch information
yp05327 committed Mar 9, 2023
1 parent 293a68e commit 5bcc68c
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion models/migrations/v1_20/v245.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,49 @@
package v1_20 //nolint

import (
"fmt"

"code.gitea.io/gitea/modules/log"
"xorm.io/xorm"
)

// FixIncorrectProjectType: set individual project's type from 3(TypeOrganization) to 1(TypeIndividual)
func FixIncorrectProjectType(x *xorm.Engine) error {
_, err := x.Exec("UPDATE project SET type = ? FROM user WHERE user.id = project.owner_id AND project.type = ? AND user.type = ?", 1, 3, 0)
type User struct {
ID int64 `xorm:"pk autoincr"`
Type int
}

const (
UserTypeIndividual int = 0

TypeIndividual uint8 = 1
TypeOrganization uint8 = 3
)

type Project struct {
OwnerID int64 `xorm:"INDEX"`
Type uint8
Owner *User `xorm:"extends"`
}

ps := make([]Project, 0, 10)
count, err := x.Table("project").
//err := x.Table("project").
Join("INNER", "user", "user.id = project.owner_id").
Where("project.type = ? AND user.type = ?", TypeOrganization, UserTypeIndividual).
//Find(&ps)
Update(&Project{
Type: TypeIndividual,
})

if err == nil {
log.Debug("Updated %d projects with owner IS UserTypeIndividual", count)
for _, p := range ps {
fmt.Println(p)
fmt.Println(p.Owner)
}
}

return err
}

0 comments on commit 5bcc68c

Please sign in to comment.