@@ -284,7 +284,7 @@ func CountRunnersWithoutBelongingOwner(ctx context.Context) (int64, error) {
284284 // Only affect action runners were a owner ID is set, as actions runners
285285 // could also be created on a repository.
286286 return db .GetEngine (ctx ).Table ("action_runner" ).
287- Join ("LEFT" , "user" , "`action_runner`.owner_id = `user`.id" ).
287+ Join ("LEFT" , "` user` " , "`action_runner`.owner_id = `user`.id" ).
288288 Where ("`action_runner`.owner_id != ?" , 0 ).
289289 And (builder.IsNull {"`user`.id" }).
290290 Count (new (ActionRunner ))
@@ -293,7 +293,7 @@ func CountRunnersWithoutBelongingOwner(ctx context.Context) (int64, error) {
293293func FixRunnersWithoutBelongingOwner (ctx context.Context ) (int64 , error ) {
294294 subQuery := builder .Select ("`action_runner`.id" ).
295295 From ("`action_runner`" ).
296- Join ("LEFT" , "user" , "`action_runner`.owner_id = `user`.id" ).
296+ Join ("LEFT" , "` user` " , "`action_runner`.owner_id = `user`.id" ).
297297 Where (builder.Neq {"`action_runner`.owner_id" : 0 }).
298298 And (builder.IsNull {"`user`.id" })
299299 b := builder .Delete (builder .In ("id" , subQuery )).From ("`action_runner`" )
@@ -303,3 +303,25 @@ func FixRunnersWithoutBelongingOwner(ctx context.Context) (int64, error) {
303303 }
304304 return res .RowsAffected ()
305305}
306+
307+ func CountRunnersWithoutBelongingRepo (ctx context.Context ) (int64 , error ) {
308+ return db .GetEngine (ctx ).Table ("action_runner" ).
309+ Join ("LEFT" , "`repository`" , "`action_runner`.repo_id = `repository`.id" ).
310+ Where ("`action_runner`.repo_id != ?" , 0 ).
311+ And (builder.IsNull {"`repository`.id" }).
312+ Count (new (ActionRunner ))
313+ }
314+
315+ func FixRunnersWithoutBelongingRepo (ctx context.Context ) (int64 , error ) {
316+ subQuery := builder .Select ("`action_runner`.id" ).
317+ From ("`action_runner`" ).
318+ Join ("LEFT" , "`repository`" , "`action_runner`.repo_id = `repository`.id" ).
319+ Where (builder.Neq {"`action_runner`.repo_id" : 0 }).
320+ And (builder.IsNull {"`repository`.id" })
321+ b := builder .Delete (builder .In ("id" , subQuery )).From ("`action_runner`" )
322+ res , err := db .GetEngine (ctx ).Exec (b )
323+ if err != nil {
324+ return 0 , err
325+ }
326+ return res .RowsAffected ()
327+ }
0 commit comments