2022-05-17 23:48:59 +00:00
|
|
|
generator client {
|
2022-05-21 19:33:23 +00:00
|
|
|
provider = "prisma-client-js"
|
2022-05-17 23:48:59 +00:00
|
|
|
}
|
|
|
|
|
2022-05-14 10:22:06 +00:00
|
|
|
datasource db {
|
2022-05-21 19:33:23 +00:00
|
|
|
provider = "postgresql"
|
|
|
|
url = env("DATABASE_URL")
|
|
|
|
}
|
|
|
|
|
|
|
|
model TwilioAccount {
|
|
|
|
subAccountSid String @id
|
|
|
|
createdAt DateTime @default(now()) @db.Timestamptz(6)
|
|
|
|
updatedAt DateTime @updatedAt @db.Timestamptz(6)
|
|
|
|
subAccountAuthToken String
|
|
|
|
accountSid String
|
|
|
|
accountAuthToken String
|
|
|
|
twimlAppSid String?
|
|
|
|
|
|
|
|
organizationId String @unique
|
2022-05-21 23:17:43 +00:00
|
|
|
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
|
2022-05-14 10:22:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
model Organization {
|
2022-05-21 19:33:23 +00:00
|
|
|
id String @id @default(cuid())
|
|
|
|
createdAt DateTime @default(now()) @db.Timestamptz(6)
|
|
|
|
updatedAt DateTime @updatedAt @db.Timestamptz(6)
|
2022-05-14 22:35:51 +00:00
|
|
|
|
2022-05-21 19:33:23 +00:00
|
|
|
twilioAccount TwilioAccount?
|
|
|
|
memberships Membership[]
|
|
|
|
phoneNumbers PhoneNumber[]
|
|
|
|
subscriptions Subscription[] // many subscriptions to keep a history
|
2022-05-14 10:22:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
model Subscription {
|
2022-05-21 19:33:23 +00:00
|
|
|
createdAt DateTime @default(now()) @db.Timestamptz(6)
|
|
|
|
updatedAt DateTime @updatedAt @db.Timestamptz(6)
|
|
|
|
paddleSubscriptionId Int @id @unique
|
|
|
|
paddlePlanId Int
|
|
|
|
paddleCheckoutId String
|
|
|
|
status SubscriptionStatus
|
|
|
|
updateUrl String
|
|
|
|
cancelUrl String
|
|
|
|
currency String
|
|
|
|
unitPrice Float
|
|
|
|
nextBillDate DateTime @db.Date
|
|
|
|
lastEventTime DateTime @db.Timestamp(6)
|
|
|
|
cancellationEffectiveDate DateTime? @db.Date
|
|
|
|
organizationId String
|
|
|
|
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
|
2022-05-14 10:22:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
model Membership {
|
2022-05-21 19:33:23 +00:00
|
|
|
id String @id @default(cuid())
|
|
|
|
role MembershipRole
|
|
|
|
organizationId String
|
|
|
|
userId String?
|
|
|
|
invitedEmail String?
|
|
|
|
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
|
|
|
|
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
invitationToken Token?
|
2022-05-14 10:22:06 +00:00
|
|
|
|
2022-05-21 19:33:23 +00:00
|
|
|
@@unique([organizationId, invitedEmail])
|
2022-05-14 10:22:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
model User {
|
2022-05-21 19:33:23 +00:00
|
|
|
id String @id @default(cuid())
|
|
|
|
createdAt DateTime @default(now()) @db.Timestamptz(6)
|
|
|
|
updatedAt DateTime @updatedAt @db.Timestamptz(6)
|
|
|
|
fullName String
|
|
|
|
email String @unique
|
|
|
|
hashedPassword String?
|
|
|
|
role GlobalRole @default(CUSTOMER)
|
|
|
|
memberships Membership[]
|
|
|
|
sessions Session[]
|
|
|
|
tokens Token[]
|
2022-05-14 10:22:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
model Session {
|
2022-05-21 19:33:23 +00:00
|
|
|
id String @id @default(cuid())
|
|
|
|
createdAt DateTime @default(now()) @db.Timestamptz(6)
|
|
|
|
updatedAt DateTime @updatedAt @db.Timestamptz(6)
|
|
|
|
expiresAt DateTime? @db.Timestamptz(6)
|
|
|
|
data String
|
|
|
|
userId String?
|
|
|
|
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
|
2022-05-14 10:22:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
model Token {
|
2022-05-21 19:33:23 +00:00
|
|
|
id String @id @default(cuid())
|
|
|
|
createdAt DateTime @default(now()) @db.Timestamptz(6)
|
|
|
|
updatedAt DateTime @updatedAt @db.Timestamptz(6)
|
|
|
|
hashedToken String
|
|
|
|
type TokenType
|
|
|
|
expiresAt DateTime @db.Timestamptz(6)
|
|
|
|
sentTo String
|
|
|
|
userId String
|
|
|
|
membershipId String @unique
|
|
|
|
membership Membership @relation(fields: [membershipId], references: [id], onDelete: Cascade)
|
|
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
2022-05-14 10:22:06 +00:00
|
|
|
|
2022-05-21 19:33:23 +00:00
|
|
|
@@unique([hashedToken, type])
|
2022-05-14 10:22:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
model Message {
|
2022-05-21 19:33:23 +00:00
|
|
|
id String @id
|
|
|
|
sentAt DateTime @db.Timestamptz(6)
|
|
|
|
content String
|
2022-05-21 23:17:43 +00:00
|
|
|
recipient String
|
2022-05-21 19:33:23 +00:00
|
|
|
from String
|
|
|
|
to String
|
|
|
|
direction Direction
|
|
|
|
status MessageStatus
|
|
|
|
phoneNumberId String
|
|
|
|
phoneNumber PhoneNumber @relation(fields: [phoneNumberId], references: [id], onDelete: Cascade)
|
2022-05-21 23:17:43 +00:00
|
|
|
|
|
|
|
@@index([phoneNumberId, recipient])
|
2022-05-17 23:48:59 +00:00
|
|
|
}
|
2022-05-14 10:22:06 +00:00
|
|
|
|
2022-05-17 23:48:59 +00:00
|
|
|
model PhoneCall {
|
2022-05-21 19:33:23 +00:00
|
|
|
id String @id
|
|
|
|
createdAt DateTime @default(now()) @db.Timestamptz(6)
|
2022-05-21 23:17:43 +00:00
|
|
|
recipient String
|
2022-05-21 19:33:23 +00:00
|
|
|
from String
|
|
|
|
to String
|
|
|
|
status CallStatus
|
|
|
|
direction Direction
|
|
|
|
duration String
|
|
|
|
phoneNumberId String
|
|
|
|
phoneNumber PhoneNumber @relation(fields: [phoneNumberId], references: [id], onDelete: Cascade)
|
2022-05-21 23:17:43 +00:00
|
|
|
|
|
|
|
@@index([phoneNumberId, recipient])
|
2022-05-17 23:48:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
model PhoneNumber {
|
2022-05-21 19:33:23 +00:00
|
|
|
id String @id
|
|
|
|
createdAt DateTime @default(now()) @db.Timestamptz(6)
|
|
|
|
number String
|
|
|
|
isCurrent Boolean
|
|
|
|
isFetchingMessages Boolean?
|
|
|
|
isFetchingCalls Boolean?
|
|
|
|
organizationId String
|
|
|
|
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
|
|
|
|
messages Message[]
|
|
|
|
phoneCalls PhoneCall[]
|
2022-05-17 23:48:59 +00:00
|
|
|
|
2022-05-21 19:33:23 +00:00
|
|
|
@@unique([organizationId, isCurrent])
|
2022-05-17 23:48:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enum SubscriptionStatus {
|
2022-05-21 19:33:23 +00:00
|
|
|
active
|
|
|
|
trialing
|
|
|
|
past_due
|
|
|
|
paused
|
|
|
|
deleted
|
2022-05-17 23:48:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enum MembershipRole {
|
2022-05-21 19:33:23 +00:00
|
|
|
OWNER
|
|
|
|
USER
|
2022-05-17 23:48:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enum GlobalRole {
|
2022-05-21 19:33:23 +00:00
|
|
|
SUPERADMIN
|
|
|
|
CUSTOMER
|
2022-05-17 23:48:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enum TokenType {
|
2022-05-21 19:33:23 +00:00
|
|
|
RESET_PASSWORD
|
|
|
|
INVITE_MEMBER
|
2022-05-14 10:22:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enum Direction {
|
2022-05-21 19:33:23 +00:00
|
|
|
Inbound
|
|
|
|
Outbound
|
2022-05-14 10:22:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enum MessageStatus {
|
2022-05-21 19:33:23 +00:00
|
|
|
Queued
|
|
|
|
Sending
|
|
|
|
Sent
|
|
|
|
Failed
|
|
|
|
Delivered
|
|
|
|
Undelivered
|
|
|
|
Receiving
|
|
|
|
Received
|
|
|
|
Accepted
|
|
|
|
Scheduled
|
|
|
|
Read
|
|
|
|
PartiallyDelivered
|
|
|
|
Canceled
|
|
|
|
Error
|
2022-05-14 10:22:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enum CallStatus {
|
2022-05-21 19:33:23 +00:00
|
|
|
Queued
|
|
|
|
Ringing
|
|
|
|
InProgress
|
|
|
|
Completed
|
|
|
|
Busy
|
|
|
|
Failed
|
|
|
|
NoAnswer
|
|
|
|
Canceled
|
2022-05-14 10:22:06 +00:00
|
|
|
}
|