-
-
Notifications
You must be signed in to change notification settings - Fork 367
Expand file tree
/
Copy pathschema.prisma
More file actions
524 lines (464 loc) · 14.6 KB
/
schema.prisma
File metadata and controls
524 lines (464 loc) · 14.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
// 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"
previewFeatures = []
}
datasource db {
provider = "postgresql"
// NOTE: When using mysql or sqlserver, uncomment the @db.Text annotations in model Account below
// Further reading:
// https://next-auth.js.org/adapters/prisma#create-the-prisma-schema
// https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#string
url = env("DATABASE_URL")
}
model AppSetting {
key String @id
value String
}
model SesSetting {
id String @id @default(cuid())
region String @unique
idPrefix String @unique
topic String
topicArn String?
transactionalQuota Int @default(50)
callbackUrl String
callbackSuccess Boolean @default(false)
configGeneral String?
configGeneralSuccess Boolean @default(false)
configClick String?
configClickSuccess Boolean @default(false)
configOpen String?
configOpenSuccess Boolean @default(false)
configFull String?
configFullSuccess Boolean @default(false)
sesEmailRateLimit Int @default(1)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
// Necessary for Next auth
model Account {
id String @id @default(cuid())
userId Int
type String
provider String
providerAccountId String
refresh_token String? // @db.Text
access_token String? // @db.Text
refresh_token_expires_in Int?
expires_at Int?
token_type String?
scope String?
id_token String? // @db.Text
session_state String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([provider, providerAccountId])
}
model Session {
id String @id @default(cuid())
sessionToken String @unique
userId Int
expires DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}
model VerificationToken {
identifier String
token String @unique
expires DateTime
@@unique([identifier, token])
}
model User {
id Int @id @default(autoincrement())
name String?
email String? @unique
emailVerified DateTime?
image String?
isBetaUser Boolean @default(false)
isWaitlisted Boolean @default(false)
createdAt DateTime @default(now())
accounts Account[]
sessions Session[]
teamUsers TeamUser[]
webhookEndpoints Webhook[]
}
enum Plan {
FREE
BASIC
}
model Team {
id Int @id @default(autoincrement())
name String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
plan Plan @default(FREE)
stripeCustomerId String? @unique
isActive Boolean @default(true)
apiRateLimit Int @default(2)
billingEmail String?
sesTenantId String?
isVerified Boolean @default(false)
dailyEmailLimit Int @default(10000)
isBlocked Boolean @default(false)
teamUsers TeamUser[]
domains Domain[]
apiKeys ApiKey[]
emails Email[]
contactBooks ContactBook[]
campaigns Campaign[]
templates Template[]
dailyEmailUsages DailyEmailUsage[]
subscription Subscription[]
invites TeamInvite[]
suppressionList SuppressionList[]
webhookEndpoints Webhook[]
webhookCalls WebhookCall[]
}
model TeamInvite {
id String @id @default(cuid())
teamId Int
email String
role Role
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
@@unique([teamId, email])
}
model Subscription {
id String @id
teamId Int
status String
priceId String
priceIds String[]
currentPeriodEnd DateTime?
currentPeriodStart DateTime?
cancelAtPeriodEnd DateTime?
paymentMethod String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
}
enum Role {
ADMIN
MEMBER
}
model TeamUser {
teamId Int
userId Int
role Role
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([teamId, userId])
}
enum DomainStatus {
NOT_STARTED
PENDING
SUCCESS
FAILED
TEMPORARY_FAILURE
}
model Domain {
id Int @id @default(autoincrement())
name String @unique
teamId Int
status DomainStatus @default(PENDING)
region String @default("us-east-1")
clickTracking Boolean @default(false)
openTracking Boolean @default(false)
publicKey String
dkimSelector String? @default("usesend")
dkimStatus String?
spfDetails String?
dmarcAdded Boolean @default(false)
errorMessage String?
subdomain String?
sesTenantId String?
isVerifying Boolean @default(false)
/// Self-hosted: custom hostname for SES click/open tracking (e.g. track.example.com). Requires DNS + verification in SES.
customTrackingHostname String? @unique
customTrackingPublicKey String?
customTrackingDkimSelector String? @default("utrack")
customTrackingDkimStatus String?
customTrackingStatus DomainStatus @default(NOT_STARTED)
trackingConfigGeneral String?
trackingConfigClick String?
trackingConfigOpen String?
trackingConfigFull String?
/// Self-hosted: when true, SES uses HTTPS for tracking links (REQUIRE). Needs valid TLS on the tracking hostname (e.g. Cloudflare proxy). When false, OPTIONAL (HTTP allowed; CNAME-only to awstrack).
trackingHttpsRequired Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
apiKeys ApiKey[]
}
enum ApiPermission {
FULL
SENDING
}
model ApiKey {
id Int @id @default(autoincrement())
clientId String @unique
tokenHash String
partialToken String
name String
permission ApiPermission @default(SENDING)
domainId Int?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
lastUsed DateTime?
teamId Int
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
domain Domain? @relation(fields: [domainId], references: [id], onDelete: SetNull, onUpdate: Cascade)
}
enum EmailStatus {
SCHEDULED
QUEUED
SENT
DELIVERY_DELAYED
BOUNCED
REJECTED
RENDERING_FAILURE
DELIVERED
OPENED
CLICKED
COMPLAINED
FAILED
CANCELLED
SUPPRESSED
}
model Email {
id String @id @default(cuid())
sesEmailId String? @unique
from String
to String[]
replyTo String[]
cc String[]
bcc String[]
subject String
text String?
html String?
latestStatus EmailStatus @default(QUEUED)
teamId Int
domainId Int?
apiId Int?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
scheduledAt DateTime?
attachments String?
campaignId String?
contactId String?
inReplyToId String?
headers String?
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
emailEvents EmailEvent[]
@@index([campaignId, contactId])
@@index([createdAt(sort: Desc)])
}
model CampaignEmail {
campaignId String
contactId String
emailId String
createdAt DateTime @default(now())
@@id([campaignId, contactId])
}
model EmailEvent {
id String @id @default(cuid())
emailId String
status EmailStatus
data Json?
teamId Int?
createdAt DateTime @default(now())
email Email @relation(fields: [emailId], references: [id], onDelete: Cascade)
@@index([emailId])
@@index([teamId])
}
model ContactBook {
id String @id @default(cuid())
name String
teamId Int
variables String[] @default([])
properties Json
doubleOptInEnabled Boolean @default(false)
doubleOptInFrom String?
doubleOptInSubject String?
doubleOptInContent String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
emoji String @default("📙")
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
contacts Contact[]
@@index([teamId])
}
enum UnsubscribeReason {
BOUNCED
COMPLAINED
UNSUBSCRIBED
}
enum SuppressionReason {
HARD_BOUNCE
COMPLAINT
MANUAL
}
model Contact {
id String @id @default(cuid())
firstName String?
lastName String?
email String
subscribed Boolean @default(true)
unsubscribeReason UnsubscribeReason?
properties Json
contactBookId String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
contactBook ContactBook @relation(fields: [contactBookId], references: [id], onDelete: Cascade)
@@unique([contactBookId, email])
@@index([contactBookId, id])
}
enum CampaignStatus {
DRAFT
SCHEDULED
RUNNING
PAUSED
SENT
}
model Campaign {
id String @id @default(cuid())
name String
teamId Int
from String
cc String[]
bcc String[]
replyTo String[]
domainId Int
subject String
previewText String?
html String?
content String?
contactBookId String?
scheduledAt DateTime?
total Int @default(0)
sent Int @default(0)
delivered Int @default(0)
opened Int @default(0)
clicked Int @default(0)
unsubscribed Int @default(0)
bounced Int @default(0)
hardBounced Int @default(0)
complained Int @default(0)
isApi Boolean @default(false)
status CampaignStatus @default(DRAFT)
batchSize Int @default(500)
batchWindowMinutes Int @default(0)
lastCursor String?
lastSentAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
@@index([createdAt(sort: Desc)])
@@index([status, scheduledAt])
}
model Template {
id String @id @default(cuid())
name String
teamId Int
subject String
html String?
content String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
@@index([createdAt(sort: Desc)])
}
enum EmailUsageType {
TRANSACTIONAL
MARKETING
}
model DailyEmailUsage {
teamId Int
date String
type EmailUsageType
domainId Int
sent Int @default(0)
delivered Int @default(0)
opened Int @default(0)
clicked Int @default(0)
bounced Int @default(0)
complained Int @default(0)
hardBounced Int @default(0)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
@@id([teamId, domainId, date, type])
}
model CumulatedMetrics {
teamId Int
domainId Int
delivered BigInt @default(0)
hardBounced BigInt @default(0)
complained BigInt @default(0)
@@id([teamId, domainId])
}
model SuppressionList {
id String @id @default(cuid())
email String // The suppressed email address
teamId Int // Team that owns this suppression
reason SuppressionReason // Why it was suppressed
source String? // Source email ID that triggered suppression
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
@@unique([teamId, email])
}
enum WebhookStatus {
ACTIVE
PAUSED
AUTO_DISABLED
}
enum WebhookCallStatus {
PENDING
IN_PROGRESS
DELIVERED
FAILED
DISCARDED
}
model Webhook {
id String @id @default(cuid())
teamId Int
domainIds Int[] @default([])
url String
description String?
secret String
status WebhookStatus @default(ACTIVE)
eventTypes String[]
apiVersion String?
consecutiveFailures Int @default(0)
lastFailureAt DateTime?
lastSuccessAt DateTime?
createdByUserId Int?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
calls WebhookCall[]
createdBy User? @relation(fields: [createdByUserId], references: [id], onDelete: SetNull)
@@index([teamId])
}
model WebhookCall {
id String @id @default(cuid())
webhookId String
teamId Int
type String
payload String
status WebhookCallStatus @default(PENDING)
attempt Int @default(0)
nextAttemptAt DateTime?
lastError String?
responseStatus Int?
responseTimeMs Int?
responseText String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
webhook Webhook @relation(fields: [webhookId], references: [id], onDelete: Cascade)
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
@@index([teamId, webhookId, status])
@@index([createdAt(sort: Desc)])
}