Go · 19804 bytes Raw Blame History
1 // Code generated by sqlc. DO NOT EDIT.
2 // versions:
3 // sqlc v1.31.1
4 // source: workflow_runs.sql
5
6 package actionsdb
7
8 import (
9 "context"
10
11 "github.com/jackc/pgx/v5/pgtype"
12 )
13
14 const completeWorkflowRun = `-- name: CompleteWorkflowRun :one
15 UPDATE workflow_runs
16 SET status = 'completed',
17 conclusion = $2::check_conclusion,
18 started_at = COALESCE(started_at, now()),
19 completed_at = COALESCE(completed_at, now()),
20 version = version + 1,
21 updated_at = now()
22 WHERE id = $1
23 RETURNING id, repo_id, run_index, workflow_file, workflow_name,
24 head_sha, head_ref, event, event_payload,
25 actor_user_id, parent_run_id, concurrency_group,
26 status, conclusion, pinned, need_approval, approved_by_user_id,
27 started_at, completed_at, version, created_at, updated_at, trigger_event_id
28 `
29
30 type CompleteWorkflowRunParams struct {
31 ID int64
32 Conclusion CheckConclusion
33 }
34
35 func (q *Queries) CompleteWorkflowRun(ctx context.Context, db DBTX, arg CompleteWorkflowRunParams) (WorkflowRun, error) {
36 row := db.QueryRow(ctx, completeWorkflowRun, arg.ID, arg.Conclusion)
37 var i WorkflowRun
38 err := row.Scan(
39 &i.ID,
40 &i.RepoID,
41 &i.RunIndex,
42 &i.WorkflowFile,
43 &i.WorkflowName,
44 &i.HeadSha,
45 &i.HeadRef,
46 &i.Event,
47 &i.EventPayload,
48 &i.ActorUserID,
49 &i.ParentRunID,
50 &i.ConcurrencyGroup,
51 &i.Status,
52 &i.Conclusion,
53 &i.Pinned,
54 &i.NeedApproval,
55 &i.ApprovedByUserID,
56 &i.StartedAt,
57 &i.CompletedAt,
58 &i.Version,
59 &i.CreatedAt,
60 &i.UpdatedAt,
61 &i.TriggerEventID,
62 )
63 return i, err
64 }
65
66 const countWorkflowRunsForRepo = `-- name: CountWorkflowRunsForRepo :one
67 SELECT COUNT(*)::bigint
68 FROM workflow_runs r
69 LEFT JOIN users u ON u.id = r.actor_user_id
70 WHERE r.repo_id = $1::bigint
71 AND ($2::text IS NULL OR r.workflow_file = $2::text)
72 AND ($3::text IS NULL OR r.head_ref = $3::text)
73 AND ($4::workflow_run_event IS NULL OR r.event = $4::workflow_run_event)
74 AND ($5::workflow_run_status IS NULL OR r.status = $5::workflow_run_status)
75 AND ($6::check_conclusion IS NULL OR r.conclusion = $6::check_conclusion)
76 AND ($7::text IS NULL OR u.username = $7::citext)
77 `
78
79 type CountWorkflowRunsForRepoParams struct {
80 RepoID int64
81 WorkflowFile pgtype.Text
82 HeadRef pgtype.Text
83 Event NullWorkflowRunEvent
84 Status NullWorkflowRunStatus
85 Conclusion NullCheckConclusion
86 ActorUsername pgtype.Text
87 }
88
89 func (q *Queries) CountWorkflowRunsForRepo(ctx context.Context, db DBTX, arg CountWorkflowRunsForRepoParams) (int64, error) {
90 row := db.QueryRow(ctx, countWorkflowRunsForRepo,
91 arg.RepoID,
92 arg.WorkflowFile,
93 arg.HeadRef,
94 arg.Event,
95 arg.Status,
96 arg.Conclusion,
97 arg.ActorUsername,
98 )
99 var column_1 int64
100 err := row.Scan(&column_1)
101 return column_1, err
102 }
103
104 const deleteOldWorkflowRunsForCleanup = `-- name: DeleteOldWorkflowRunsForCleanup :execrows
105 DELETE FROM workflow_runs
106 WHERE pinned = false
107 AND status IN ('completed', 'cancelled')
108 AND completed_at IS NOT NULL
109 AND completed_at < $1
110 `
111
112 func (q *Queries) DeleteOldWorkflowRunsForCleanup(ctx context.Context, db DBTX, completedAt pgtype.Timestamptz) (int64, error) {
113 result, err := db.Exec(ctx, deleteOldWorkflowRunsForCleanup, completedAt)
114 if err != nil {
115 return 0, err
116 }
117 return result.RowsAffected(), nil
118 }
119
120 const enqueueWorkflowRun = `-- name: EnqueueWorkflowRun :one
121 INSERT INTO workflow_runs (
122 repo_id, run_index, workflow_file, workflow_name,
123 head_sha, head_ref, event, event_payload,
124 actor_user_id, parent_run_id, concurrency_group, need_approval,
125 trigger_event_id
126 ) VALUES (
127 $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13
128 )
129 ON CONFLICT (repo_id, workflow_file, trigger_event_id) WHERE trigger_event_id <> ''
130 DO NOTHING
131 RETURNING id, repo_id, run_index, workflow_file, workflow_name,
132 head_sha, head_ref, event, event_payload,
133 actor_user_id, parent_run_id, concurrency_group,
134 status, conclusion, pinned, need_approval, approved_by_user_id,
135 started_at, completed_at, version, created_at, updated_at, trigger_event_id
136 `
137
138 type EnqueueWorkflowRunParams struct {
139 RepoID int64
140 RunIndex int64
141 WorkflowFile string
142 WorkflowName string
143 HeadSha string
144 HeadRef string
145 Event WorkflowRunEvent
146 EventPayload []byte
147 ActorUserID pgtype.Int8
148 ParentRunID pgtype.Int8
149 ConcurrencyGroup string
150 NeedApproval bool
151 TriggerEventID string
152 }
153
154 // Idempotent insert: if a row with the same (repo_id, workflow_file,
155 // trigger_event_id) already exists, returns no rows (pgx.ErrNoRows in
156 // Go). The handler treats that as a successful no-op so worker
157 // retries and admin replays of the same triggering event don't
158 // duplicate runs.
159 //
160 // The ON CONFLICT predicate matches the partial unique index defined
161 // in migration 0051; both must agree for postgres to infer the
162 // target.
163 func (q *Queries) EnqueueWorkflowRun(ctx context.Context, db DBTX, arg EnqueueWorkflowRunParams) (WorkflowRun, error) {
164 row := db.QueryRow(ctx, enqueueWorkflowRun,
165 arg.RepoID,
166 arg.RunIndex,
167 arg.WorkflowFile,
168 arg.WorkflowName,
169 arg.HeadSha,
170 arg.HeadRef,
171 arg.Event,
172 arg.EventPayload,
173 arg.ActorUserID,
174 arg.ParentRunID,
175 arg.ConcurrencyGroup,
176 arg.NeedApproval,
177 arg.TriggerEventID,
178 )
179 var i WorkflowRun
180 err := row.Scan(
181 &i.ID,
182 &i.RepoID,
183 &i.RunIndex,
184 &i.WorkflowFile,
185 &i.WorkflowName,
186 &i.HeadSha,
187 &i.HeadRef,
188 &i.Event,
189 &i.EventPayload,
190 &i.ActorUserID,
191 &i.ParentRunID,
192 &i.ConcurrencyGroup,
193 &i.Status,
194 &i.Conclusion,
195 &i.Pinned,
196 &i.NeedApproval,
197 &i.ApprovedByUserID,
198 &i.StartedAt,
199 &i.CompletedAt,
200 &i.Version,
201 &i.CreatedAt,
202 &i.UpdatedAt,
203 &i.TriggerEventID,
204 )
205 return i, err
206 }
207
208 const getWorkflowRunByID = `-- name: GetWorkflowRunByID :one
209 SELECT id, repo_id, run_index, workflow_file, workflow_name,
210 head_sha, head_ref, event, event_payload,
211 actor_user_id, parent_run_id, concurrency_group,
212 status, conclusion, pinned, need_approval, approved_by_user_id,
213 started_at, completed_at, version, created_at, updated_at, trigger_event_id
214 FROM workflow_runs
215 WHERE id = $1
216 `
217
218 func (q *Queries) GetWorkflowRunByID(ctx context.Context, db DBTX, id int64) (WorkflowRun, error) {
219 row := db.QueryRow(ctx, getWorkflowRunByID, id)
220 var i WorkflowRun
221 err := row.Scan(
222 &i.ID,
223 &i.RepoID,
224 &i.RunIndex,
225 &i.WorkflowFile,
226 &i.WorkflowName,
227 &i.HeadSha,
228 &i.HeadRef,
229 &i.Event,
230 &i.EventPayload,
231 &i.ActorUserID,
232 &i.ParentRunID,
233 &i.ConcurrencyGroup,
234 &i.Status,
235 &i.Conclusion,
236 &i.Pinned,
237 &i.NeedApproval,
238 &i.ApprovedByUserID,
239 &i.StartedAt,
240 &i.CompletedAt,
241 &i.Version,
242 &i.CreatedAt,
243 &i.UpdatedAt,
244 &i.TriggerEventID,
245 )
246 return i, err
247 }
248
249 const getWorkflowRunForRepoByIndex = `-- name: GetWorkflowRunForRepoByIndex :one
250 SELECT r.id, r.repo_id, r.run_index, r.workflow_file, r.workflow_name,
251 r.head_sha, r.head_ref, r.event, r.event_payload,
252 r.actor_user_id, COALESCE(u.username::text, '')::text AS actor_username,
253 r.parent_run_id, r.concurrency_group,
254 r.status, r.conclusion, r.pinned, r.need_approval, r.approved_by_user_id,
255 r.started_at, r.completed_at, r.version, r.created_at, r.updated_at, r.trigger_event_id
256 FROM workflow_runs r
257 LEFT JOIN users u ON u.id = r.actor_user_id
258 WHERE r.repo_id = $1 AND r.run_index = $2
259 `
260
261 type GetWorkflowRunForRepoByIndexParams struct {
262 RepoID int64
263 RunIndex int64
264 }
265
266 type GetWorkflowRunForRepoByIndexRow struct {
267 ID int64
268 RepoID int64
269 RunIndex int64
270 WorkflowFile string
271 WorkflowName string
272 HeadSha string
273 HeadRef string
274 Event WorkflowRunEvent
275 EventPayload []byte
276 ActorUserID pgtype.Int8
277 ActorUsername string
278 ParentRunID pgtype.Int8
279 ConcurrencyGroup string
280 Status WorkflowRunStatus
281 Conclusion NullCheckConclusion
282 Pinned bool
283 NeedApproval bool
284 ApprovedByUserID pgtype.Int8
285 StartedAt pgtype.Timestamptz
286 CompletedAt pgtype.Timestamptz
287 Version int32
288 CreatedAt pgtype.Timestamptz
289 UpdatedAt pgtype.Timestamptz
290 TriggerEventID string
291 }
292
293 func (q *Queries) GetWorkflowRunForRepoByIndex(ctx context.Context, db DBTX, arg GetWorkflowRunForRepoByIndexParams) (GetWorkflowRunForRepoByIndexRow, error) {
294 row := db.QueryRow(ctx, getWorkflowRunForRepoByIndex, arg.RepoID, arg.RunIndex)
295 var i GetWorkflowRunForRepoByIndexRow
296 err := row.Scan(
297 &i.ID,
298 &i.RepoID,
299 &i.RunIndex,
300 &i.WorkflowFile,
301 &i.WorkflowName,
302 &i.HeadSha,
303 &i.HeadRef,
304 &i.Event,
305 &i.EventPayload,
306 &i.ActorUserID,
307 &i.ActorUsername,
308 &i.ParentRunID,
309 &i.ConcurrencyGroup,
310 &i.Status,
311 &i.Conclusion,
312 &i.Pinned,
313 &i.NeedApproval,
314 &i.ApprovedByUserID,
315 &i.StartedAt,
316 &i.CompletedAt,
317 &i.Version,
318 &i.CreatedAt,
319 &i.UpdatedAt,
320 &i.TriggerEventID,
321 )
322 return i, err
323 }
324
325 const insertWorkflowRun = `-- name: InsertWorkflowRun :one
326
327 INSERT INTO workflow_runs (
328 repo_id, run_index, workflow_file, workflow_name,
329 head_sha, head_ref, event, event_payload,
330 actor_user_id, parent_run_id, concurrency_group, need_approval
331 ) VALUES (
332 $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12
333 )
334 RETURNING id, repo_id, run_index, workflow_file, workflow_name,
335 head_sha, head_ref, event, event_payload,
336 actor_user_id, parent_run_id, concurrency_group,
337 status, conclusion, pinned, need_approval, approved_by_user_id,
338 started_at, completed_at, version, created_at, updated_at, trigger_event_id
339 `
340
341 type InsertWorkflowRunParams struct {
342 RepoID int64
343 RunIndex int64
344 WorkflowFile string
345 WorkflowName string
346 HeadSha string
347 HeadRef string
348 Event WorkflowRunEvent
349 EventPayload []byte
350 ActorUserID pgtype.Int8
351 ParentRunID pgtype.Int8
352 ConcurrencyGroup string
353 NeedApproval bool
354 }
355
356 // SPDX-License-Identifier: AGPL-3.0-or-later
357 func (q *Queries) InsertWorkflowRun(ctx context.Context, db DBTX, arg InsertWorkflowRunParams) (WorkflowRun, error) {
358 row := db.QueryRow(ctx, insertWorkflowRun,
359 arg.RepoID,
360 arg.RunIndex,
361 arg.WorkflowFile,
362 arg.WorkflowName,
363 arg.HeadSha,
364 arg.HeadRef,
365 arg.Event,
366 arg.EventPayload,
367 arg.ActorUserID,
368 arg.ParentRunID,
369 arg.ConcurrencyGroup,
370 arg.NeedApproval,
371 )
372 var i WorkflowRun
373 err := row.Scan(
374 &i.ID,
375 &i.RepoID,
376 &i.RunIndex,
377 &i.WorkflowFile,
378 &i.WorkflowName,
379 &i.HeadSha,
380 &i.HeadRef,
381 &i.Event,
382 &i.EventPayload,
383 &i.ActorUserID,
384 &i.ParentRunID,
385 &i.ConcurrencyGroup,
386 &i.Status,
387 &i.Conclusion,
388 &i.Pinned,
389 &i.NeedApproval,
390 &i.ApprovedByUserID,
391 &i.StartedAt,
392 &i.CompletedAt,
393 &i.Version,
394 &i.CreatedAt,
395 &i.UpdatedAt,
396 &i.TriggerEventID,
397 )
398 return i, err
399 }
400
401 const listBlockingConcurrencyRunsForUpdate = `-- name: ListBlockingConcurrencyRunsForUpdate :many
402 SELECT r.id, r.repo_id, r.run_index, r.workflow_file, r.workflow_name,
403 r.head_sha, r.head_ref, r.event, r.event_payload,
404 r.actor_user_id, r.parent_run_id, r.concurrency_group,
405 r.status, r.conclusion, r.pinned, r.need_approval, r.approved_by_user_id,
406 r.started_at, r.completed_at, r.version, r.created_at, r.updated_at, r.trigger_event_id
407 FROM workflow_runs r
408 JOIN workflow_runs current_run ON current_run.id = $1::bigint
409 WHERE r.repo_id = $2::bigint
410 AND r.concurrency_group = $3::text
411 AND r.concurrency_group <> ''
412 AND r.id <> current_run.id
413 AND r.status IN ('queued', 'running')
414 AND (r.created_at, r.id) < (current_run.created_at, current_run.id)
415 AND EXISTS (
416 SELECT 1
417 FROM workflow_jobs j
418 WHERE j.run_id = r.id
419 AND j.status IN ('queued', 'running')
420 AND j.cancel_requested = false
421 )
422 ORDER BY r.created_at ASC, r.id ASC
423 FOR UPDATE OF r
424 `
425
426 type ListBlockingConcurrencyRunsForUpdateParams struct {
427 RunID int64
428 RepoID int64
429 ConcurrencyGroup string
430 }
431
432 // Older queued/running runs with the same group block the new run while they
433 // still have at least one queued/running job that has not already received a
434 // cancel request. cancel-in-progress releases the slot by flipping that job
435 // flag even if the runner is still draining the old container.
436 func (q *Queries) ListBlockingConcurrencyRunsForUpdate(ctx context.Context, db DBTX, arg ListBlockingConcurrencyRunsForUpdateParams) ([]WorkflowRun, error) {
437 rows, err := db.Query(ctx, listBlockingConcurrencyRunsForUpdate, arg.RunID, arg.RepoID, arg.ConcurrencyGroup)
438 if err != nil {
439 return nil, err
440 }
441 defer rows.Close()
442 items := []WorkflowRun{}
443 for rows.Next() {
444 var i WorkflowRun
445 if err := rows.Scan(
446 &i.ID,
447 &i.RepoID,
448 &i.RunIndex,
449 &i.WorkflowFile,
450 &i.WorkflowName,
451 &i.HeadSha,
452 &i.HeadRef,
453 &i.Event,
454 &i.EventPayload,
455 &i.ActorUserID,
456 &i.ParentRunID,
457 &i.ConcurrencyGroup,
458 &i.Status,
459 &i.Conclusion,
460 &i.Pinned,
461 &i.NeedApproval,
462 &i.ApprovedByUserID,
463 &i.StartedAt,
464 &i.CompletedAt,
465 &i.Version,
466 &i.CreatedAt,
467 &i.UpdatedAt,
468 &i.TriggerEventID,
469 ); err != nil {
470 return nil, err
471 }
472 items = append(items, i)
473 }
474 if err := rows.Err(); err != nil {
475 return nil, err
476 }
477 return items, nil
478 }
479
480 const listWorkflowRunWorkflowsForRepo = `-- name: ListWorkflowRunWorkflowsForRepo :many
481 WITH ranked AS (
482 SELECT workflow_file,
483 workflow_name,
484 (COUNT(*) OVER (PARTITION BY workflow_file))::bigint AS run_count,
485 ROW_NUMBER() OVER (PARTITION BY workflow_file ORDER BY created_at DESC, id DESC) AS rn
486 FROM workflow_runs
487 WHERE repo_id = $1
488 )
489 SELECT workflow_file,
490 COALESCE(NULLIF(workflow_name, ''), workflow_file) AS workflow_name,
491 run_count
492 FROM ranked
493 WHERE rn = 1
494 ORDER BY lower(COALESCE(NULLIF(workflow_name, ''), workflow_file)), workflow_file
495 `
496
497 type ListWorkflowRunWorkflowsForRepoRow struct {
498 WorkflowFile string
499 WorkflowName string
500 RunCount int64
501 }
502
503 func (q *Queries) ListWorkflowRunWorkflowsForRepo(ctx context.Context, db DBTX, repoID int64) ([]ListWorkflowRunWorkflowsForRepoRow, error) {
504 rows, err := db.Query(ctx, listWorkflowRunWorkflowsForRepo, repoID)
505 if err != nil {
506 return nil, err
507 }
508 defer rows.Close()
509 items := []ListWorkflowRunWorkflowsForRepoRow{}
510 for rows.Next() {
511 var i ListWorkflowRunWorkflowsForRepoRow
512 if err := rows.Scan(&i.WorkflowFile, &i.WorkflowName, &i.RunCount); err != nil {
513 return nil, err
514 }
515 items = append(items, i)
516 }
517 if err := rows.Err(); err != nil {
518 return nil, err
519 }
520 return items, nil
521 }
522
523 const listWorkflowRunsForRepo = `-- name: ListWorkflowRunsForRepo :many
524 SELECT r.id, r.repo_id, r.run_index, r.workflow_file, r.workflow_name,
525 r.head_sha, r.head_ref, r.event, r.status, r.conclusion,
526 r.actor_user_id, COALESCE(u.username::text, '')::text AS actor_username,
527 r.started_at, r.completed_at, r.created_at, r.updated_at
528 FROM workflow_runs r
529 LEFT JOIN users u ON u.id = r.actor_user_id
530 WHERE r.repo_id = $1::bigint
531 AND ($2::text IS NULL OR r.workflow_file = $2::text)
532 AND ($3::text IS NULL OR r.head_ref = $3::text)
533 AND ($4::workflow_run_event IS NULL OR r.event = $4::workflow_run_event)
534 AND ($5::workflow_run_status IS NULL OR r.status = $5::workflow_run_status)
535 AND ($6::check_conclusion IS NULL OR r.conclusion = $6::check_conclusion)
536 AND ($7::text IS NULL OR u.username = $7::citext)
537 ORDER BY r.created_at DESC, r.id DESC
538 LIMIT $9 OFFSET $8
539 `
540
541 type ListWorkflowRunsForRepoParams struct {
542 RepoID int64
543 WorkflowFile pgtype.Text
544 HeadRef pgtype.Text
545 Event NullWorkflowRunEvent
546 Status NullWorkflowRunStatus
547 Conclusion NullCheckConclusion
548 ActorUsername pgtype.Text
549 PageOffset int32
550 PageLimit int32
551 }
552
553 type ListWorkflowRunsForRepoRow struct {
554 ID int64
555 RepoID int64
556 RunIndex int64
557 WorkflowFile string
558 WorkflowName string
559 HeadSha string
560 HeadRef string
561 Event WorkflowRunEvent
562 Status WorkflowRunStatus
563 Conclusion NullCheckConclusion
564 ActorUserID pgtype.Int8
565 ActorUsername string
566 StartedAt pgtype.Timestamptz
567 CompletedAt pgtype.Timestamptz
568 CreatedAt pgtype.Timestamptz
569 UpdatedAt pgtype.Timestamptz
570 }
571
572 func (q *Queries) ListWorkflowRunsForRepo(ctx context.Context, db DBTX, arg ListWorkflowRunsForRepoParams) ([]ListWorkflowRunsForRepoRow, error) {
573 rows, err := db.Query(ctx, listWorkflowRunsForRepo,
574 arg.RepoID,
575 arg.WorkflowFile,
576 arg.HeadRef,
577 arg.Event,
578 arg.Status,
579 arg.Conclusion,
580 arg.ActorUsername,
581 arg.PageOffset,
582 arg.PageLimit,
583 )
584 if err != nil {
585 return nil, err
586 }
587 defer rows.Close()
588 items := []ListWorkflowRunsForRepoRow{}
589 for rows.Next() {
590 var i ListWorkflowRunsForRepoRow
591 if err := rows.Scan(
592 &i.ID,
593 &i.RepoID,
594 &i.RunIndex,
595 &i.WorkflowFile,
596 &i.WorkflowName,
597 &i.HeadSha,
598 &i.HeadRef,
599 &i.Event,
600 &i.Status,
601 &i.Conclusion,
602 &i.ActorUserID,
603 &i.ActorUsername,
604 &i.StartedAt,
605 &i.CompletedAt,
606 &i.CreatedAt,
607 &i.UpdatedAt,
608 ); err != nil {
609 return nil, err
610 }
611 items = append(items, i)
612 }
613 if err := rows.Err(); err != nil {
614 return nil, err
615 }
616 return items, nil
617 }
618
619 const lookupWorkflowRunByTriggerEvent = `-- name: LookupWorkflowRunByTriggerEvent :one
620 SELECT id, repo_id, run_index, workflow_file, workflow_name,
621 head_sha, head_ref, event, event_payload,
622 actor_user_id, parent_run_id, concurrency_group,
623 status, conclusion, pinned, need_approval, approved_by_user_id,
624 started_at, completed_at, version, created_at, updated_at, trigger_event_id
625 FROM workflow_runs
626 WHERE repo_id = $1 AND workflow_file = $2 AND trigger_event_id = $3
627 `
628
629 type LookupWorkflowRunByTriggerEventParams struct {
630 RepoID int64
631 WorkflowFile string
632 TriggerEventID string
633 }
634
635 // Companion to EnqueueWorkflowRun for the conflict path: when an
636 // INSERT ... ON CONFLICT DO NOTHING returns no rows, the trigger
637 // handler uses this to find the existing row so it can surface a
638 // stable RunID. Matches the partial-unique index from migration 0051.
639 func (q *Queries) LookupWorkflowRunByTriggerEvent(ctx context.Context, db DBTX, arg LookupWorkflowRunByTriggerEventParams) (WorkflowRun, error) {
640 row := db.QueryRow(ctx, lookupWorkflowRunByTriggerEvent, arg.RepoID, arg.WorkflowFile, arg.TriggerEventID)
641 var i WorkflowRun
642 err := row.Scan(
643 &i.ID,
644 &i.RepoID,
645 &i.RunIndex,
646 &i.WorkflowFile,
647 &i.WorkflowName,
648 &i.HeadSha,
649 &i.HeadRef,
650 &i.Event,
651 &i.EventPayload,
652 &i.ActorUserID,
653 &i.ParentRunID,
654 &i.ConcurrencyGroup,
655 &i.Status,
656 &i.Conclusion,
657 &i.Pinned,
658 &i.NeedApproval,
659 &i.ApprovedByUserID,
660 &i.StartedAt,
661 &i.CompletedAt,
662 &i.Version,
663 &i.CreatedAt,
664 &i.UpdatedAt,
665 &i.TriggerEventID,
666 )
667 return i, err
668 }
669
670 const markWorkflowRunRunning = `-- name: MarkWorkflowRunRunning :exec
671 UPDATE workflow_runs
672 SET status = 'running',
673 started_at = COALESCE(started_at, now()),
674 version = version + 1,
675 updated_at = now()
676 WHERE id = $1 AND status = 'queued'
677 `
678
679 func (q *Queries) MarkWorkflowRunRunning(ctx context.Context, db DBTX, id int64) error {
680 _, err := db.Exec(ctx, markWorkflowRunRunning, id)
681 return err
682 }
683
684 const nextRunIndexForRepo = `-- name: NextRunIndexForRepo :one
685 SELECT (COALESCE(MAX(run_index), 0) + 1)::bigint AS next_index
686 FROM workflow_runs
687 WHERE repo_id = $1
688 `
689
690 // Atomic next-index emitter: take the max + 1 for this repo. Pairs
691 // with the (repo_id, run_index) UNIQUE so concurrent inserts that
692 // race here will catch a unique-violation and the caller retries.
693 // Cast to bigint so sqlc generates int64 (the column type) rather
694 // than int32 (the type the +1 literal would default to).
695 func (q *Queries) NextRunIndexForRepo(ctx context.Context, db DBTX, repoID int64) (int64, error) {
696 row := db.QueryRow(ctx, nextRunIndexForRepo, repoID)
697 var next_index int64
698 err := row.Scan(&next_index)
699 return next_index, err
700 }
701