-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathschema.prisma
More file actions
798 lines (600 loc) · 19.6 KB
/
schema.prisma
File metadata and controls
798 lines (600 loc) · 19.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgres"
url = env("DATABASE_URL")
shadowDatabaseUrl = env("SHADOW_DATABASE_URL")
relationMode = "foreignKeys"
}
enum GitProvider {
GITHUB
}
enum InstallationTargetType {
ORGANIZATION
USER
}
enum PullRequestState {
DRAFT
OPEN
CLOSED
MERGED
}
enum PullRequestSize {
TINY
SMALL
MEDIUM
LARGE
HUGE
}
enum CodeReviewState {
APPROVED
CHANGES_REQUESTED
COMMENTED
}
enum TeamMemberRole {
DESIGNER
ENGINEER
LEADER
MANAGER
PRODUCT
QA
}
enum IntegrationApp {
SLACK
}
enum AutomationType {
PR_TITLE_CHECK
PR_SIZE_LABELER
INCIDENT_DETECTION
}
enum DigestType {
TEAM_METRICS
TEAM_WIP
}
enum AlertType {
SLOW_REVIEW
SLOW_MERGE
MERGED_WITHOUT_APPROVAL
HOT_PR
UNRELEASED_CHANGES
}
enum DayOfTheWeek {
SUNDAY
MONDAY
TUESDAY
WEDNESDAY
THURSDAY
FRIDAY
SATURDAY
}
enum Frequency {
WEEKLY
MONTHLY
}
enum ActivityEventType {
CODE_REVIEW_SUBMITTED
PULL_REQUEST_MERGED
PULL_REQUEST_CREATED
}
enum DeploymentChangeType {
FORWARD
ROLLBACK
BASELINE
DIVERGED
NO_CHANGE
}
// User git profiles. Public data. May not have an associated user.
model GitProfile {
id Int @id @default(autoincrement())
gitProvider GitProvider
gitUserId String
handle String
name String
avatar String?
workspaceMemberships WorkspaceMembership[]
user User? @relation(fields: [userId], references: [id])
userId Int?
// A single user might have multiple git profiles, with multiple personal workspaces.
workspace Workspace?
pullRequests PullRequest[]
teamMemberships TeamMember[]
codeReviews CodeReview[]
codeReviewRequests CodeReviewRequest[]
activityEvents ActivityEvent[]
apiKeys ApiKey[]
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
Deployment Deployment[]
Incident Incident[]
@@unique([gitProvider, gitUserId])
@@unique([gitProvider, userId])
@@index([userId])
}
// A person that has authorized GitHub OAuth
model User {
id Int @id @default(autoincrement())
slug String @unique
email String @unique
gitProfiles GitProfile[]
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
}
// An org that has authorized GitHub OAuth
model Organization {
id Int @id @default(autoincrement())
gitProvider GitProvider
gitOrganizationId String
name String
handle String
avatar String?
workspace Workspace?
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@unique([gitProvider, gitOrganizationId])
}
model Workspace {
id Int @id @default(autoincrement())
gitProvider GitProvider
settings Json @default("{}")
trialEndAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
featureAdoption Json @default("{}")
subscription Subscription?
installation Installation?
// A workspace can belong either to an Organization or an User
organization Organization? @relation(fields: [organizationId], references: [id], onDelete: Cascade)
organizationId Int?
// A personal workspace can become orphan when an user revokes their OAuth
// Re-authenticating creates a new user and reconnects
gitProfile GitProfile? @relation(fields: [gitProfileId], references: [id], onDelete: SetNull)
gitProfileId Int?
memberships WorkspaceMembership[]
repositories Repository[]
teams Team[]
automations Automation[]
codeReviews CodeReview[]
codeReviewRequests CodeReviewRequest[]
pullRequestTrackings PullRequestTracking[]
pullRequests PullRequest[]
teamMembers TeamMember[]
integrations Integration[]
digests Digest[]
alerts Alert[]
alertEvents AlertEvent[]
activityEvents ActivityEvent[]
apiKeys ApiKey[]
syncTasks SyncBatch[]
applications Application[]
deployments Deployment[]
deploymentPullRequests DeploymentPullRequest[]
Environment Environment[]
Incident Incident[]
@@unique([gitProfileId])
@@unique([organizationId])
}
// ---------------------------------------------------------------------------------------
// Workspace Scope (RLS-Enabled)
// |- Add workspaceId in all tables below to ensure query performance and data isolation.
// |- When adding new models, create a migration to activate RLS for the new tables.
// ---------------------------------------------------------------------------------------
model Subscription {
id Int @id @default(autoincrement())
workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
workspaceId Int @unique
// Stripe data
customerId String
subscriptionId String @unique
priceId String
status String
interval String
quantity Int
currentPeriodStart DateTime
currentPeriodEnd DateTime
startedAt DateTime
object Json
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
}
model Installation {
id Int @id @default(autoincrement())
gitInstallationId String @unique
gitProvider GitProvider
targetId String
targetType InstallationTargetType
repositorySelection String
permissions Json
events Json
suspendedAt DateTime?
workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
workspaceId Int
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@unique([workspaceId])
}
model SyncBatch {
id Int @id @default(autoincrement())
sinceDaysAgo Int
scheduledAt DateTime
startedAt DateTime?
finishedAt DateTime?
metadata Json
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
workspaceId Int
@@index([workspaceId])
}
model WorkspaceMembership {
id Int @id @default(autoincrement())
gitProfile GitProfile @relation(fields: [gitProfileId], references: [id], onDelete: Cascade)
gitProfileId Int
workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
workspaceId Int
role String?
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@unique([gitProfileId, workspaceId])
@@index([workspaceId])
}
model Repository {
id Int @id @default(autoincrement())
gitProvider GitProvider
gitRepositoryId String
name String
fullName String
description String?
isPrivate Boolean
isFork Boolean
isMirror Boolean
archivedAt DateTime?
starCount Int
createdAt DateTime
workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
workspaceId Int
updatedAt DateTime @default(now()) @updatedAt
pullRequests PullRequest[]
activityEvents ActivityEvent[]
applications Application[]
@@unique([gitProvider, gitRepositoryId])
@@index([workspaceId])
}
model ActivityEvent {
id Int @id @default(autoincrement())
type ActivityEventType
metadata Json
eventId String?
eventAt DateTime @default(now())
gitProfile GitProfile @relation(fields: [gitProfileId], references: [id], onDelete: Cascade)
gitProfileId Int
workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
workspaceId Int
pullRequest PullRequest? @relation(fields: [pullRequestId], references: [id], onDelete: Cascade)
pullRequestId Int?
repository Repository? @relation(fields: [repositoryId], references: [id], onDelete: Cascade)
repositoryId Int?
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@unique([workspaceId, eventId])
@@index([workspaceId])
@@index([gitProfileId])
@@index([pullRequestId])
@@index([repositoryId])
}
model PullRequest {
id Int @id @default(autoincrement())
gitProvider GitProvider
gitPullRequestId String
gitUrl String
title String
number String
sourceBranch String @default("")
targetBranch String @default("main")
body String @default("")
labels Json @default("[]")
files Json @default("[]")
commentCount Int
changedFilesCount Int
linesAddedCount Int
linesDeletedCount Int
state PullRequestState
mergeCommitSha String?
mergedAt DateTime?
closedAt DateTime?
createdAt DateTime
updatedAt DateTime
repository Repository @relation(fields: [repositoryId], references: [id], onDelete: Cascade)
repositoryId Int
author GitProfile @relation(fields: [authorId], references: [id], onDelete: Cascade)
authorId Int
tracking PullRequestTracking?
workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
workspaceId Int
codeReviews CodeReview[]
codeReviewRequests CodeReviewRequest[]
alertEvents AlertEvent[]
activityEvents ActivityEvent[]
deploymentEvents DeploymentPullRequest[]
@@unique([gitProvider, gitPullRequestId])
@@index([workspaceId])
@@index([repositoryId])
@@index([authorId])
}
model PullRequestTracking {
id Int @id @default(autoincrement())
// When tracking, we ignore files that doesn't matter for PR size (i.e. lock files)
changedFilesCount Int @default(0)
linesAddedCount Int @default(0)
linesDeletedCount Int @default(0)
size PullRequestSize
firstCommitAt DateTime?
firstDraftedAt DateTime?
firstReadyAt DateTime? // Ready for review, i.e. open
firstReviewerRequestedAt DateTime?
firstReviewAt DateTime?
firstApprovalAt DateTime?
firstDeployedAt DateTime?
timeToCode BigInt?
timeToFirstReview BigInt?
timeToFirstApproval BigInt?
timeToMerge BigInt?
timeToDeploy BigInt?
cycleTime BigInt?
pullRequest PullRequest @relation(fields: [pullRequestId], references: [id], onDelete: Cascade)
pullRequestId Int
workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
workspaceId Int
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@unique([pullRequestId])
@@index([workspaceId])
}
model CodeReview {
id Int @id @default(autoincrement())
commentCount Int
state CodeReviewState
createdAt DateTime
pullRequest PullRequest @relation(fields: [pullRequestId], references: [id], onDelete: Cascade)
pullRequestId Int
author GitProfile @relation(fields: [authorId], references: [id], onDelete: Cascade)
authorId Int
workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
workspaceId Int
updatedAt DateTime @default(now()) @updatedAt
@@unique([pullRequestId, authorId])
@@index([workspaceId])
@@index([authorId])
}
model CodeReviewRequest {
id Int @id @default(autoincrement())
createdAt DateTime
deletedAt DateTime?
pullRequest PullRequest @relation(fields: [pullRequestId], references: [id], onDelete: Cascade)
pullRequestId Int
reviewer GitProfile @relation(fields: [reviewerId], references: [id], onDelete: Cascade)
reviewerId Int
workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
workspaceId Int
updatedAt DateTime @default(now()) @updatedAt
@@unique([pullRequestId, reviewerId])
@@index([workspaceId])
@@index([reviewerId])
}
model Team {
id Int @id @default(autoincrement())
name String
description String?
icon String
startColor String
endColor String
members TeamMember[]
archivedAt DateTime?
workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
workspaceId Int
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
Digest Digest[]
Alert Alert[]
Incident Incident[]
Application Application[]
@@unique([workspaceId, name])
}
model TeamMember {
id Int @id @default(autoincrement())
role TeamMemberRole
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
teamId Int
gitProfile GitProfile @relation(fields: [gitProfileId], references: [id])
gitProfileId Int
workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
workspaceId Int
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@index([workspaceId])
@@index([gitProfileId])
@@index([teamId])
}
model Digest {
id Int @id @default(autoincrement())
type DigestType
enabled Boolean
channel String
frequency Frequency
dayOfTheWeek DayOfTheWeek[]
timeOfDay String
timezone String
settings Json
teamId Int
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
workspaceId Int
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@unique([teamId, type])
@@index([workspaceId])
}
model Alert {
id Int @id @default(autoincrement())
type AlertType
enabled Boolean
channel String
settings Json
teamId Int
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
workspaceId Int
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
AlertEvent AlertEvent[]
@@unique([teamId, type])
@@index([workspaceId])
}
model AlertEvent {
id Int @id @default(autoincrement())
alertId Int
alert Alert @relation(fields: [alertId], references: [id], onDelete: Cascade)
pullRequest PullRequest @relation(fields: [pullRequestId], references: [id], onDelete: Cascade)
pullRequestId Int
workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
workspaceId Int
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@index([workspaceId])
@@index([pullRequestId])
@@index([alertId])
}
model Automation {
id Int @id @default(autoincrement())
type AutomationType
enabled Boolean
settings Json
workspaceId Int
workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@unique([workspaceId, type])
}
model Integration {
id Int @id @default(autoincrement())
workspaceId Int
app IntegrationApp
data Json
workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@unique([workspaceId, app])
}
model ApiKey {
id Int @id @default(autoincrement())
key String @unique
name String
lastUsedAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
workspaceId Int
creatorId Int
creator GitProfile @relation(fields: [creatorId], references: [id], onDelete: Cascade)
@@index([workspaceId])
@@index([creatorId])
}
model Environment {
id Int @id @default(autoincrement())
name String
deployments Deployment[]
isProduction Boolean
workspaceId Int
workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
archivedAt DateTime?
@@unique([workspaceId, name])
}
model Application {
id Int @id @default(autoincrement())
name String
description String?
repositoryId Int
repository Repository @relation(fields: [repositoryId], references: [id], onDelete: Cascade)
teamId Int?
team Team? @relation(fields: [teamId], references: [id], onDelete: Cascade)
deploymentSettings Json
workspaceId Int
workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
deployments Deployment[]
archivedAt DateTime?
@@unique([workspaceId, name])
@@index([repositoryId])
@@index([teamId])
}
model Deployment {
id Int @id @default(autoincrement())
applicationId Int
application Application @relation(fields: [applicationId], references: [id], onDelete: Cascade)
version String
commitHash String
description String?
changeType DeploymentChangeType?
environmentId Int
environment Environment @relation(fields: [environmentId], references: [id], onDelete: Cascade)
author GitProfile? @relation(fields: [authorId], references: [id], onDelete: Cascade)
authorId Int?
deployedAt DateTime
pullRequests DeploymentPullRequest[]
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
workspaceId Int
workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
causedIncidents Incident[] @relation(name: "CauseDeployment")
fixedIncidents Incident[] @relation(name: "FixDeployment")
archivedAt DateTime?
@@unique([workspaceId, environmentId, applicationId, version, deployedAt])
@@index([applicationId])
@@index([environmentId])
@@index([authorId])
@@index([workspaceId, deployedAt])
}
model Incident {
id Int @id @default(autoincrement())
teamId Int?
team Team? @relation(fields: [teamId], references: [id], onDelete: SetNull)
leaderId Int?
leader GitProfile? @relation(fields: [leaderId], references: [id], onDelete: SetNull)
detectedAt DateTime
resolvedAt DateTime?
causeDeploymentId Int
causeDeployment Deployment @relation("CauseDeployment", fields: [causeDeploymentId], references: [id], onDelete: Cascade)
fixDeploymentId Int?
fixDeployment Deployment? @relation("FixDeployment", fields: [fixDeploymentId], references: [id], onDelete: SetNull)
postmortemUrl String?
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
workspaceId Int
workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
archivedAt DateTime?
@@unique([workspaceId, causeDeploymentId])
@@index([causeDeploymentId])
@@index([fixDeploymentId])
@@index([teamId])
@@index([leaderId])
@@index([workspaceId, detectedAt])
}
model DeploymentPullRequest {
id Int @id @default(autoincrement())
deploymentId Int
deployment Deployment @relation(fields: [deploymentId], references: [id], onDelete: Cascade)
pullRequestId Int
pullRequest PullRequest @relation(fields: [pullRequestId], references: [id], onDelete: Cascade)
workspaceId Int
workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@unique([deploymentId, pullRequestId])
@@index([pullRequestId])
@@index([workspaceId])
}