CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
Blame · Line-by-line history
0004_org_owned_repos.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.
| 7437605 | 1 | -- Gluecron migration 0004: Block B2 — repositories can be owned by an org. |
| 2 | -- Adds repositories.org_id (nullable) + partial unique indexes so a user and | |
| 3 | -- an org can each have a repo named "web" without collision, but two orgs | |
| 4 | -- (or two users) still cannot. | |
| 5 | ||
| 6 | --> statement-breakpoint | |
| 7 | ALTER TABLE "repositories" ADD COLUMN IF NOT EXISTS "org_id" uuid; | |
| 8 | ||
| 9 | --> statement-breakpoint | |
| 10 | ALTER TABLE "repositories" | |
| 11 | DROP CONSTRAINT IF EXISTS "repositories_org_id_fk"; | |
| 12 | ||
| 13 | --> statement-breakpoint | |
| 14 | ALTER TABLE "repositories" | |
| 15 | ADD CONSTRAINT "repositories_org_id_fk" | |
| 16 | FOREIGN KEY ("org_id") REFERENCES "organizations"("id") ON DELETE CASCADE; | |
| 17 | ||
| 18 | --> statement-breakpoint | |
| 19 | -- Existing unique index was on (owner_id, name) across all rows. That would | |
| 20 | -- block the same user from creating a personal "web" AND an org-owned "web" | |
| 21 | -- where they happen to be the listed creator. Make it partial so it only | |
| 22 | -- enforces uniqueness within the user namespace. | |
| 23 | DROP INDEX IF EXISTS "repos_owner_name"; | |
| 24 | ||
| 25 | --> statement-breakpoint | |
| 26 | CREATE UNIQUE INDEX IF NOT EXISTS "repos_owner_name" | |
| 27 | ON "repositories" ("owner_id", "name") | |
| 28 | WHERE "org_id" IS NULL; | |
| 29 | ||
| 30 | --> statement-breakpoint | |
| 31 | CREATE UNIQUE INDEX IF NOT EXISTS "repos_org_name" | |
| 32 | ON "repositories" ("org_id", "name") | |
| 33 | WHERE "org_id" IS NOT NULL; | |
| 34 | ||
| 35 | --> statement-breakpoint | |
| 36 | CREATE INDEX IF NOT EXISTS "repos_org" ON "repositories" ("org_id"); |