Skip to content

Commit db2d4b8

Browse files
committed
Create schema and migration for organization access tokens
1 parent cd6a0b3 commit db2d4b8

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
CREATE TABLE "OrganizationAccessToken" (
2+
"id" TEXT NOT NULL,
3+
"name" TEXT NOT NULL,
4+
"encryptedToken" JSONB NOT NULL,
5+
"obfuscatedToken" TEXT NOT NULL,
6+
"hashedToken" TEXT NOT NULL,
7+
"organizationId" TEXT NOT NULL,
8+
"expiresAt" TIMESTAMP(3),
9+
"revokedAt" TIMESTAMP(3),
10+
"lastAccessedAt" TIMESTAMP(3),
11+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
12+
"updatedAt" TIMESTAMP(3) NOT NULL,
13+
14+
CONSTRAINT "OrganizationAccessToken_pkey" PRIMARY KEY ("id")
15+
);
16+
17+
CREATE UNIQUE INDEX "OrganizationAccessToken_hashedToken_key" ON "OrganizationAccessToken"("hashedToken");
18+
19+
ALTER TABLE "OrganizationAccessToken" ADD CONSTRAINT "OrganizationAccessToken_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

internal-packages/database/prisma/schema.prisma

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,33 @@ model PersonalAccessToken {
133133
authorizationCodes AuthorizationCode[]
134134
}
135135

136+
model OrganizationAccessToken {
137+
id String @id @default(cuid())
138+
139+
/// User-provided name for the token
140+
name String
141+
142+
/// This is the token encrypted using the ENCRYPTION_KEY
143+
encryptedToken Json
144+
145+
/// This is shown in the UI, with ********
146+
obfuscatedToken String
147+
148+
/// This is used to find the token in the database
149+
hashedToken String @unique
150+
151+
organization Organization @relation(fields: [organizationId], references: [id])
152+
organizationId String
153+
154+
/// Optional expiration date for the token
155+
expiresAt DateTime?
156+
revokedAt DateTime?
157+
lastAccessedAt DateTime?
158+
159+
createdAt DateTime @default(now())
160+
updatedAt DateTime @updatedAt
161+
}
162+
136163
model Organization {
137164
id String @id @default(cuid())
138165
slug String @unique
@@ -174,6 +201,7 @@ model Organization {
174201
members OrgMember[]
175202
invites OrgMemberInvite[]
176203
organizationIntegrations OrganizationIntegration[]
204+
organizationAccessTokens OrganizationAccessToken[]
177205
workerGroups WorkerInstanceGroup[]
178206
workerInstances WorkerInstance[]
179207
executionSnapshots TaskRunExecutionSnapshot[]

0 commit comments

Comments
 (0)