| 1 | CREATE TABLE "organization_pinned_repository" ( |
| 2 | "organizationId" text NOT NULL, |
| 3 | "repositoryId" text NOT NULL, |
| 4 | "position" integer NOT NULL, |
| 5 | CONSTRAINT "organization_pinned_repository_organizationId_repositoryId_pk" PRIMARY KEY("organizationId","repositoryId") |
| 6 | ); |
| 7 | --> statement-breakpoint |
| 8 | CREATE TABLE "organization_public_member" ( |
| 9 | "organizationId" text NOT NULL, |
| 10 | "userId" text NOT NULL, |
| 11 | CONSTRAINT "organization_public_member_organizationId_userId_pk" PRIMARY KEY("organizationId","userId") |
| 12 | ); |
| 13 | --> statement-breakpoint |
| 14 | CREATE TABLE "organization_settings" ( |
| 15 | "organizationId" text PRIMARY KEY NOT NULL, |
| 16 | "basePermission" "repository_role" DEFAULT 'read', |
| 17 | "membersCanCreatePublicRepositories" boolean DEFAULT true NOT NULL, |
| 18 | "membersCanCreatePrivateRepositories" boolean DEFAULT true NOT NULL, |
| 19 | "allowPrivateForks" boolean DEFAULT false NOT NULL, |
| 20 | "defaultBranch" text, |
| 21 | "description" text, |
| 22 | "website" text, |
| 23 | "location" text, |
| 24 | "email" text, |
| 25 | "updatedAt" timestamp with time zone DEFAULT now() NOT NULL |
| 26 | ); |
| 27 | --> statement-breakpoint |
| 28 | CREATE TABLE "repository_redirect" ( |
| 29 | "ownerName" text NOT NULL, |
| 30 | "slug" text NOT NULL, |
| 31 | "repositoryId" text NOT NULL, |
| 32 | "createdAt" timestamp with time zone DEFAULT now() NOT NULL |
| 33 | ); |
| 34 | --> statement-breakpoint |
| 35 | CREATE TABLE "repository_transfer" ( |
| 36 | "repositoryId" text PRIMARY KEY NOT NULL, |
| 37 | "toUserId" text, |
| 38 | "toOrganizationId" text, |
| 39 | "requestedById" text, |
| 40 | "createdAt" timestamp with time zone DEFAULT now() NOT NULL |
| 41 | ); |
| 42 | --> statement-breakpoint |
| 43 | CREATE TABLE "team_maintainer" ( |
| 44 | "teamId" text NOT NULL, |
| 45 | "userId" text NOT NULL, |
| 46 | CONSTRAINT "team_maintainer_teamId_userId_pk" PRIMARY KEY("teamId","userId") |
| 47 | ); |
| 48 | --> statement-breakpoint |
| 49 | ALTER TABLE "organization_pinned_repository" ADD CONSTRAINT "organization_pinned_repository_organizationId_organization_id_fk" FOREIGN KEY ("organizationId") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint |
| 50 | ALTER TABLE "organization_pinned_repository" ADD CONSTRAINT "organization_pinned_repository_repositoryId_repository_id_fk" FOREIGN KEY ("repositoryId") REFERENCES "public"."repository"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint |
| 51 | ALTER TABLE "organization_public_member" ADD CONSTRAINT "organization_public_member_organizationId_organization_id_fk" FOREIGN KEY ("organizationId") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint |
| 52 | ALTER TABLE "organization_public_member" ADD CONSTRAINT "organization_public_member_userId_user_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint |
| 53 | ALTER TABLE "organization_settings" ADD CONSTRAINT "organization_settings_organizationId_organization_id_fk" FOREIGN KEY ("organizationId") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint |
| 54 | ALTER TABLE "repository_redirect" ADD CONSTRAINT "repository_redirect_repositoryId_repository_id_fk" FOREIGN KEY ("repositoryId") REFERENCES "public"."repository"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint |
| 55 | ALTER TABLE "repository_transfer" ADD CONSTRAINT "repository_transfer_repositoryId_repository_id_fk" FOREIGN KEY ("repositoryId") REFERENCES "public"."repository"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint |
| 56 | ALTER TABLE "repository_transfer" ADD CONSTRAINT "repository_transfer_toUserId_user_id_fk" FOREIGN KEY ("toUserId") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint |
| 57 | ALTER TABLE "repository_transfer" ADD CONSTRAINT "repository_transfer_toOrganizationId_organization_id_fk" FOREIGN KEY ("toOrganizationId") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint |
| 58 | ALTER TABLE "repository_transfer" ADD CONSTRAINT "repository_transfer_requestedById_user_id_fk" FOREIGN KEY ("requestedById") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint |
| 59 | ALTER TABLE "team_maintainer" ADD CONSTRAINT "team_maintainer_teamId_team_id_fk" FOREIGN KEY ("teamId") REFERENCES "public"."team"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint |
| 60 | ALTER TABLE "team_maintainer" ADD CONSTRAINT "team_maintainer_userId_user_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint |
| 61 | CREATE UNIQUE INDEX "repository_redirect_name_idx" ON "repository_redirect" USING btree (lower("ownerName"),"slug");--> statement-breakpoint |
| 62 | CREATE INDEX "repository_redirect_repository_idx" ON "repository_redirect" USING btree ("repositoryId");--> statement-breakpoint |
| 63 | -- Every existing organization gets its settings row, with the defaults a new one would have. |
| 64 | INSERT INTO "organization_settings" ("organizationId") SELECT "id" FROM "organization" ON CONFLICT DO NOTHING;--> statement-breakpoint |
| 65 | -- Organization roles are now member, admin and owner; repository access moved to the base permission. |
| 66 | UPDATE "member" SET "role" = 'member' WHERE "role" NOT IN ('owner', 'admin');--> statement-breakpoint |
| 67 | UPDATE "invitation" SET "role" = 'member' WHERE "role" IS NOT NULL AND "role" NOT IN ('owner', 'admin'); |