summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--models/actions/runner.go26
-rw-r--r--services/doctor/dbconsistency.go6
2 files changed, 30 insertions, 2 deletions
diff --git a/models/actions/runner.go b/models/actions/runner.go
index 67f003387b..9192925d5a 100644
--- a/models/actions/runner.go
+++ b/models/actions/runner.go
@@ -270,7 +270,7 @@ func CountRunnersWithoutBelongingOwner(ctx context.Context) (int64, error) {
// Only affect action runners were a owner ID is set, as actions runners
// could also be created on a repository.
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).
And(builder.IsNull{"`user`.id"}).
Count(new(ActionRunner))
@@ -279,7 +279,7 @@ func CountRunnersWithoutBelongingOwner(ctx context.Context) (int64, error) {
func FixRunnersWithoutBelongingOwner(ctx context.Context) (int64, error) {
subQuery := builder.Select("`action_runner`.id").
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}).
And(builder.IsNull{"`user`.id"})
b := builder.Delete(builder.In("id", subQuery)).From("`action_runner`")
@@ -289,3 +289,25 @@ func FixRunnersWithoutBelongingOwner(ctx context.Context) (int64, error) {
}
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()
+}
diff --git a/services/doctor/dbconsistency.go b/services/doctor/dbconsistency.go
index dfdf7b547a..7cb7445148 100644
--- a/services/doctor/dbconsistency.go
+++ b/services/doctor/dbconsistency.go
@@ -153,6 +153,12 @@ func prepareDBConsistencyChecks() []consistencyCheck {
FixedMessage: "Removed",
},
{
+ Name: "Action Runners without existing repository",
+ Counter: actions_model.CountRunnersWithoutBelongingRepo,
+ Fixer: actions_model.FixRunnersWithoutBelongingRepo,
+ FixedMessage: "Removed",
+ },
+ {
Name: "Topics with empty repository count",
Counter: repo_model.CountOrphanedTopics,
Fixer: repo_model.DeleteOrphanedTopics,