Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
yp05327 committed Mar 15, 2023
1 parent 41671bb commit 3d86625
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion models/migrations/v1_20/v246.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
package v1_20 //nolint

import (
"code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/log"

"xorm.io/builder"
"xorm.io/xorm"
)

Expand All @@ -24,6 +26,7 @@ func FixIncorrectProjectType(x *xorm.Engine) error {
)

type Project struct {
ID int64 `xorm:"pk autoincr"`
OwnerID int64 `xorm:"INDEX"`
Type uint8
Owner *User `xorm:"extends"`
Expand All @@ -36,8 +39,30 @@ func FixIncorrectProjectType(x *xorm.Engine) error {
return err
}

var ps []Project
err := sess.Table("project").
Join("INNER", "user", "user.id = project.owner_id").
Where("project.type = ? AND user.type = ?", TypeOrganization, UserTypeIndividual).
Find(&ps)
if err != nil {
return err
}

pids := make(container.Set[int64], len(ps))
for _, p := range ps {
if p.ID == 0 {
continue
}
pids.Add(p.ID)
}

sql, args, err := builder.ToSQL(builder.Eq{"id": pids.Values()})
if err != nil {
return err
}

count, err := sess.Table("project").
Where("type = ? AND owner_id IN (SELECT id FROM user WHERE type = ?)", TypeOrganization, UserTypeIndividual).
Where(sql, args...).
Update(&Project{
Type: TypeIndividual,
})
Expand Down

0 comments on commit 3d86625

Please sign in to comment.