Files
vtuber/packages/db/prisma/schema.prisma

246 lines
6.3 KiB
Plaintext

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
enum OrderStatus {
PENDING
PAID
SHIPPED
CANCELLED
}
enum TeamRole {
HOST
PRODUCER
DIRECTOR
EDITOR
SUPPORT
WAREHOUSE
MARKETING
OPERATOR
}
enum LiveRoomStatus {
PLANNING
LIVE
FINISHED
CANCELLED
}
enum OrderSource {
WEB
LIVE
}
model User {
id String @id @default(cuid())
email String @unique
name String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
orders Order[]
carts Cart[]
messages LiveMessage[]
}
model LiveTeamMember {
id String @id @default(cuid())
displayName String
nickname String?
role TeamRole
phone String?
email String?
notes String?
isActive Boolean @default(true)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
assignments LiveRoomRoleAssignment[]
}
model Product {
id String @id @default(cuid())
name String
slug String @unique
description String?
imageUrl String?
basePrice Int
isActive Boolean @default(true)
liveRoomId String?
liveRoom LiveRoom? @relation(fields: [liveRoomId], references: [id], onDelete: SetNull)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
variants ProductVariant[]
}
model ProductVariant {
id String @id @default(cuid())
productId String
sku String @unique
name String
size String?
price Int
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
inventory Inventory?
orderItems OrderItem[]
cartItems CartItem[]
messages LiveMessage[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Inventory {
id String @id @default(cuid())
productVariantId String @unique
productVariant ProductVariant @relation(fields: [productVariantId], references: [id], onDelete: Cascade)
quantity Int @default(0)
reserved Int @default(0)
updatedAt DateTime @updatedAt
}
model Order {
id String @id @default(cuid())
orderNumber String @unique @default(cuid())
userId String?
user User? @relation(fields: [userId], references: [id], onDelete: SetNull)
status OrderStatus @default(PENDING)
orderSource OrderSource @default(WEB)
totalAmount Int
liveRoomId String?
liveRoom LiveRoom? @relation(fields: [liveRoomId], references: [id], onDelete: SetNull)
items OrderItem[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model OrderItem {
id String @id @default(cuid())
orderId String
productVariantId String
quantity Int
unitPrice Int
order Order @relation(fields: [orderId], references: [id], onDelete: Cascade)
variant ProductVariant @relation(fields: [productVariantId], references: [id], onDelete: Cascade)
}
model LiveRoom {
id String @id @default(cuid())
title String
hostName String
description String?
status LiveRoomStatus @default(PLANNING)
streamUrl String?
liveGoal String?
plannedStartAt DateTime?
plannedEndAt DateTime?
isActive Boolean @default(true)
startedAt DateTime?
endedAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
products Product[]
messages LiveMessage[]
assignments LiveRoomRoleAssignment[]
scripts LiveRoomScript[]
checklists LiveRoomChecklistItem[]
orders Order[]
}
model LiveMessage {
id String @id @default(cuid())
liveRoomId String
userId String?
userName String
message String
productVariantId String?
createdAt DateTime @default(now())
liveRoom LiveRoom @relation(fields: [liveRoomId], references: [id], onDelete: Cascade)
user User? @relation(fields: [userId], references: [id], onDelete: SetNull)
productVariant ProductVariant? @relation(fields: [productVariantId], references: [id], onDelete: SetNull)
}
model Cart {
id String @id @default(cuid())
userId String?
sessionId String?
user User? @relation(fields: [userId], references: [id], onDelete: SetNull)
items CartItem[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([userId, sessionId])
}
model CartItem {
id String @id @default(cuid())
cartId String
productVariantId String
quantity Int
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
cart Cart @relation(fields: [cartId], references: [id], onDelete: Cascade)
variant ProductVariant @relation(fields: [productVariantId], references: [id], onDelete: Cascade)
@@unique([cartId, productVariantId])
}
model LiveRoomRoleAssignment {
id String @id @default(cuid())
liveRoomId String
teamMemberId String
role TeamRole
isPrimary Boolean @default(false)
shiftStartAt DateTime?
shiftEndAt DateTime?
note String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
liveRoom LiveRoom @relation(fields: [liveRoomId], references: [id], onDelete: Cascade)
teamMember LiveTeamMember @relation(fields: [teamMemberId], references: [id], onDelete: Cascade)
@@unique([liveRoomId, teamMemberId])
}
model LiveRoomScript {
id String @id @default(cuid())
liveRoomId String
sequence Int
cue String?
title String
content String
ownerRole TeamRole?
targetProductId String?
isDone Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
liveRoom LiveRoom @relation(fields: [liveRoomId], references: [id], onDelete: Cascade)
}
model LiveRoomChecklistItem {
id String @id @default(cuid())
liveRoomId String
title String
ownerRole TeamRole
description String?
isRequired Boolean @default(true)
isDone Boolean @default(false)
note String?
completedAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
liveRoom LiveRoom @relation(fields: [liveRoomId], references: [id], onDelete: Cascade)
}