shellphone.app/prisma/schema.prisma

186 lines
5.0 KiB
Plaintext
Raw Normal View History

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