mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-11 15:58:30 +00:00
refactor: prepare to decouple the "model migration" package and "models" package (#38533)
Migrations should never use model structs directly, because the model structs can be different in different releases. e.g. if one migration uses "User" model, it works in the early releases, then one day, when the User model changes, the migration breaks because it will use the new (incorrect) User model, it should only use the old User model. The same to "modules/structs". --------- Signed-off-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: delvh <dev.lh@web.de>
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
// Copyright 2018 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package v1_7
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
|
||||
func AddMustChangePassword(x base.EngineMigration) error {
|
||||
// User see models/user.go
|
||||
type User struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
MustChangePassword bool `xorm:"NOT NULL DEFAULT false"`
|
||||
}
|
||||
|
||||
return x.Sync(new(User))
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// Copyright 2018 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package v1_7
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
|
||||
func AddApprovalWhitelistsToProtectedBranches(x base.EngineMigration) error {
|
||||
type ProtectedBranch struct {
|
||||
ApprovalsWhitelistUserIDs []int64 `xorm:"JSON TEXT"`
|
||||
ApprovalsWhitelistTeamIDs []int64 `xorm:"JSON TEXT"`
|
||||
RequiredApprovals int64 `xorm:"NOT NULL DEFAULT 0"`
|
||||
}
|
||||
return x.Sync(new(ProtectedBranch))
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Copyright 2018 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package v1_7
|
||||
|
||||
import (
|
||||
"gitea.dev/modelmigration/base"
|
||||
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
func ClearNonusedData(x base.EngineMigration) error {
|
||||
condDelete := func(colName string) builder.Cond {
|
||||
return builder.NotIn(colName, builder.Select("id").From("`user`"))
|
||||
}
|
||||
|
||||
if _, err := x.Exec(builder.Delete(condDelete("uid")).From("team_user")); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := x.Exec(builder.Delete(condDelete("user_id")).From("collaboration")); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := x.Exec(builder.Delete(condDelete("user_id")).From("stopwatch")); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := x.Exec(builder.Delete(condDelete("owner_id")).From("gpg_key")); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user