| 1 | CREATE TYPE "public"."pull_request_state" AS ENUM('open', 'closed', 'merged');--> statement-breakpoint |
| 2 | CREATE TABLE "pull_request" ( |
| 3 | "id" text PRIMARY KEY NOT NULL, |
| 4 | "number" integer NOT NULL, |
| 5 | "title" text NOT NULL, |
| 6 | "body" text, |
| 7 | "state" "pull_request_state" DEFAULT 'open' NOT NULL, |
| 8 | "baseRepositoryId" text NOT NULL, |
| 9 | "baseRef" text NOT NULL, |
| 10 | "headRepositoryId" text NOT NULL, |
| 11 | "headRef" text NOT NULL, |
| 12 | "headSha" text NOT NULL, |
| 13 | "mergeCommitSha" text, |
| 14 | "authorId" text NOT NULL, |
| 15 | "closedAt" timestamp, |
| 16 | "mergedAt" timestamp, |
| 17 | "createdAt" timestamp DEFAULT now() NOT NULL, |
| 18 | "updatedAt" timestamp DEFAULT now() NOT NULL, |
| 19 | CONSTRAINT "pull_request_id_unique" UNIQUE("id") |
| 20 | ); |
| 21 | --> statement-breakpoint |
| 22 | ALTER TABLE "pull_request" ADD CONSTRAINT "pull_request_baseRepositoryId_repository_id_fk" FOREIGN KEY ("baseRepositoryId") REFERENCES "public"."repository"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint |
| 23 | ALTER TABLE "pull_request" ADD CONSTRAINT "pull_request_headRepositoryId_repository_id_fk" FOREIGN KEY ("headRepositoryId") REFERENCES "public"."repository"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint |
| 24 | ALTER TABLE "pull_request" ADD CONSTRAINT "pull_request_authorId_user_id_fk" FOREIGN KEY ("authorId") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint |
| 25 | CREATE UNIQUE INDEX "pull_request_base_number_idx" ON "pull_request" USING btree ("baseRepositoryId","number");--> statement-breakpoint |
| 26 | CREATE UNIQUE INDEX "pull_request_open_branch_idx" ON "pull_request" USING btree ("baseRepositoryId","baseRef","headRepositoryId","headRef") WHERE "pull_request"."state" = 'open';--> statement-breakpoint |
| 27 | CREATE INDEX "pull_request_head_idx" ON "pull_request" USING btree ("headRepositoryId");--> statement-breakpoint |
| 28 | CREATE INDEX "pull_request_base_state_idx" ON "pull_request" USING btree ("baseRepositoryId","state"); |