MySQL · 1221 bytes Raw Blame History
1 -- SPDX-License-Identifier: AGPL-3.0-or-later
2 --
3 -- Query surface for the policy package. The policy code reads roles to
4 -- decide; admin/settings UIs (S32) write through these as well.
5
6 -- name: GetCollabRole :one
7 -- Returns the collaborator role for (repo_id, user_id), or pgx.ErrNoRows
8 -- when the user is not a collaborator on this repo.
9 SELECT role FROM repo_collaborators
10 WHERE repo_id = $1 AND user_id = $2;
11
12 -- name: UpsertCollabRole :exec
13 -- Insert or upgrade a collaborator's role. added_by_user_id records who
14 -- granted the role for the audit trail.
15 INSERT INTO repo_collaborators (repo_id, user_id, role, added_by_user_id)
16 VALUES ($1, $2, $3, sqlc.narg(added_by_user_id)::bigint)
17 ON CONFLICT (repo_id, user_id)
18 DO UPDATE SET role = EXCLUDED.role,
19 added_by_user_id = EXCLUDED.added_by_user_id;
20
21 -- name: RemoveCollab :exec
22 DELETE FROM repo_collaborators WHERE repo_id = $1 AND user_id = $2;
23
24 -- name: ListCollabs :many
25 -- Used by the repo settings page (S32) and tests.
26 SELECT rc.repo_id, rc.user_id, rc.role, rc.added_at,
27 u.username AS username, u.display_name AS display_name
28 FROM repo_collaborators rc
29 JOIN users u ON u.id = rc.user_id
30 WHERE rc.repo_id = $1
31 ORDER BY rc.added_at DESC;
32