-
Notifications
You must be signed in to change notification settings - Fork 514
Expand file tree
/
Copy pathschema.prisma
More file actions
911 lines (699 loc) · 25 KB
/
schema.prisma
File metadata and controls
911 lines (699 loc) · 25 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
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
generator client {
provider = "prisma-client-js"
previewFeatures = ["driverAdapters", "relationJoins"]
}
datasource db {
provider = "postgresql"
url = env("STACK_DATABASE_CONNECTION_STRING")
directUrl = env("STACK_DIRECT_DATABASE_CONNECTION_STRING")
}
model SchemaMigration {
id String @id @default(dbgenerated("gen_random_uuid()"))
finishedAt DateTime
migrationName String @unique
@@ignore
}
model Project {
// Note that the project with ID `internal` is handled as a special case. All other project IDs are UUIDs.
id String @id
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
displayName String
description String @default("")
isProductionMode Boolean
ownerTeamId String? @db.Uuid
logoUrl String?
logoFullUrl String?
logoDarkModeUrl String?
logoFullDarkModeUrl String?
projectConfigOverride Json?
stripeAccountId String?
apiKeySets ApiKeySet[]
projectUsers ProjectUser[]
provisionedProject ProvisionedProject?
tenancies Tenancy[]
environmentConfigOverrides EnvironmentConfigOverride[]
}
model Tenancy {
id String @id @default(uuid()) @db.Uuid
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
projectId String
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
branchId String
// If organizationId is NULL, hasNoOrganization must be TRUE. If organizationId is not NULL, hasNoOrganization must be NULL.
organizationId String? @db.Uuid
hasNoOrganization BooleanTrue?
@@unique([projectId, branchId, organizationId])
@@unique([projectId, branchId, hasNoOrganization])
}
model EnvironmentConfigOverride {
projectId String
branchId String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
config Json
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
@@id([projectId, branchId])
}
model Team {
tenancyId String @db.Uuid
teamId String @default(uuid()) @db.Uuid
// Team IDs must be unique across all organizations (but not necessarily across all branches).
// To model this in the DB, we add two columns that are always equal to tenancy.projectId and tenancy.branchId.
mirroredProjectId String
mirroredBranchId String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
displayName String
clientMetadata Json?
clientReadOnlyMetadata Json?
serverMetadata Json?
profileImageUrl String?
teamMembers TeamMember[]
projectApiKey ProjectApiKey[]
@@id([tenancyId, teamId])
@@unique([mirroredProjectId, mirroredBranchId, teamId])
}
// This is used for fields that are boolean but only the true value is part of a unique constraint.
// For example if you want to allow only one selected team per user, you can make an optional field with this type and add a unique constraint.
// Only the true value is considered for the unique constraint, the null value is not.
enum BooleanTrue {
TRUE
}
model TeamMember {
tenancyId String @db.Uuid
projectUserId String @db.Uuid
teamId String @db.Uuid
// This will override the displayName of the user in this team.
displayName String?
profileImageUrl String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
projectUser ProjectUser @relation(fields: [tenancyId, projectUserId], references: [tenancyId, projectUserId], onDelete: Cascade)
team Team @relation(fields: [tenancyId, teamId], references: [tenancyId, teamId], onDelete: Cascade)
isSelected BooleanTrue?
teamMemberDirectPermissions TeamMemberDirectPermission[]
@@id([tenancyId, projectUserId, teamId])
@@unique([tenancyId, projectUserId, isSelected])
}
model ProjectUserDirectPermission {
id String @id @default(uuid()) @db.Uuid
tenancyId String @db.Uuid
projectUserId String @db.Uuid
permissionId String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
projectUser ProjectUser @relation(fields: [tenancyId, projectUserId], references: [tenancyId, projectUserId], onDelete: Cascade)
@@unique([tenancyId, projectUserId, permissionId])
}
model TeamMemberDirectPermission {
id String @id @default(uuid()) @db.Uuid
tenancyId String @db.Uuid
projectUserId String @db.Uuid
teamId String @db.Uuid
permissionId String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
teamMember TeamMember @relation(fields: [tenancyId, projectUserId, teamId], references: [tenancyId, projectUserId, teamId], onDelete: Cascade)
@@unique([tenancyId, projectUserId, teamId, permissionId])
}
model ProjectUser {
tenancyId String @db.Uuid
projectUserId String @default(uuid()) @db.Uuid
// User IDs must be unique across all organizations (but not necessarily across all branches).
// To model this in the DB, we add two columns that are always equal to tenancy.projectId and tenancy.branchId.
mirroredProjectId String
mirroredBranchId String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
sequenceId BigInt? @unique
shouldUpdateSequenceId Boolean @default(true)
displayName String?
serverMetadata Json?
clientReadOnlyMetadata Json?
clientMetadata Json?
profileImageUrl String?
requiresTotpMfa Boolean @default(false)
totpSecret Bytes?
isAnonymous Boolean @default(false)
projectUserOAuthAccounts ProjectUserOAuthAccount[]
teamMembers TeamMember[]
contactChannels ContactChannel[]
authMethods AuthMethod[]
// some backlinks for the unique constraints on some auth methods
passwordAuthMethod PasswordAuthMethod[]
passkeyAuthMethod PasskeyAuthMethod[]
otpAuthMethod OtpAuthMethod[]
oauthAuthMethod OAuthAuthMethod[]
SentEmail SentEmail[]
projectApiKey ProjectApiKey[]
directPermissions ProjectUserDirectPermission[]
Project Project? @relation(fields: [projectId], references: [id])
projectId String?
userNotificationPreference UserNotificationPreference[]
@@id([tenancyId, projectUserId])
@@unique([mirroredProjectId, mirroredBranchId, projectUserId])
// indices for sorting and filtering
@@index([tenancyId, displayName(sort: Asc)], name: "ProjectUser_displayName_asc")
@@index([tenancyId, displayName(sort: Desc)], name: "ProjectUser_displayName_desc")
@@index([tenancyId, createdAt(sort: Asc)], name: "ProjectUser_createdAt_asc")
@@index([tenancyId, createdAt(sort: Desc)], name: "ProjectUser_createdAt_desc")
}
// This should be renamed to "OAuthAccount" as it is not always bound to a user
// When ever a user goes through the OAuth flow and gets an account ID from the OAuth provider, we store that here.
model ProjectUserOAuthAccount {
id String @default(uuid()) @db.Uuid
tenancyId String @db.Uuid
projectUserId String? @db.Uuid
configOAuthProviderId String
providerAccountId String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
// This is used for the user to distinguish between multiple accounts from the same provider.
// we might want to add more user info here later
email String?
// Before the OAuth account is connected to a user (for example, in the link oauth process), the projectUser is null.
projectUser ProjectUser? @relation(fields: [tenancyId, projectUserId], references: [tenancyId, projectUserId], onDelete: Cascade)
oauthTokens OAuthToken[]
oauthAccessToken OAuthAccessToken[]
// if allowSignIn is true, oauthAuthMethod must be set
oauthAuthMethod OAuthAuthMethod?
allowConnectedAccounts Boolean @default(true)
allowSignIn Boolean @default(true)
@@id([tenancyId, id])
@@unique([tenancyId, configOAuthProviderId, projectUserId, providerAccountId])
@@index([tenancyId, projectUserId])
}
enum ContactChannelType {
EMAIL
// PHONE
}
model ContactChannel {
tenancyId String @db.Uuid
projectUserId String @db.Uuid
id String @default(uuid()) @db.Uuid
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
sequenceId BigInt? @unique
shouldUpdateSequenceId Boolean @default(true)
type ContactChannelType
isPrimary BooleanTrue?
usedForAuth BooleanTrue?
isVerified Boolean
value String
projectUser ProjectUser @relation(fields: [tenancyId, projectUserId], references: [tenancyId, projectUserId], onDelete: Cascade)
@@id([tenancyId, projectUserId, id])
// each user has at most one primary contact channel of each type
@@unique([tenancyId, projectUserId, type, isPrimary])
// value must be unique per user per type
@@unique([tenancyId, projectUserId, type, value])
// only one contact channel per project with the same value and type can be used for auth
@@unique([tenancyId, type, value, usedForAuth])
}
model AuthMethod {
tenancyId String @db.Uuid
id String @default(uuid()) @db.Uuid
projectUserId String @db.Uuid
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
// exactly one of the xyzAuthMethods should be set
otpAuthMethod OtpAuthMethod?
passwordAuthMethod PasswordAuthMethod?
passkeyAuthMethod PasskeyAuthMethod?
oauthAuthMethod OAuthAuthMethod?
projectUser ProjectUser @relation(fields: [tenancyId, projectUserId], references: [tenancyId, projectUserId], onDelete: Cascade)
@@id([tenancyId, id])
@@index([tenancyId, projectUserId])
}
model OtpAuthMethod {
tenancyId String @db.Uuid
authMethodId String @db.Uuid
projectUserId String @db.Uuid
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
authMethod AuthMethod @relation(fields: [tenancyId, authMethodId], references: [tenancyId, id], onDelete: Cascade)
projectUser ProjectUser @relation(fields: [tenancyId, projectUserId], references: [tenancyId, projectUserId], onDelete: Cascade)
@@id([tenancyId, authMethodId])
// a user can only have one OTP auth method
@@unique([tenancyId, projectUserId])
}
model PasswordAuthMethod {
tenancyId String @db.Uuid
authMethodId String @db.Uuid
projectUserId String @db.Uuid
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
passwordHash String
authMethod AuthMethod @relation(fields: [tenancyId, authMethodId], references: [tenancyId, id], onDelete: Cascade)
projectUser ProjectUser @relation(fields: [tenancyId, projectUserId], references: [tenancyId, projectUserId], onDelete: Cascade)
@@id([tenancyId, authMethodId])
// a user can only have one password auth method
@@unique([tenancyId, projectUserId])
}
model PasskeyAuthMethod {
tenancyId String @db.Uuid
authMethodId String @db.Uuid
projectUserId String @db.Uuid
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
credentialId String
publicKey String
userHandle String
transports String[]
credentialDeviceType String
counter Int
authMethod AuthMethod @relation(fields: [tenancyId, authMethodId], references: [tenancyId, id], onDelete: Cascade)
projectUser ProjectUser @relation(fields: [tenancyId, projectUserId], references: [tenancyId, projectUserId], onDelete: Cascade)
@@id([tenancyId, authMethodId])
// a user can only have one password auth method
@@unique([tenancyId, projectUserId])
}
// This connects to projectUserOauthAccount, which might be shared between auth method and connected account.
model OAuthAuthMethod {
tenancyId String @db.Uuid
authMethodId String @db.Uuid
configOAuthProviderId String
providerAccountId String
projectUserId String @db.Uuid
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
authMethod AuthMethod @relation(fields: [tenancyId, authMethodId], references: [tenancyId, id], onDelete: Cascade)
oauthAccount ProjectUserOAuthAccount @relation(fields: [tenancyId, configOAuthProviderId, projectUserId, providerAccountId], references: [tenancyId, configOAuthProviderId, projectUserId, providerAccountId])
projectUser ProjectUser @relation(fields: [tenancyId, projectUserId], references: [tenancyId, projectUserId], onDelete: Cascade)
@@id([tenancyId, authMethodId])
@@unique([tenancyId, configOAuthProviderId, providerAccountId])
@@unique([tenancyId, projectUserId, configOAuthProviderId])
@@unique([tenancyId, configOAuthProviderId, projectUserId, providerAccountId])
}
enum StandardOAuthProviderType {
GITHUB
FACEBOOK
GOOGLE
MICROSOFT
SPOTIFY
DISCORD
GITLAB
BITBUCKET
LINKEDIN
APPLE
X
TWITCH
}
model OAuthToken {
id String @id @default(uuid()) @db.Uuid
tenancyId String @db.Uuid
oauthAccountId String @db.Uuid
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
projectUserOAuthAccount ProjectUserOAuthAccount @relation(fields: [tenancyId, oauthAccountId], references: [tenancyId, id], onDelete: Cascade)
refreshToken String
scopes String[]
isValid Boolean @default(true)
}
model OAuthAccessToken {
id String @id @default(uuid()) @db.Uuid
tenancyId String @db.Uuid
oauthAccountId String @db.Uuid
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
projectUserOAuthAccount ProjectUserOAuthAccount @relation(fields: [tenancyId, oauthAccountId], references: [tenancyId, id], onDelete: Cascade)
accessToken String
scopes String[]
expiresAt DateTime
isValid Boolean @default(true)
}
model OAuthOuterInfo {
id String @id @default(uuid()) @db.Uuid
info Json
innerState String @unique
expiresAt DateTime
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model ProjectUserRefreshToken {
id String @default(uuid()) @db.Uuid
tenancyId String @db.Uuid
projectUserId String @db.Uuid
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
refreshToken String @unique
expiresAt DateTime?
isImpersonation Boolean @default(false)
@@id([tenancyId, id])
}
model ProjectUserAuthorizationCode {
tenancyId String @db.Uuid
projectUserId String @db.Uuid
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
authorizationCode String @unique
redirectUri String
expiresAt DateTime
codeChallenge String
codeChallengeMethod String
newUser Boolean
afterCallbackRedirectUrl String?
@@id([tenancyId, authorizationCode])
}
model VerificationCode {
projectId String
branchId String
id String @default(uuid()) @db.Uuid
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
type VerificationCodeType
code String
expiresAt DateTime
usedAt DateTime?
redirectUrl String?
method Json @default("null")
data Json
attemptCount Int @default(0)
@@id([projectId, branchId, id])
@@unique([projectId, branchId, code])
@@index([data(ops: JsonbPathOps)], type: Gin)
}
enum VerificationCodeType {
ONE_TIME_PASSWORD
PASSWORD_RESET
CONTACT_CHANNEL_VERIFICATION
TEAM_INVITATION
MFA_ATTEMPT
PASSKEY_REGISTRATION_CHALLENGE
PASSKEY_AUTHENTICATION_CHALLENGE
INTEGRATION_PROJECT_TRANSFER
PURCHASE_URL
}
//#region API keys
// Internal API keys
model ApiKeySet {
projectId String
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
id String @default(uuid()) @db.Uuid
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
description String
expiresAt DateTime
manuallyRevokedAt DateTime?
publishableClientKey String? @unique
secretServerKey String? @unique
superSecretAdminKey String? @unique
@@id([projectId, id])
}
//#endregion
model ProjectApiKey {
tenancyId String @db.Uuid
id String @default(uuid()) @db.Uuid
secretApiKey String @unique
// Validity and revocation
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
expiresAt DateTime?
manuallyRevokedAt DateTime?
description String
isPublic Boolean
// exactly one of [teamId] or [projectUserId] must be set
teamId String? @db.Uuid
projectUserId String? @db.Uuid
projectUser ProjectUser? @relation(fields: [tenancyId, projectUserId], references: [tenancyId, projectUserId], onDelete: Cascade)
team Team? @relation(fields: [tenancyId, teamId], references: [tenancyId, teamId], onDelete: Cascade)
@@id([tenancyId, id])
}
enum EmailTemplateType {
EMAIL_VERIFICATION
PASSWORD_RESET
MAGIC_LINK
TEAM_INVITATION
SIGN_IN_INVITATION
}
model EmailTemplate {
projectId String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
content Json
type EmailTemplateType
subject String
@@id([projectId, type])
}
//#region IdP
model IdPAccountToCdfcResultMapping {
idpId String
id String
idpAccountId String @unique @db.Uuid
cdfcResult Json
@@id([idpId, id])
}
model ProjectWrapperCodes {
idpId String
id String @default(uuid()) @db.Uuid
interactionUid String
authorizationCode String @unique
cdfcResult Json
@@id([idpId, id])
}
model IdPAdapterData {
idpId String
model String
id String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
payload Json
expiresAt DateTime
@@id([idpId, model, id])
@@index([payload(ops: JsonbPathOps)], type: Gin)
@@index([expiresAt])
}
//#endregion
model ProvisionedProject {
projectId String @id
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
clientId String
}
//#region Events
model Event {
id String @id @default(uuid()) @db.Uuid
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
// if isWide == false, then eventEndedAt is always equal to eventStartedAt
isWide Boolean
eventStartedAt DateTime
eventEndedAt DateTime
// TODO: add event_type, and at least one of either system_event_type or event_type is always set
systemEventTypeIds String[]
data Json
// ============================== BEGIN END USER PROPERTIES ==============================
// Below are properties describing the end user that caused this event to be logged
// This is different from a request IP. See: apps/backend/src/lib/end-users.tsx
// Note that the IP may have been spoofed, unless isEndUserIpInfoGuessTrusted is true
endUserIpInfoGuessId String? @db.Uuid
endUserIpInfoGuess EventIpInfo? @relation("EventIpInfo", fields: [endUserIpInfoGuessId], references: [id])
// If true, then endUserIpInfoGuess is not spoofed (might still be behind VPNs/proxies). If false, then the values may be spoofed.
isEndUserIpInfoGuessTrusted Boolean @default(false)
// =============================== END END USER PROPERTIES ===============================
@@index([data(ops: JsonbPathOps)], type: Gin)
}
// An IP address that was seen in an event. Use the location fields instead of refetching the location from the ip, as the real-world geoip data may have changed since the event was logged.
model EventIpInfo {
id String @id @default(uuid()) @db.Uuid
ip String
countryCode String?
regionCode String?
cityName String?
latitude Float?
longitude Float?
tzIdentifier String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
events Event[] @relation("EventIpInfo")
}
//#endregion
model SentEmail {
tenancyId String @db.Uuid
id String @default(uuid()) @db.Uuid
userId String? @db.Uuid
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
senderConfig Json
to String[]
subject String
html String?
text String?
error Json?
user ProjectUser? @relation(fields: [tenancyId, userId], references: [tenancyId, projectUserId], onDelete: Cascade)
@@id([tenancyId, id])
}
model EmailDraft {
tenancyId String @db.Uuid
id String @default(uuid()) @db.Uuid
displayName String
themeMode DraftThemeMode @default(PROJECT_DEFAULT)
themeId String?
tsxSource String
sentAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@id([tenancyId, id])
}
enum DraftThemeMode {
PROJECT_DEFAULT
NONE
CUSTOM
}
model CliAuthAttempt {
tenancyId String @db.Uuid
id String @default(uuid()) @db.Uuid
pollingCode String @unique
loginCode String @unique
refreshToken String?
expiresAt DateTime
usedAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@id([tenancyId, id])
}
model UserNotificationPreference {
id String @default(uuid()) @db.Uuid
tenancyId String @db.Uuid
projectUserId String @db.Uuid
notificationCategoryId String @db.Uuid
enabled Boolean
projectUser ProjectUser @relation(fields: [tenancyId, projectUserId], references: [tenancyId, projectUserId], onDelete: Cascade)
@@id([tenancyId, id])
@@unique([tenancyId, projectUserId, notificationCategoryId])
}
model ThreadMessage {
id String @default(uuid()) @db.Uuid
tenancyId String @db.Uuid
threadId String @db.Uuid
content Json
createdAt DateTime @default(now())
@@id([tenancyId, id])
}
enum CustomerType {
USER
TEAM
CUSTOM
}
enum SubscriptionStatus {
active
trialing
canceled
paused
incomplete
incomplete_expired
past_due
unpaid
}
enum PurchaseCreationSource {
PURCHASE_PAGE
TEST_MODE
API_GRANT
}
model Subscription {
id String @default(uuid()) @db.Uuid
tenancyId String @db.Uuid
customerId String
customerType CustomerType
productId String?
priceId String?
product Json
quantity Int @default(1)
stripeSubscriptionId String?
status SubscriptionStatus
currentPeriodEnd DateTime
currentPeriodStart DateTime
cancelAtPeriodEnd Boolean
refundedAt DateTime?
creationSource PurchaseCreationSource
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
SubscriptionInvoices SubscriptionInvoice[]
@@id([tenancyId, id])
@@unique([tenancyId, stripeSubscriptionId])
}
model ItemQuantityChange {
id String @default(uuid()) @db.Uuid
tenancyId String @db.Uuid
customerId String
customerType CustomerType
itemId String
quantity Int
description String?
expiresAt DateTime?
createdAt DateTime @default(now())
@@id([tenancyId, id])
@@index([tenancyId, customerId, expiresAt])
}
model OneTimePurchase {
id String @default(uuid()) @db.Uuid
tenancyId String @db.Uuid
customerId String
customerType CustomerType
productId String?
priceId String?
product Json
quantity Int
stripePaymentIntentId String?
createdAt DateTime @default(now())
refundedAt DateTime?
creationSource PurchaseCreationSource
@@id([tenancyId, id])
@@unique([tenancyId, stripePaymentIntentId])
}
model DataVaultEntry {
id String @default(uuid()) @db.Uuid
tenancyId String @db.Uuid
storeId String
hashedKey String
encrypted Json // Contains { edkBase64, ciphertextBase64 } from encryptWithKms()
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@id([tenancyId, id])
@@unique([tenancyId, storeId, hashedKey])
@@index([tenancyId, storeId])
}
model CacheEntry {
id String @id @default(uuid()) @db.Uuid
namespace String
cacheKey String
payload Json
expiresAt DateTime
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([namespace, cacheKey])
}
model SubscriptionInvoice {
id String @default(uuid()) @db.Uuid
tenancyId String @db.Uuid
stripeSubscriptionId String
stripeInvoiceId String
isSubscriptionCreationInvoice Boolean
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
subscription Subscription @relation(fields: [tenancyId, stripeSubscriptionId], references: [tenancyId, stripeSubscriptionId])
@@id([tenancyId, id])
@@unique([tenancyId, stripeInvoiceId])
}
model OutgoingRequest {
id String @id @default(uuid()) @db.Uuid
createdAt DateTime @default(now())
qstashOptions Json
fulfilledAt DateTime?
@@index([fulfilledAt])
}
model DeletedRow {
id String @id @default(uuid()) @db.Uuid
tenancyId String @db.Uuid
tableName String
sequenceId BigInt? @unique
shouldUpdateSequenceId Boolean @default(true)
primaryKey Json
data Json?
deletedAt DateTime @default(now())
fulfilledAt DateTime?
@@index([tableName])
@@index([tenancyId])
}