CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
Blame · Line-by-line history
0035_repo_collaborators.sql
Each line is annotated with the commit that last touched it. Click any SHA to jump to that commit and see the surrounding change.
| 23d1a81 | 1 | -- Collaborators — per-repo role grants (read / write / admin). |
| 2 | -- | |
| 3 | -- A user granted access to a repository beyond ownership. Roles are | |
| 4 | -- hierarchical: admin implies write, write implies read. `invited_by` tracks | |
| 5 | -- who added them (nulled once that user is deleted); `accepted_at` is null | |
| 6 | -- until the invitee explicitly accepts. Unique per (repo, user) so a given | |
| 7 | -- user has at most one role per repo. | |
| 8 | ||
| 9 | CREATE TABLE IF NOT EXISTS "repo_collaborators" ( | |
| 10 | "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, | |
| 11 | "repository_id" uuid NOT NULL REFERENCES "repositories"("id") ON DELETE CASCADE, | |
| 12 | "user_id" uuid NOT NULL REFERENCES "users"("id") ON DELETE CASCADE, | |
| 13 | "role" text NOT NULL DEFAULT 'read' CHECK (role IN ('read', 'write', 'admin')), | |
| 14 | "invited_by" uuid REFERENCES "users"("id") ON DELETE SET NULL, | |
| 15 | "invited_at" timestamp NOT NULL DEFAULT now(), | |
| 16 | "accepted_at" timestamp | |
| 17 | ); | |
| 18 | ||
| 19 | --> statement-breakpoint | |
| 20 | ||
| 21 | CREATE UNIQUE INDEX IF NOT EXISTS "repo_collaborators_repo_user_uq" | |
| 22 | ON "repo_collaborators" ("repository_id", "user_id"); | |
| 23 | ||
| 24 | --> statement-breakpoint | |
| 25 | ||
| 26 | CREATE INDEX IF NOT EXISTS "repo_collaborators_repo_idx" | |
| 27 | ON "repo_collaborators" ("repository_id"); | |
| 28 | ||
| 29 | --> statement-breakpoint | |
| 30 | ||
| 31 | CREATE INDEX IF NOT EXISTS "repo_collaborators_user_idx" | |
| 32 | ON "repo_collaborators" ("user_id"); |