diff --git a/models/migrations/v1_20/v247.go b/models/migrations/v1_20/v247.go index 8395e7bca8ee9..ec345006042dd 100644 --- a/models/migrations/v1_20/v247.go +++ b/models/migrations/v1_20/v247.go @@ -6,6 +6,7 @@ package v1_20 //nolint import ( "code.gitea.io/gitea/modules/log" + "xorm.io/builder" "xorm.io/xorm" ) @@ -36,8 +37,18 @@ func FixIncorrectProjectType(x *xorm.Engine) error { return err } + sql, args, err := builder.ToSQL( + builder.And( + builder.Eq{"type": TypeOrganization}, + builder.And(builder.Eq{"owner_id": builder.Select("id").From("user").Where(builder.Eq{"type": UserTypeIndividual})}), + ), + ) + 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, })