Files
persionalBrand/apps/api/prisma/schema.prisma
T

321 lines
9.8 KiB
Plaintext

generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
enum BookingStatus {
received
contacting
confirmed
completed
cancelled
}
enum BookingRequestType {
package
private_chef
inquiry
}
enum ContactPreference {
wechat
phone
none
}
enum FulfillmentType {
pickup
delivery
}
model BrandProfile {
id String @id @default(uuid())
name String
templateKey String @default("food")
tagline String?
description String?
avatarUrl String?
coverUrl String?
hours String?
address String?
deliveryNote String?
contactPhone String?
contactWechat String?
config Json?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
services Service[]
bookings Booking[]
customerUsers CustomerUser[]
tags Tag[]
trustContents TrustContent[]
templateInstallations BrandTemplateInstallation[]
modules BrandModule[]
fieldDefinitions BrandFieldDefinition[]
offerings Offering[]
inquiryForms InquiryForm[]
inquirySubmissions InquirySubmission[]
}
model Service {
id String @id @default(uuid())
brandId String
brand BrandProfile @relation(fields: [brandId], references: [id])
name String
description String
categoryKey String @default("standard")
config Json?
coverUrl String?
priceText String?
priceAmount Int?
bookingEnabled Boolean @default(true)
isEnabled Boolean @default(true)
sortOrder Int @default(0)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
bookings Booking[]
bookingItems BookingItem[]
offeringId String?
offering Offering? @relation(fields: [offeringId], references: [id], onDelete: SetNull)
@@unique([brandId, name])
@@index([brandId, isEnabled, sortOrder])
}
model BrandTemplateInstallation {
id String @id @default(uuid())
brandId String
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
templateKey String
templateVersion String @default("1.0.0")
configSnapshot Json
previousSnapshots Json @default("[]")
installedAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([brandId, templateKey])
@@index([brandId])
}
model BrandModule {
id String @id @default(uuid())
brandId String
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
type String
title String
isEnabled Boolean @default(true)
sortOrder Int @default(0)
source String @default("core")
config Json?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([brandId, isEnabled, sortOrder])
}
model BrandFieldDefinition {
id String @id @default(uuid())
brandId String
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
scope String
key String
label String
type String
required Boolean @default(false)
isVisible Boolean @default(true)
sortOrder Int @default(0)
source String @default("custom")
isOverridden Boolean @default(false)
options Json?
visibleWhen Json?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([brandId, scope, key])
@@index([brandId, scope, sortOrder])
}
model Offering {
id String @id @default(uuid())
brandId String
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
kind String @default("service")
name String
summary String?
description String?
coverUrl String?
priceText String?
priceAmount Int?
isEnabled Boolean @default(true)
sortOrder Int @default(0)
config Json?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
services Service[]
inquiryForms InquiryForm[]
bookings Booking[]
bookingItems BookingItem[]
@@unique([brandId, name])
@@index([brandId, isEnabled, sortOrder])
}
model InquiryForm {
id String @id @default(uuid())
brandId String
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
offeringId String?
offering Offering? @relation(fields: [offeringId], references: [id], onDelete: SetNull)
name String
purpose String @default("inquiry")
targetType String @default("brand")
submissionAction String @default("create-inquiry")
version Int @default(1)
isEnabled Boolean @default(true)
fieldsSnapshot Json
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
submissions InquirySubmission[]
@@index([brandId, isEnabled])
}
model InquirySubmission {
id String @id @default(uuid())
brandId String
inquiryFormId String
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
inquiryForm InquiryForm @relation(fields: [inquiryFormId], references: [id], onDelete: Restrict)
formVersion Int
fieldsSnapshot Json
values Json
activeFields Json
createdAt DateTime @default(now())
@@index([brandId, createdAt])
@@index([inquiryFormId, formVersion])
}
model TrustContent {
id String @id @default(uuid())
brandId String
brand BrandProfile @relation(fields: [brandId], references: [id], onDelete: Cascade)
type String
title String
summary String?
content String
coverUrl String?
sortOrder Int @default(0)
isPublished Boolean @default(true)
config Json?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([brandId, type, sortOrder])
}
model CustomerUser {
id String @id @default(uuid())
brandId String
brand BrandProfile @relation(fields: [brandId], references: [id])
openid String
lastLoginAt DateTime @default(now())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
bookings Booking[]
@@unique([brandId, openid])
}
model Booking {
id String @id @default(uuid())
bookingNo String @unique
brandId String
brand BrandProfile @relation(fields: [brandId], references: [id])
customerUserId String
customerUser CustomerUser @relation(fields: [customerUserId], references: [id])
requestType BookingRequestType
customerName String
phone String?
wechatId String?
contactPreference ContactPreference
fulfillmentType FulfillmentType?
serviceId String?
service Service? @relation(fields: [serviceId], references: [id], onDelete: SetNull)
offeringId String?
offering Offering? @relation(fields: [offeringId], references: [id], onDelete: SetNull)
requestedDate DateTime?
requestedTime String?
deliveryAddress String?
estimatedAmount Int?
extraData Json?
note String?
adminNote String?
status BookingStatus @default(received)
workflowKey String @default("booking.basic")
workflowVersion String @default("1.0.0")
currentState String @default("received")
isRead Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
items BookingItem[]
tags BookingTag[]
stateTransitions BookingStateTransition[]
@@index([brandId, status, createdAt])
@@index([customerUserId, createdAt])
}
model BookingStateTransition {
id String @id @default(uuid())
bookingId String
booking Booking @relation(fields: [bookingId], references: [id], onDelete: Cascade)
workflowKey String
workflowVersion String
fromState String?
toState String
actorRole String
createdAt DateTime @default(now())
@@index([bookingId, createdAt])
}
model BookingItem {
id String @id @default(uuid())
bookingId String
booking Booking @relation(fields: [bookingId], references: [id], onDelete: Cascade)
serviceId String?
service Service? @relation(fields: [serviceId], references: [id], onDelete: SetNull)
offeringId String?
offering Offering? @relation(fields: [offeringId], references: [id], onDelete: SetNull)
serviceNameSnapshot String
unitPriceSnapshot Int
quantity Int
subtotalSnapshot Int
}
model Tag {
id String @id @default(uuid())
brandId String
brand BrandProfile @relation(fields: [brandId], references: [id])
name String
isPreset Boolean @default(false)
isEnabled Boolean @default(true)
createdAt DateTime @default(now())
bookings BookingTag[]
@@unique([brandId, name])
}
model AdminUser {
id String @id @default(uuid())
username String @unique
passwordHash String
displayName String
role String @default("admin")
isEnabled Boolean @default(true)
lastLoginAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model BookingTag {
bookingId String
tagId String
booking Booking @relation(fields: [bookingId], references: [id], onDelete: Cascade)
tag Tag @relation(fields: [tagId], references: [id], onDelete: Cascade)
@@id([bookingId, tagId])
}