shellphone.app/prisma/schema.prisma

217 lines
5.8 KiB
Plaintext
Raw Normal View History

2022-05-17 23:48:59 +00:00
generator client {
provider = "prisma-client-js"
2022-05-17 23:48:59 +00:00
}
2022-05-14 10:22:06 +00:00
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model TwilioAccount {
2022-06-11 00:09:37 +00:00
accountSid String @id
createdAt DateTime @default(now()) @db.Timestamptz(6)
updatedAt DateTime @updatedAt @db.Timestamptz(6)
authToken String
twimlAppSid String?
apiKeySid String?
apiKeySecret String?
organizationId String @unique
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
phoneNumbers PhoneNumber[]
2022-05-14 10:22:06 +00:00
}
model Organization {
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
twilioAccount TwilioAccount?
memberships Membership[]
subscriptions Subscription[] // many subscriptions to keep a history
2022-05-14 10:22:06 +00:00
}
model Subscription {
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 {
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?
notificationSubscription NotificationSubscription[]
2022-05-14 10:22:06 +00:00
@@unique([organizationId, invitedEmail])
2022-05-14 10:22:06 +00:00
}
model User {
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 {
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 {
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
@@unique([hashedToken, type])
2022-05-14 10:22:06 +00:00
}
model Message {
id String @id
sentAt DateTime @db.Timestamptz(6)
content String
recipient String
from String
to String
direction Direction
status MessageStatus
phoneNumberId String
phoneNumber PhoneNumber @relation(fields: [phoneNumberId], references: [id], onDelete: Cascade)
@@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 {
id String @id
createdAt DateTime @default(now()) @db.Timestamptz(6)
recipient String
from String
to String
status CallStatus
direction Direction
duration String
phoneNumberId String
phoneNumber PhoneNumber @relation(fields: [phoneNumberId], references: [id], onDelete: Cascade)
@@index([phoneNumberId, recipient])
2022-05-17 23:48:59 +00:00
}
model PhoneNumber {
2022-06-11 00:09:37 +00:00
id String @id
createdAt DateTime @default(now()) @db.Timestamptz(6)
number String
isCurrent Boolean
isFetchingMessages Boolean?
isFetchingCalls Boolean?
2022-06-11 00:09:37 +00:00
twilioAccountSid String
twilioAccount TwilioAccount @relation(fields: [twilioAccountSid], references: [accountSid], onDelete: Cascade)
messages Message[]
phoneCalls PhoneCall[]
2022-05-17 23:48:59 +00:00
2022-06-11 00:09:37 +00:00
@@unique([twilioAccountSid, isCurrent])
2022-05-17 23:48:59 +00:00
}
model NotificationSubscription {
id String @id @default(uuid())
createdAt DateTime @default(now()) @db.Timestamptz
updatedAt DateTime @updatedAt @db.Timestamptz
endpoint String @unique
expirationTime Int?
keys_p256dh String
keys_auth String
membership Membership @relation(fields: [membershipId], references: [id], onDelete: Cascade)
membershipId String
}
2022-05-17 23:48:59 +00:00
enum SubscriptionStatus {
active
trialing
past_due
paused
deleted
2022-05-17 23:48:59 +00:00
}
enum MembershipRole {
OWNER
USER
2022-05-17 23:48:59 +00:00
}
enum GlobalRole {
SUPERADMIN
CUSTOMER
2022-05-17 23:48:59 +00:00
}
enum TokenType {
RESET_PASSWORD
INVITE_MEMBER
2022-05-14 10:22:06 +00:00
}
enum Direction {
Inbound
Outbound
2022-05-14 10:22:06 +00:00
}
enum MessageStatus {
Queued
Sending
Sent
Failed
Delivered
Undelivered
Receiving
Received
Accepted
Scheduled
Read
PartiallyDelivered
Canceled
Error
2022-05-14 10:22:06 +00:00
}
enum CallStatus {
Queued
Ringing
InProgress
Completed
Busy
Failed
NoAnswer
Canceled
2022-05-14 10:22:06 +00:00
}