mirror of
https://github.com/go-gitea/gitea.git
synced 2024-12-04 14:46:57 -05:00
Backport #30614
This commit is contained in:
parent
03518d3e18
commit
ddf64b84e4
@ -284,7 +284,7 @@ func CountRunnersWithoutBelongingOwner(ctx context.Context) (int64, error) {
|
|||||||
// Only affect action runners were a owner ID is set, as actions runners
|
// Only affect action runners were a owner ID is set, as actions runners
|
||||||
// could also be created on a repository.
|
// could also be created on a repository.
|
||||||
return db.GetEngine(ctx).Table("action_runner").
|
return db.GetEngine(ctx).Table("action_runner").
|
||||||
Join("LEFT", "user", "`action_runner`.owner_id = `user`.id").
|
Join("LEFT", "`user`", "`action_runner`.owner_id = `user`.id").
|
||||||
Where("`action_runner`.owner_id != ?", 0).
|
Where("`action_runner`.owner_id != ?", 0).
|
||||||
And(builder.IsNull{"`user`.id"}).
|
And(builder.IsNull{"`user`.id"}).
|
||||||
Count(new(ActionRunner))
|
Count(new(ActionRunner))
|
||||||
@ -293,7 +293,7 @@ func CountRunnersWithoutBelongingOwner(ctx context.Context) (int64, error) {
|
|||||||
func FixRunnersWithoutBelongingOwner(ctx context.Context) (int64, error) {
|
func FixRunnersWithoutBelongingOwner(ctx context.Context) (int64, error) {
|
||||||
subQuery := builder.Select("`action_runner`.id").
|
subQuery := builder.Select("`action_runner`.id").
|
||||||
From("`action_runner`").
|
From("`action_runner`").
|
||||||
Join("LEFT", "user", "`action_runner`.owner_id = `user`.id").
|
Join("LEFT", "`user`", "`action_runner`.owner_id = `user`.id").
|
||||||
Where(builder.Neq{"`action_runner`.owner_id": 0}).
|
Where(builder.Neq{"`action_runner`.owner_id": 0}).
|
||||||
And(builder.IsNull{"`user`.id"})
|
And(builder.IsNull{"`user`.id"})
|
||||||
b := builder.Delete(builder.In("id", subQuery)).From("`action_runner`")
|
b := builder.Delete(builder.In("id", subQuery)).From("`action_runner`")
|
||||||
@ -303,3 +303,25 @@ func FixRunnersWithoutBelongingOwner(ctx context.Context) (int64, error) {
|
|||||||
}
|
}
|
||||||
return res.RowsAffected()
|
return res.RowsAffected()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CountRunnersWithoutBelongingRepo(ctx context.Context) (int64, error) {
|
||||||
|
return db.GetEngine(ctx).Table("action_runner").
|
||||||
|
Join("LEFT", "`repository`", "`action_runner`.repo_id = `repository`.id").
|
||||||
|
Where("`action_runner`.repo_id != ?", 0).
|
||||||
|
And(builder.IsNull{"`repository`.id"}).
|
||||||
|
Count(new(ActionRunner))
|
||||||
|
}
|
||||||
|
|
||||||
|
func FixRunnersWithoutBelongingRepo(ctx context.Context) (int64, error) {
|
||||||
|
subQuery := builder.Select("`action_runner`.id").
|
||||||
|
From("`action_runner`").
|
||||||
|
Join("LEFT", "`repository`", "`action_runner`.repo_id = `repository`.id").
|
||||||
|
Where(builder.Neq{"`action_runner`.repo_id": 0}).
|
||||||
|
And(builder.IsNull{"`repository`.id"})
|
||||||
|
b := builder.Delete(builder.In("id", subQuery)).From("`action_runner`")
|
||||||
|
res, err := db.GetEngine(ctx).Exec(b)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return res.RowsAffected()
|
||||||
|
}
|
||||||
|
@ -158,6 +158,12 @@ func checkDBConsistency(ctx context.Context, logger log.Logger, autofix bool) er
|
|||||||
Fixer: actions_model.FixRunnersWithoutBelongingOwner,
|
Fixer: actions_model.FixRunnersWithoutBelongingOwner,
|
||||||
FixedMessage: "Removed",
|
FixedMessage: "Removed",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "Action Runners without existing repository",
|
||||||
|
Counter: actions_model.CountRunnersWithoutBelongingRepo,
|
||||||
|
Fixer: actions_model.FixRunnersWithoutBelongingRepo,
|
||||||
|
FixedMessage: "Removed",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: function to recalc all counters
|
// TODO: function to recalc all counters
|
||||||
|
Loading…
Reference in New Issue
Block a user