2023-04-18 06:24:44 +03:00
|
|
|
generator client {
|
2023-09-08 00:32:41 +03:00
|
|
|
provider = "prisma-client-js"
|
2023-10-19 11:59:02 +03:00
|
|
|
binaryTargets = ["native", "debian-openssl-3.0.x", "linux-arm64-openssl-3.0.x"]
|
2023-08-29 13:07:05 +03:00
|
|
|
previewFeatures = ["metrics", "tracing"]
|
2023-04-18 06:24:44 +03:00
|
|
|
}
|
|
|
|
|
2023-06-21 09:08:32 +03:00
|
|
|
datasource db {
|
|
|
|
provider = "postgresql"
|
|
|
|
url = env("DATABASE_URL")
|
2023-04-18 06:24:44 +03:00
|
|
|
}
|
|
|
|
|
2023-04-28 02:02:05 +03:00
|
|
|
model Workspace {
|
2023-08-29 13:07:05 +03:00
|
|
|
id String @id @default(uuid()) @db.VarChar
|
|
|
|
public Boolean
|
|
|
|
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
|
|
|
|
users UserWorkspacePermission[]
|
2023-04-28 02:02:05 +03:00
|
|
|
|
|
|
|
@@map("workspaces")
|
2023-04-18 06:24:44 +03:00
|
|
|
}
|
|
|
|
|
2023-04-28 02:02:05 +03:00
|
|
|
model UserWorkspacePermission {
|
|
|
|
id String @id @default(uuid()) @db.VarChar
|
|
|
|
workspaceId String @map("workspace_id") @db.VarChar
|
2023-08-29 13:07:05 +03:00
|
|
|
subPageId String? @map("sub_page_id") @db.VarChar
|
|
|
|
userId String? @map("entity_id") @db.VarChar
|
2023-04-28 02:02:05 +03:00
|
|
|
/// Read/Write/Admin/Owner
|
|
|
|
type Int @db.SmallInt
|
|
|
|
/// Whether the permission invitation is accepted by the user
|
|
|
|
accepted Boolean @default(false)
|
|
|
|
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
|
2023-08-29 13:07:05 +03:00
|
|
|
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
|
2023-06-21 09:08:32 +03:00
|
|
|
workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
|
2023-04-28 02:02:05 +03:00
|
|
|
|
2023-08-29 13:07:05 +03:00
|
|
|
@@unique([workspaceId, subPageId, userId])
|
2023-04-28 02:02:05 +03:00
|
|
|
@@map("user_workspace_permissions")
|
2023-04-18 06:24:44 +03:00
|
|
|
}
|
2023-06-21 09:08:32 +03:00
|
|
|
|
|
|
|
model User {
|
|
|
|
id String @id @default(uuid()) @db.VarChar
|
|
|
|
name String
|
2023-08-29 13:07:05 +03:00
|
|
|
email String @unique
|
2023-06-21 09:08:32 +03:00
|
|
|
emailVerified DateTime? @map("email_verified")
|
|
|
|
// image field is for the next-auth
|
2023-08-29 13:07:05 +03:00
|
|
|
avatarUrl String? @map("avatar_url") @db.VarChar
|
2023-06-21 09:08:32 +03:00
|
|
|
accounts Account[]
|
|
|
|
sessions Session[]
|
|
|
|
workspaces UserWorkspacePermission[]
|
|
|
|
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
|
|
|
|
/// Not available if user signed up through OAuth providers
|
|
|
|
password String? @db.VarChar
|
2023-09-08 00:32:41 +03:00
|
|
|
features UserFeatureGates[]
|
2023-10-19 05:06:34 +03:00
|
|
|
customer UserStripeCustomer?
|
|
|
|
subscription UserSubscription?
|
|
|
|
invoices UserInvoice[]
|
2023-06-21 09:08:32 +03:00
|
|
|
|
|
|
|
@@map("users")
|
|
|
|
}
|
|
|
|
|
2023-09-08 00:32:41 +03:00
|
|
|
model UserFeatureGates {
|
|
|
|
id String @id @default(uuid()) @db.VarChar
|
|
|
|
userId String @map("user_id") @db.VarChar
|
|
|
|
feature String @db.VarChar
|
|
|
|
reason String @db.VarChar
|
|
|
|
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
|
|
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
|
|
|
|
@@map("user_feature_gates")
|
|
|
|
}
|
|
|
|
|
2023-06-21 09:08:32 +03:00
|
|
|
model Account {
|
|
|
|
id String @id @default(cuid())
|
|
|
|
userId String @map("user_id")
|
|
|
|
type String
|
|
|
|
provider String
|
|
|
|
providerAccountId String @map("provider_account_id")
|
|
|
|
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])
|
|
|
|
@@map("accounts")
|
|
|
|
}
|
|
|
|
|
|
|
|
model Session {
|
|
|
|
id String @id @default(cuid())
|
|
|
|
sessionToken String @unique @map("session_token")
|
|
|
|
userId String @map("user_id")
|
|
|
|
expires DateTime
|
|
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
|
|
|
|
@@map("sessions")
|
|
|
|
}
|
|
|
|
|
|
|
|
model VerificationToken {
|
|
|
|
identifier String
|
|
|
|
token String @unique
|
|
|
|
expires DateTime
|
|
|
|
|
|
|
|
@@unique([identifier, token])
|
|
|
|
@@map("verificationtokens")
|
|
|
|
}
|
2023-06-29 04:45:45 +03:00
|
|
|
|
|
|
|
model Blob {
|
2023-08-29 13:07:05 +03:00
|
|
|
id Int @id @default(autoincrement()) @db.Integer
|
|
|
|
hash String @db.VarChar
|
2023-06-29 04:45:45 +03:00
|
|
|
workspaceId String @map("workspace_id") @db.VarChar
|
|
|
|
blob Bytes @db.ByteA
|
2023-08-29 13:07:05 +03:00
|
|
|
length BigInt
|
2023-06-29 04:45:45 +03:00
|
|
|
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
|
|
|
|
|
|
|
|
@@unique([workspaceId, hash])
|
|
|
|
@@map("blobs")
|
|
|
|
}
|
|
|
|
|
|
|
|
model OptimizedBlob {
|
2023-08-29 13:07:05 +03:00
|
|
|
id Int @id @default(autoincrement()) @db.Integer
|
|
|
|
hash String @db.VarChar
|
2023-06-29 04:45:45 +03:00
|
|
|
workspaceId String @map("workspace_id") @db.VarChar
|
|
|
|
params String @db.VarChar
|
|
|
|
blob Bytes @db.ByteA
|
2023-08-29 13:07:05 +03:00
|
|
|
length BigInt
|
2023-06-29 04:45:45 +03:00
|
|
|
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
|
|
|
|
|
|
|
|
@@unique([workspaceId, hash, params])
|
|
|
|
@@map("optimized_blobs")
|
|
|
|
}
|
|
|
|
|
2023-08-29 13:07:05 +03:00
|
|
|
// the latest snapshot of each doc that we've seen
|
|
|
|
// Snapshot + Updates are the latest state of the doc
|
|
|
|
model Snapshot {
|
|
|
|
id String @default(uuid()) @map("guid") @db.VarChar
|
|
|
|
workspaceId String @map("workspace_id") @db.VarChar
|
|
|
|
blob Bytes @db.ByteA
|
2023-10-10 06:23:12 +03:00
|
|
|
seq Int @default(0) @db.Integer
|
|
|
|
state Bytes? @db.ByteA
|
2023-08-29 13:07:05 +03:00
|
|
|
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
|
|
|
|
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz(6)
|
|
|
|
|
|
|
|
@@id([id, workspaceId])
|
|
|
|
@@map("snapshots")
|
|
|
|
}
|
|
|
|
|
|
|
|
// backup during other update operation queue downtime
|
|
|
|
model Update {
|
|
|
|
objectId String @id @default(uuid()) @map("object_id") @db.VarChar
|
|
|
|
workspaceId String @map("workspace_id") @db.VarChar
|
2023-10-10 06:23:12 +03:00
|
|
|
id String @map("guid") @db.VarChar
|
|
|
|
seq Int @db.Integer
|
2023-08-29 13:07:05 +03:00
|
|
|
blob Bytes @db.ByteA
|
|
|
|
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
|
|
|
|
|
2023-10-10 06:23:12 +03:00
|
|
|
@@unique([workspaceId, id, seq])
|
2023-08-29 13:07:05 +03:00
|
|
|
@@map("updates")
|
|
|
|
}
|
2023-06-29 04:45:45 +03:00
|
|
|
|
2023-08-29 13:07:05 +03:00
|
|
|
model NewFeaturesWaitingList {
|
|
|
|
id String @id @default(uuid()) @db.VarChar
|
|
|
|
email String @unique
|
|
|
|
type Int @db.SmallInt
|
|
|
|
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
|
2023-06-29 04:45:45 +03:00
|
|
|
|
2023-08-29 13:07:05 +03:00
|
|
|
@@map("new_features_waiting_list")
|
2023-06-29 04:45:45 +03:00
|
|
|
}
|
2023-10-19 05:06:34 +03:00
|
|
|
|
|
|
|
model UserStripeCustomer {
|
|
|
|
userId String @id @map("user_id") @db.VarChar
|
|
|
|
stripeCustomerId String @unique @map("stripe_customer_id") @db.VarChar
|
|
|
|
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
|
|
|
|
|
|
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
|
|
|
|
@@map("user_stripe_customers")
|
|
|
|
}
|
|
|
|
|
|
|
|
model UserSubscription {
|
|
|
|
id Int @id @default(autoincrement()) @db.Integer
|
|
|
|
userId String @unique @map("user_id") @db.VarChar(36)
|
|
|
|
plan String @db.VarChar(20)
|
|
|
|
// yearly/monthly
|
|
|
|
recurring String @db.VarChar(20)
|
|
|
|
// subscription.id
|
|
|
|
stripeSubscriptionId String @unique @map("stripe_subscription_id")
|
|
|
|
// subscription.status, active/past_due/canceled/unpaid...
|
|
|
|
status String @db.VarChar(20)
|
|
|
|
// subscription.current_period_start
|
|
|
|
start DateTime @map("start") @db.Timestamptz(6)
|
|
|
|
// subscription.current_period_end
|
|
|
|
end DateTime @map("end") @db.Timestamptz(6)
|
|
|
|
// subscription.billing_cycle_anchor
|
|
|
|
nextBillAt DateTime? @map("next_bill_at") @db.Timestamptz(6)
|
|
|
|
// subscription.canceled_at
|
|
|
|
canceledAt DateTime? @map("canceled_at") @db.Timestamptz(6)
|
|
|
|
// subscription.trial_start
|
|
|
|
trialStart DateTime? @map("trial_start") @db.Timestamptz(6)
|
|
|
|
// subscription.trial_end
|
|
|
|
trialEnd DateTime? @map("trial_end") @db.Timestamptz(6)
|
|
|
|
stripeScheduleId String? @map("stripe_schedule_id") @db.VarChar
|
|
|
|
|
|
|
|
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
|
|
|
|
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz(6)
|
|
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
|
|
|
|
@@map("user_subscriptions")
|
|
|
|
}
|
|
|
|
|
|
|
|
model UserInvoice {
|
|
|
|
id Int @id @default(autoincrement()) @db.Integer
|
|
|
|
userId String @map("user_id") @db.VarChar(36)
|
|
|
|
stripeInvoiceId String @unique @map("stripe_invoice_id")
|
|
|
|
currency String @db.VarChar(3)
|
|
|
|
// CNY 12.50 stored as 1250
|
|
|
|
amount Int @db.Integer
|
|
|
|
status String @db.VarChar(20)
|
|
|
|
plan String @db.VarChar(20)
|
|
|
|
recurring String @db.VarChar(20)
|
|
|
|
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
|
|
|
|
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz(6)
|
|
|
|
// billing reason
|
|
|
|
reason String @db.VarChar
|
|
|
|
lastPaymentError String? @map("last_payment_error") @db.Text
|
|
|
|
|
|
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
|
|
|
|
@@map("user_invoices")
|
|
|
|
}
|