Files
sign/packages/prisma/schema.prisma

535 lines
15 KiB
Plaintext
Raw Normal View History

generator kysely {
provider = "prisma-kysely"
2023-01-07 15:10:26 +01:00
}
datasource db {
2023-08-25 17:51:58 +10:00
provider = "postgresql"
url = env("NEXT_PRIVATE_DATABASE_URL")
directUrl = env("NEXT_PRIVATE_DIRECT_DATABASE_URL")
2023-01-07 15:10:26 +01:00
}
2023-02-19 12:49:09 +01:00
enum IdentityProvider {
DOCUMENSO
GOOGLE
2023-01-07 15:10:26 +01:00
}
enum Role {
ADMIN
USER
}
2023-01-07 15:10:26 +01:00
model User {
id Int @id @default(autoincrement())
name String?
customerId String? @unique
email String @unique
emailVerified DateTime?
password String?
source String?
signature String?
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
lastSignedIn DateTime @default(now())
roles Role[] @default([USER])
identityProvider IdentityProvider @default(DOCUMENSO)
accounts Account[]
sessions Session[]
Document Document[]
Subscription Subscription[]
PasswordResetToken PasswordResetToken[]
ownedTeams Team[]
ownedPendingTeams TeamPending[]
teamMembers TeamMember[]
twoFactorSecret String?
twoFactorEnabled Boolean @default(false)
twoFactorBackupCodes String?
2024-02-28 14:43:09 +11:00
url String? @unique
2024-02-28 14:43:09 +11:00
userProfile UserProfile?
2024-01-30 17:31:27 +11:00
VerificationToken VerificationToken[]
ApiToken ApiToken[]
2024-01-30 17:31:27 +11:00
Template Template[]
securityAuditLogs UserSecurityAuditLog[]
2024-02-06 16:00:28 +02:00
Webhooks Webhook[]
2024-02-23 10:47:01 +00:00
siteSettings SiteSettings[]
2023-10-30 16:58:51 +11:00
@@index([email])
}
model UserProfile {
2024-02-28 14:43:09 +11:00
id Int @id
bio String?
2024-02-28 14:43:09 +11:00
User User? @relation(fields: [id], references: [id], onDelete: Cascade)
}
2024-01-30 17:31:27 +11:00
enum UserSecurityAuditLogType {
ACCOUNT_PROFILE_UPDATE
ACCOUNT_SSO_LINK
AUTH_2FA_DISABLE
AUTH_2FA_ENABLE
PASSWORD_RESET
PASSWORD_UPDATE
SIGN_OUT
SIGN_IN
2024-01-31 12:27:40 +11:00
SIGN_IN_FAIL
SIGN_IN_2FA_FAIL
2024-01-30 17:31:27 +11:00
}
model UserSecurityAuditLog {
id Int @id @default(autoincrement())
userId Int
createdAt DateTime @default(now())
type UserSecurityAuditLogType
userAgent String?
ipAddress String?
2024-01-30 18:37:48 +11:00
User User @relation(fields: [userId], references: [id], onDelete: Cascade)
2024-01-30 17:31:27 +11:00
}
model PasswordResetToken {
id Int @id @default(autoincrement())
token String @unique
createdAt DateTime @default(now())
expiry DateTime
userId Int
User User @relation(fields: [userId], references: [id])
}
model VerificationToken {
id Int @id @default(autoincrement())
identifier String
token String @unique
expires DateTime
createdAt DateTime @default(now())
userId Int
2023-12-05 03:54:41 +01:00
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}
2024-02-06 16:00:28 +02:00
enum WebhookTriggerEvents {
DOCUMENT_CREATED
2024-02-24 11:18:58 +02:00
DOCUMENT_SENT
DOCUMENT_OPENED
2024-02-06 16:00:28 +02:00
DOCUMENT_SIGNED
2024-02-24 11:18:58 +02:00
DOCUMENT_COMPLETED
2024-02-06 16:00:28 +02:00
}
model Webhook {
2024-02-27 12:13:56 +11:00
id String @id @default(cuid())
2024-02-06 16:00:28 +02:00
webhookUrl String
eventTriggers WebhookTriggerEvents[]
secret String?
enabled Boolean @default(true)
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
userId Int
User User @relation(fields: [userId], references: [id], onDelete: Cascade)
2024-02-27 13:38:12 +11:00
teamId Int?
team Team? @relation(fields: [teamId], references: [id], onDelete: Cascade)
2024-02-27 12:54:37 +11:00
WebhookCall WebhookCall[]
}
enum WebhookCallStatus {
SUCCESS
FAILED
}
model WebhookCall {
id String @id @default(cuid())
2024-02-27 12:54:37 +11:00
status WebhookCallStatus
url String
event WebhookTriggerEvents
2024-02-27 12:54:37 +11:00
requestBody Json
responseCode Int
responseHeaders Json?
responseBody Json?
createdAt DateTime @default(now())
2024-02-27 12:54:37 +11:00
webhookId String
webhook Webhook @relation(fields: [webhookId], references: [id], onDelete: Cascade)
2024-02-06 16:00:28 +02:00
}
enum ApiTokenAlgorithm {
SHA512
}
model ApiToken {
id Int @id @default(autoincrement())
name String
token String @unique
algorithm ApiTokenAlgorithm @default(SHA512)
2024-02-09 11:32:54 +02:00
expires DateTime?
createdAt DateTime @default(now())
2024-02-22 13:39:34 +11:00
userId Int?
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
teamId Int?
team Team? @relation(fields: [teamId], references: [id], onDelete: Cascade)
}
enum SubscriptionStatus {
ACTIVE
PAST_DUE
INACTIVE
}
model Subscription {
id Int @id @default(autoincrement())
status SubscriptionStatus @default(INACTIVE)
planId String @unique
priceId String
periodEnd DateTime?
userId Int?
teamId Int? @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
cancelAtPeriodEnd Boolean @default(false)
team Team? @relation(fields: [teamId], references: [id], onDelete: Cascade)
User User? @relation(fields: [userId], references: [id], onDelete: Cascade)
@@index([userId])
2023-01-10 18:52:04 +01:00
}
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
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)
}
2023-02-19 12:49:09 +01:00
enum DocumentStatus {
DRAFT
PENDING
COMPLETED
2023-02-13 19:33:26 +01:00
}
2023-02-19 12:49:09 +01:00
model Document {
2023-09-21 00:51:02 +00:00
id Int @id @default(autoincrement())
userId Int
User User @relation(fields: [userId], references: [id], onDelete: Cascade)
title String
status DocumentStatus @default(DRAFT)
Recipient Recipient[]
Field Field[]
ShareLink DocumentShareLink[]
documentDataId String
2023-10-28 20:57:26 +11:00
documentData DocumentData @relation(fields: [documentDataId], references: [id], onDelete: Cascade)
documentMeta DocumentMeta?
2023-10-28 20:57:26 +11:00
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
2023-11-03 15:48:19 +11:00
completedAt DateTime?
deletedAt DateTime?
teamId Int?
team Team? @relation(fields: [teamId], references: [id])
auditLogs DocumentAuditLog[]
2023-09-21 00:51:02 +00:00
@@unique([documentDataId])
2023-10-30 16:58:51 +11:00
@@index([userId])
@@index([status])
2023-09-21 00:51:02 +00:00
}
model DocumentAuditLog {
id String @id @default(cuid())
documentId Int
createdAt DateTime @default(now())
type String
data Json
// Details of the person who performed the action which caused the audit log.
name String?
email String?
userId Int?
userAgent String?
ipAddress String?
Document Document @relation(fields: [documentId], references: [id], onDelete: Cascade)
}
2023-09-21 00:51:02 +00:00
enum DocumentDataType {
S3_PATH
BYTES
BYTES_64
}
model DocumentData {
id String @id @default(cuid())
type DocumentDataType
data String
initialData String
Document Document?
2023-10-06 22:54:24 +00:00
Template Template?
2023-01-07 15:10:26 +01:00
}
model DocumentMeta {
2024-02-22 13:39:34 +11:00
id String @id @default(cuid())
subject String?
message String?
timezone String? @default("Etc/UTC") @db.Text
password String?
dateFormat String? @default("yyyy-MM-dd hh:mm a") @db.Text
documentId Int @unique
document Document @relation(fields: [documentId], references: [id], onDelete: Cascade)
redirectUrl String?
}
2023-01-07 15:10:26 +01:00
enum ReadStatus {
NOT_OPENED
OPENED
}
enum SendStatus {
NOT_SENT
SENT
}
enum SigningStatus {
NOT_SIGNED
SIGNED
}
2023-01-27 20:14:32 +01:00
enum RecipientRole {
CC
SIGNER
VIEWER
APPROVER
}
2023-02-19 12:49:09 +01:00
model Recipient {
id Int @id @default(autoincrement())
2023-10-06 22:54:24 +00:00
documentId Int?
templateId Int?
2023-02-19 12:49:09 +01:00
email String @db.VarChar(255)
name String @default("") @db.VarChar(255)
token String
expired DateTime?
signedAt DateTime?
role RecipientRole @default(SIGNER)
2023-02-19 12:49:09 +01:00
readStatus ReadStatus @default(NOT_OPENED)
signingStatus SigningStatus @default(NOT_SIGNED)
sendStatus SendStatus @default(NOT_SENT)
2024-01-30 17:31:27 +11:00
Document Document? @relation(fields: [documentId], references: [id], onDelete: Cascade)
Template Template? @relation(fields: [templateId], references: [id], onDelete: Cascade)
2023-02-19 12:49:09 +01:00
Field Field[]
Signature Signature[]
@@unique([documentId, email])
2023-10-06 22:54:24 +00:00
@@unique([templateId, email])
2023-10-30 16:58:51 +11:00
@@index([documentId])
2023-10-06 22:54:24 +00:00
@@index([templateId])
2023-10-30 16:58:51 +11:00
@@index([token])
2023-02-19 12:49:09 +01:00
}
enum FieldType {
SIGNATURE
FREE_SIGNATURE
NAME
EMAIL
2023-02-19 12:49:09 +01:00
DATE
TEXT
}
model Field {
id Int @id @default(autoincrement())
secondaryId String @unique @default(cuid())
2023-10-06 22:54:24 +00:00
documentId Int?
templateId Int?
2023-02-19 12:49:09 +01:00
recipientId Int?
type FieldType
page Int
positionX Decimal @default(0)
positionY Decimal @default(0)
width Decimal @default(-1)
height Decimal @default(-1)
2023-02-28 19:36:21 +01:00
customText String
2023-03-09 13:43:05 +01:00
inserted Boolean
2023-10-06 22:54:24 +00:00
Document Document? @relation(fields: [documentId], references: [id], onDelete: Cascade)
Template Template? @relation(fields: [templateId], references: [id], onDelete: Cascade)
Recipient Recipient? @relation(fields: [recipientId], references: [id], onDelete: Cascade)
2023-02-19 12:49:09 +01:00
Signature Signature?
2023-10-30 16:58:51 +11:00
@@index([documentId])
2023-10-06 22:54:24 +00:00
@@index([templateId])
2023-10-30 16:58:51 +11:00
@@index([recipientId])
2023-02-19 12:49:09 +01:00
}
model Signature {
id Int @id @default(autoincrement())
created DateTime @default(now())
recipientId Int
fieldId Int @unique
signatureImageAsBase64 String?
typedSignature String?
2023-02-19 12:49:09 +01:00
Recipient Recipient @relation(fields: [recipientId], references: [id], onDelete: Cascade)
2023-02-19 12:49:09 +01:00
Field Field @relation(fields: [fieldId], references: [id], onDelete: Restrict)
2023-10-30 16:58:51 +11:00
@@index([recipientId])
2023-01-27 20:14:32 +01:00
}
2023-06-05 12:23:52 +00:00
2023-09-21 00:51:02 +00:00
model DocumentShareLink {
id Int @id @default(autoincrement())
email String
slug String @unique
documentId Int
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
document Document @relation(fields: [documentId], references: [id], onDelete: Cascade)
2023-09-21 00:51:02 +00:00
@@unique([documentId, email])
2023-06-05 12:23:52 +00:00
}
2023-10-06 22:54:24 +00:00
enum TeamMemberRole {
ADMIN
MANAGER
MEMBER
}
enum TeamMemberInviteStatus {
ACCEPTED
PENDING
}
model Team {
id Int @id @default(autoincrement())
name String
url String @unique
createdAt DateTime @default(now())
customerId String? @unique
ownerUserId Int
members TeamMember[]
invites TeamMemberInvite[]
teamEmail TeamEmail?
emailVerification TeamEmailVerification?
transferVerification TeamTransferVerification?
owner User @relation(fields: [ownerUserId], references: [id])
subscription Subscription?
2024-02-08 12:33:20 +11:00
document Document[]
templates Template[]
2024-02-22 13:39:34 +11:00
ApiToken ApiToken[]
2024-02-27 13:38:12 +11:00
Webhook Webhook[]
}
model TeamPending {
id Int @id @default(autoincrement())
name String
url String @unique
createdAt DateTime @default(now())
customerId String @unique
ownerUserId Int
owner User @relation(fields: [ownerUserId], references: [id], onDelete: Cascade)
}
model TeamMember {
id Int @id @default(autoincrement())
teamId Int
createdAt DateTime @default(now())
role TeamMemberRole
userId Int
user User @relation(fields: [userId], references: [id])
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
@@unique([userId, teamId])
}
model TeamEmail {
teamId Int @id @unique
createdAt DateTime @default(now())
name String
email String @unique
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
}
model TeamEmailVerification {
teamId Int @id @unique
name String
email String
token String @unique
expiresAt DateTime
createdAt DateTime @default(now())
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
}
model TeamTransferVerification {
teamId Int @id @unique
userId Int
name String
email String
token String @unique
expiresAt DateTime
createdAt DateTime @default(now())
clearPaymentMethods Boolean @default(false)
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
}
model TeamMemberInvite {
id Int @id @default(autoincrement())
teamId Int
createdAt DateTime @default(now())
email String
status TeamMemberInviteStatus @default(PENDING)
role TeamMemberRole
token String @unique
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
@@unique([teamId, email])
}
2023-10-06 22:54:24 +00:00
enum TemplateType {
PUBLIC
PRIVATE
}
model Template {
id Int @id @default(autoincrement())
type TemplateType @default(PRIVATE)
2023-12-15 22:07:27 +11:00
title String
userId Int
2024-02-08 12:33:20 +11:00
teamId Int?
2023-10-06 22:54:24 +00:00
templateDocumentDataId String
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
2023-12-15 22:07:27 +11:00
2024-02-08 12:33:20 +11:00
team Team? @relation(fields: [teamId], references: [id], onDelete: Cascade)
2024-01-30 17:31:27 +11:00
templateDocumentData DocumentData @relation(fields: [templateDocumentDataId], references: [id], onDelete: Cascade)
User User @relation(fields: [userId], references: [id], onDelete: Cascade)
Recipient Recipient[]
Field Field[]
2023-10-06 22:54:24 +00:00
@@unique([templateDocumentDataId])
}
2024-02-23 10:47:01 +00:00
model SiteSettings {
id String @id
enabled Boolean @default(false)
data Json
lastModifiedByUserId Int?
lastModifiedAt DateTime @default(now())
lastModifiedByUser User? @relation(fields: [lastModifiedByUserId], references: [id])
}