| 1 | -- SPDX-License-Identifier: AGPL-3.0-or-later |
| 2 | |
| 3 | -- name: IsWorkflowDisabled :one |
| 4 | -- Hot path for trigger.Enqueue: skip enqueueing when the row exists. |
| 5 | SELECT EXISTS ( |
| 6 | SELECT 1 FROM workflow_disabled |
| 7 | WHERE repo_id = $1 AND workflow_file = $2 |
| 8 | ) AS disabled; |
| 9 | |
| 10 | -- name: ListDisabledWorkflowsForRepo :many |
| 11 | -- Used by the workflows-list endpoint to mark `state: "disabled"` |
| 12 | -- entries without round-tripping through Is for every file. |
| 13 | SELECT workflow_file |
| 14 | FROM workflow_disabled |
| 15 | WHERE repo_id = $1 |
| 16 | ORDER BY workflow_file; |
| 17 | |
| 18 | -- name: DisableWorkflow :exec |
| 19 | -- Idempotent: re-disabling an already-disabled workflow is a no-op |
| 20 | -- and does not bump disabled_at. |
| 21 | INSERT INTO workflow_disabled (repo_id, workflow_file, disabled_by_user_id) |
| 22 | VALUES ($1, $2, sqlc.narg(disabled_by_user_id)::bigint) |
| 23 | ON CONFLICT (repo_id, workflow_file) DO NOTHING; |
| 24 | |
| 25 | -- name: EnableWorkflow :execrows |
| 26 | -- Returns affected-rows so the handler can distinguish 200 (re-enabled) |
| 27 | -- from 404-ish no-op. |
| 28 | DELETE FROM workflow_disabled |
| 29 | WHERE repo_id = $1 AND workflow_file = $2; |
| 30 |