Skip to content

Commit 8f83bcc

Browse files
committed
Add schemas for gh app installations
1 parent 9b1877b commit 8f83bcc

3 files changed

Lines changed: 153 additions & 1 deletion

File tree

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
-- CreateEnum
2+
CREATE TYPE "public"."GithubRepositorySelection" AS ENUM ('ALL', 'SELECTED');
3+
4+
-- DropIndex
5+
DROP INDEX "public"."SecretStore_key_idx";
6+
7+
-- DropIndex
8+
DROP INDEX "public"."TaskRun_runtimeEnvironmentId_createdAt_idx";
9+
10+
-- DropIndex
11+
DROP INDEX "public"."TaskRun_runtimeEnvironmentId_id_idx";
12+
13+
-- AlterTable
14+
ALTER TABLE "public"."_BackgroundWorkerToBackgroundWorkerFile" ADD CONSTRAINT "_BackgroundWorkerToBackgroundWorkerFile_AB_pkey" PRIMARY KEY ("A", "B");
15+
16+
-- DropIndex
17+
DROP INDEX "public"."_BackgroundWorkerToBackgroundWorkerFile_AB_unique";
18+
19+
-- AlterTable
20+
ALTER TABLE "public"."_BackgroundWorkerToTaskQueue" ADD CONSTRAINT "_BackgroundWorkerToTaskQueue_AB_pkey" PRIMARY KEY ("A", "B");
21+
22+
-- DropIndex
23+
DROP INDEX "public"."_BackgroundWorkerToTaskQueue_AB_unique";
24+
25+
-- AlterTable
26+
ALTER TABLE "public"."_TaskRunToTaskRunTag" ADD CONSTRAINT "_TaskRunToTaskRunTag_AB_pkey" PRIMARY KEY ("A", "B");
27+
28+
-- DropIndex
29+
DROP INDEX "public"."_TaskRunToTaskRunTag_AB_unique";
30+
31+
-- AlterTable
32+
ALTER TABLE "public"."_WaitpointRunConnections" ADD CONSTRAINT "_WaitpointRunConnections_AB_pkey" PRIMARY KEY ("A", "B");
33+
34+
-- DropIndex
35+
DROP INDEX "public"."_WaitpointRunConnections_AB_unique";
36+
37+
-- AlterTable
38+
ALTER TABLE "public"."_completedWaitpoints" ADD CONSTRAINT "_completedWaitpoints_AB_pkey" PRIMARY KEY ("A", "B");
39+
40+
-- DropIndex
41+
DROP INDEX "public"."_completedWaitpoints_AB_unique";
42+
43+
-- CreateTable
44+
CREATE TABLE "public"."GithubAppInstallation" (
45+
"id" TEXT NOT NULL,
46+
"appInstallationId" INTEGER NOT NULL,
47+
"targetId" INTEGER NOT NULL,
48+
"targetType" TEXT NOT NULL,
49+
"permissions" JSONB,
50+
"repositorySelection" "public"."GithubRepositorySelection" NOT NULL,
51+
"installedBy" TEXT,
52+
"organizationId" TEXT NOT NULL,
53+
"deletedAt" TIMESTAMP(3),
54+
"suspendedAt" TIMESTAMP(3),
55+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
56+
"updatedAt" TIMESTAMP(3) NOT NULL,
57+
58+
CONSTRAINT "GithubAppInstallation_pkey" PRIMARY KEY ("id")
59+
);
60+
61+
-- CreateTable
62+
CREATE TABLE "public"."GithubRepository" (
63+
"id" TEXT NOT NULL,
64+
"githubId" INTEGER NOT NULL,
65+
"name" TEXT NOT NULL,
66+
"fullName" TEXT NOT NULL,
67+
"htmlUrl" TEXT NOT NULL,
68+
"private" BOOLEAN NOT NULL,
69+
"removedAt" TIMESTAMP(3),
70+
"installationId" TEXT NOT NULL,
71+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
72+
"updatedAt" TIMESTAMP(3) NOT NULL,
73+
74+
CONSTRAINT "GithubRepository_pkey" PRIMARY KEY ("id")
75+
);
76+
77+
-- CreateIndex
78+
CREATE UNIQUE INDEX "GithubAppInstallation_appInstallationId_key" ON "public"."GithubAppInstallation"("appInstallationId");
79+
80+
-- CreateIndex
81+
CREATE INDEX "GithubAppInstallation_organizationId_idx" ON "public"."GithubAppInstallation"("organizationId");
82+
83+
-- CreateIndex
84+
CREATE INDEX "GithubRepository_installationId_idx" ON "public"."GithubRepository"("installationId");
85+
86+
-- CreateIndex
87+
CREATE UNIQUE INDEX "GithubRepository_installationId_githubId_key" ON "public"."GithubRepository"("installationId", "githubId");
88+
89+
-- CreateIndex
90+
CREATE INDEX "SecretStore_key_idx" ON "public"."SecretStore"("key" text_pattern_ops);
91+
92+
-- CreateIndex
93+
CREATE INDEX "TaskRun_runtimeEnvironmentId_id_idx" ON "public"."TaskRun"("runtimeEnvironmentId", "id" DESC);
94+
95+
-- CreateIndex
96+
CREATE INDEX "TaskRun_runtimeEnvironmentId_createdAt_idx" ON "public"."TaskRun"("runtimeEnvironmentId", "createdAt" DESC);
97+
98+
-- AddForeignKey
99+
ALTER TABLE "public"."GithubAppInstallation" ADD CONSTRAINT "GithubAppInstallation_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "public"."Organization"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
100+
101+
-- AddForeignKey
102+
ALTER TABLE "public"."GithubRepository" ADD CONSTRAINT "GithubRepository_installationId_fkey" FOREIGN KEY ("installationId") REFERENCES "public"."GithubAppInstallation"("id") ON DELETE CASCADE ON UPDATE CASCADE;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Please do not edit this file manually
2-
# It should be added in your version-control system (i.e. Git)
2+
# It should be added in your version-control system (e.g., Git)
33
provider = "postgresql"

internal-packages/database/prisma/schema.prisma

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ model Organization {
210210
workerGroups WorkerInstanceGroup[]
211211
workerInstances WorkerInstance[]
212212
executionSnapshots TaskRunExecutionSnapshot[]
213+
githubAppInstallations GithubAppInstallation[]
213214
}
214215

215216
model OrgMember {
@@ -2238,3 +2239,52 @@ model TaskEventPartitioned {
22382239
// Used for getting all logs for a run
22392240
@@index([runId])
22402241
}
2242+
2243+
enum GithubRepositorySelection {
2244+
ALL
2245+
SELECTED
2246+
}
2247+
2248+
model GithubAppInstallation {
2249+
id String @id @default(cuid())
2250+
2251+
appInstallationId Int @unique
2252+
targetId Int
2253+
targetType String
2254+
permissions Json?
2255+
repositorySelection GithubRepositorySelection
2256+
installedBy String?
2257+
2258+
organization Organization @relation(fields: [organizationId], references: [id])
2259+
organizationId String
2260+
2261+
repositories GithubRepository[]
2262+
2263+
deletedAt DateTime?
2264+
suspendedAt DateTime?
2265+
createdAt DateTime @default(now())
2266+
updatedAt DateTime @updatedAt
2267+
2268+
@@index([organizationId])
2269+
}
2270+
2271+
model GithubRepository {
2272+
id String @id @default(cuid())
2273+
2274+
githubId Int
2275+
name String
2276+
fullName String
2277+
htmlUrl String
2278+
private Boolean
2279+
2280+
removedAt DateTime?
2281+
2282+
installation GithubAppInstallation @relation(fields: [installationId], references: [id], onDelete: Cascade, onUpdate: Cascade)
2283+
installationId String
2284+
2285+
createdAt DateTime @default(now())
2286+
updatedAt DateTime @updatedAt
2287+
2288+
@@unique([installationId, githubId])
2289+
@@index([installationId])
2290+
}

0 commit comments

Comments
 (0)