| 1 | -- SPDX-License-Identifier: AGPL-3.0-or-later |
| 2 | -- |
| 3 | -- repo_collaborators stores per-(repo, user) role grants beyond the |
| 4 | -- owner. The five roles mirror GitHub's: |
| 5 | -- |
| 6 | -- read — clone/fetch a private repo, view issues/pulls |
| 7 | -- triage — read + manage issue state (close, label, assign) |
| 8 | -- write — triage + push, branch create, PR create |
| 9 | -- maintain — write + most settings except dangerous ones |
| 10 | -- admin — maintain + delete/transfer/visibility |
| 11 | -- |
| 12 | -- The owner is implicit (effectively `admin` for the purposes of policy) |
| 13 | -- and is not stored here; the owner column on `repos` is the source of |
| 14 | -- truth. A row in this table for the owner would be redundant. |
| 15 | -- |
| 16 | -- Org-team grants live in a separate table (S31). The policy package |
| 17 | -- merges both sources when evaluating an action. |
| 18 | |
| 19 | -- +goose Up |
| 20 | CREATE TYPE collab_role AS ENUM ('read', 'triage', 'write', 'maintain', 'admin'); |
| 21 | |
| 22 | CREATE TABLE repo_collaborators ( |
| 23 | repo_id bigint NOT NULL REFERENCES repos(id) ON DELETE CASCADE, |
| 24 | user_id bigint NOT NULL REFERENCES users(id) ON DELETE CASCADE, |
| 25 | role collab_role NOT NULL, |
| 26 | added_at timestamptz NOT NULL DEFAULT now(), |
| 27 | added_by_user_id bigint REFERENCES users(id) ON DELETE SET NULL, |
| 28 | |
| 29 | PRIMARY KEY (repo_id, user_id) |
| 30 | ); |
| 31 | |
| 32 | CREATE INDEX repo_collaborators_user_id_idx ON repo_collaborators (user_id); |
| 33 | CREATE INDEX repo_collaborators_repo_id_idx ON repo_collaborators (repo_id); |
| 34 | |
| 35 | -- +goose Down |
| 36 | DROP TABLE IF EXISTS repo_collaborators; |
| 37 | DROP TYPE IF EXISTS collab_role; |
| 38 |