Skip to content

Commit 97508b5

Browse files
committed
Add schemas for gh app installations
1 parent ddbae6b commit 97508b5

File tree

3 files changed

+155
-3
lines changed

3 files changed

+155
-3
lines changed
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: 2 additions & 2 deletions
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)
3-
provider = "postgresql"
2+
# It should be added in your version-control system (e.g., Git)
3+
provider = "postgresql"

internal-packages/database/prisma/schema.prisma

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ model OrganizationAccessToken {
151151
/// This is used to find the token in the database
152152
hashedToken String @unique
153153
154-
organization Organization @relation(fields: [organizationId], references: [id])
154+
organization Organization @relation(fields: [organizationId], references: [id])
155155
organizationId String
156156
157157
/// Optional expiration date for the token
@@ -210,6 +210,7 @@ model Organization {
210210
workerGroups WorkerInstanceGroup[]
211211
workerInstances WorkerInstance[]
212212
executionSnapshots TaskRunExecutionSnapshot[]
213+
githubAppInstallations GithubAppInstallation[]
213214
}
214215

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

0 commit comments

Comments
 (0)