@@ -270,7 +270,7 @@ func CountRunnersWithoutBelongingOwner(ctx context.Context) (int64, error) {
270270 // Only affect action runners were a owner ID is set, as actions runners
271271 // could also be created on a repository.
272272 return db .GetEngine (ctx ).Table ("action_runner" ).
273- Join ("LEFT" , "user" , "`action_runner`.owner_id = `user`.id" ).
273+ Join ("LEFT" , "` user` " , "`action_runner`.owner_id = `user`.id" ).
274274 Where ("`action_runner`.owner_id != ?" , 0 ).
275275 And (builder.IsNull {"`user`.id" }).
276276 Count (new (ActionRunner ))
@@ -279,7 +279,7 @@ func CountRunnersWithoutBelongingOwner(ctx context.Context) (int64, error) {
279279func FixRunnersWithoutBelongingOwner (ctx context.Context ) (int64 , error ) {
280280 subQuery := builder .Select ("`action_runner`.id" ).
281281 From ("`action_runner`" ).
282- Join ("LEFT" , "user" , "`action_runner`.owner_id = `user`.id" ).
282+ Join ("LEFT" , "` user` " , "`action_runner`.owner_id = `user`.id" ).
283283 Where (builder.Neq {"`action_runner`.owner_id" : 0 }).
284284 And (builder.IsNull {"`user`.id" })
285285 b := builder .Delete (builder .In ("id" , subQuery )).From ("`action_runner`" )
@@ -289,3 +289,25 @@ func FixRunnersWithoutBelongingOwner(ctx context.Context) (int64, error) {
289289 }
290290 return res .RowsAffected ()
291291}
292+
293+ func CountRunnersWithoutBelongingRepo (ctx context.Context ) (int64 , error ) {
294+ return db .GetEngine (ctx ).Table ("action_runner" ).
295+ Join ("LEFT" , "`repository`" , "`action_runner`.repo_id = `repository`.id" ).
296+ Where ("`action_runner`.repo_id != ?" , 0 ).
297+ And (builder.IsNull {"`repository`.id" }).
298+ Count (new (ActionRunner ))
299+ }
300+
301+ func FixRunnersWithoutBelongingRepo (ctx context.Context ) (int64 , error ) {
302+ subQuery := builder .Select ("`action_runner`.id" ).
303+ From ("`action_runner`" ).
304+ Join ("LEFT" , "`repository`" , "`action_runner`.repo_id = `repository`.id" ).
305+ Where (builder.Neq {"`action_runner`.repo_id" : 0 }).
306+ And (builder.IsNull {"`repository`.id" })
307+ b := builder .Delete (builder .In ("id" , subQuery )).From ("`action_runner`" )
308+ res , err := db .GetEngine (ctx ).Exec (b )
309+ if err != nil {
310+ return 0 , err
311+ }
312+ return res .RowsAffected ()
313+ }
0 commit comments