CREATE TABLE IF NOT EXISTS "merge_queue_entries" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"repository_id" uuid NOT NULL,
"pull_request_id" uuid NOT NULL,
"base_branch" text NOT NULL,
"state" text NOT NULL DEFAULT 'queued',
"position" integer NOT NULL DEFAULT 0,
"enqueued_by" uuid,
"enqueued_at" timestamp DEFAULT now() NOT NULL,
"started_at" timestamp,
"finished_at" timestamp,
"error_message" text,
CONSTRAINT "merge_queue_entries_repo_fk" FOREIGN KEY ("repository_id") REFERENCES "repositories"("id") ON DELETE cascade,
CONSTRAINT "merge_queue_entries_pr_fk" FOREIGN KEY ("pull_request_id") REFERENCES "pull_requests"("id") ON DELETE cascade,
CONSTRAINT "merge_queue_entries_enqueuer_fk" FOREIGN KEY ("enqueued_by") REFERENCES "users"("id")
);
CREATE INDEX IF NOT EXISTS "merge_queue_repo_branch" ON "merge_queue_entries" ("repository_id", "base_branch", "state");
CREATE UNIQUE INDEX IF NOT EXISTS "merge_queue_pr_active" ON "merge_queue_entries" ("pull_request_id") WHERE state IN ('queued', 'running');
|