Skip to content

Commit 5bcc68c

Browse files
committed
(error preview)
1 parent 293a68e commit 5bcc68c

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

models/migrations/v1_20/v245.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,49 @@
44
package v1_20 //nolint
55

66
import (
7+
"fmt"
8+
9+
"code.gitea.io/gitea/modules/log"
710
"xorm.io/xorm"
811
)
912

1013
// FixIncorrectProjectType: set individual project's type from 3(TypeOrganization) to 1(TypeIndividual)
1114
func FixIncorrectProjectType(x *xorm.Engine) error {
12-
_, err := x.Exec("UPDATE project SET type = ? FROM user WHERE user.id = project.owner_id AND project.type = ? AND user.type = ?", 1, 3, 0)
15+
type User struct {
16+
ID int64 `xorm:"pk autoincr"`
17+
Type int
18+
}
19+
20+
const (
21+
UserTypeIndividual int = 0
22+
23+
TypeIndividual uint8 = 1
24+
TypeOrganization uint8 = 3
25+
)
26+
27+
type Project struct {
28+
OwnerID int64 `xorm:"INDEX"`
29+
Type uint8
30+
Owner *User `xorm:"extends"`
31+
}
32+
33+
ps := make([]Project, 0, 10)
34+
count, err := x.Table("project").
35+
//err := x.Table("project").
36+
Join("INNER", "user", "user.id = project.owner_id").
37+
Where("project.type = ? AND user.type = ?", TypeOrganization, UserTypeIndividual).
38+
//Find(&ps)
39+
Update(&Project{
40+
Type: TypeIndividual,
41+
})
42+
43+
if err == nil {
44+
log.Debug("Updated %d projects with owner IS UserTypeIndividual", count)
45+
for _, p := range ps {
46+
fmt.Println(p)
47+
fmt.Println(p.Owner)
48+
}
49+
}
1350

1451
return err
1552
}

0 commit comments

Comments
 (0)