* Add self host setup * Improve blunders * Move to bull mq * More changes * Add example code for sending test emails
206 lines
5.3 KiB
Plaintext
206 lines
5.3 KiB
Plaintext
// 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 = "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
|
|
topic String
|
|
topicArn String?
|
|
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)
|
|
accounts Account[]
|
|
sessions Session[]
|
|
teamUsers TeamUser[]
|
|
}
|
|
|
|
model Team {
|
|
id Int @id @default(autoincrement())
|
|
name String
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
teamUsers TeamUser[]
|
|
domains Domain[]
|
|
apiKeys ApiKey[]
|
|
emails Email[]
|
|
}
|
|
|
|
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
|
|
dkimStatus String?
|
|
spfDetails String?
|
|
dmarcAdded Boolean @default(false)
|
|
errorMessage String?
|
|
subdomain String?
|
|
isVerifying Boolean @default(false)
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
|
|
}
|
|
|
|
enum ApiPermission {
|
|
FULL
|
|
SENDING
|
|
}
|
|
|
|
model ApiKey {
|
|
id Int @id @default(autoincrement())
|
|
tokenHash String @unique
|
|
partialToken String
|
|
name String
|
|
permission ApiPermission @default(SENDING)
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
lastUsed DateTime?
|
|
teamId Int
|
|
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
|
|
}
|
|
|
|
enum EmailStatus {
|
|
QUEUED
|
|
SENT
|
|
BOUNCED
|
|
DELIVERED
|
|
OPENED
|
|
CLICKED
|
|
COMPLAINED
|
|
REJECTED
|
|
RENDERING_FAILURE
|
|
DELIVERY_DELAYED
|
|
FAILED
|
|
}
|
|
|
|
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?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
attachments String?
|
|
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
|
|
emailEvents EmailEvent[]
|
|
}
|
|
|
|
model EmailEvent {
|
|
id String @id @default(cuid())
|
|
emailId String
|
|
status EmailStatus
|
|
data Json?
|
|
createdAt DateTime @default(now())
|
|
email Email @relation(fields: [emailId], references: [id], onDelete: Cascade)
|
|
}
|