2025-06-24 14:09:12 +08:00

131 lines
3.2 KiB
Plaintext

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {
id String @id @default(cuid())
email String @unique
username String @unique
password String
name String?
phone String?
address String?
isAdmin Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
orders Order[]
cartItems CartItem[]
conversations Conversation[]
@@map("users")
}
model ComponentType {
id String @id @default(cuid())
name String @unique // CPU、内存、硬盘、主板、显卡、机箱
description String?
components Component[]
@@map("component_types")
}
model Component {
id String @id @default(cuid())
name String
brand String
model String
price Float
description String?
imageUrl String?
stock Int @default(0)
specifications String? // JSON格式存储规格参数
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
componentTypeId String
componentType ComponentType @relation(fields: [componentTypeId], references: [id])
orderItems OrderItem[]
cartItems CartItem[]
@@map("components")
}
model Order {
id String @id @default(cuid())
orderNumber String @unique
totalAmount Float
status OrderStatus @default(PENDING)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
userId String
user User @relation(fields: [userId], references: [id])
orderItems OrderItem[]
@@map("orders")
}
model OrderItem {
id String @id @default(cuid())
quantity Int @default(1)
price Float
orderId String
order Order @relation(fields: [orderId], references: [id], onDelete: Cascade)
componentId String
component Component @relation(fields: [componentId], references: [id])
@@map("order_items")
}
model CartItem {
id String @id @default(cuid())
quantity Int @default(1)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
componentId String
component Component @relation(fields: [componentId], references: [id], onDelete: Cascade)
@@unique([userId, componentId]) // 一个用户对同一个商品只能有一条购物车记录
@@map("cart_items")
}
enum OrderStatus {
PENDING
CONFIRMED
PROCESSING
SHIPPED
DELIVERED
CANCELLED
}
model Conversation {
id String @id @default(cuid())
title String? // 对话标题,可以根据第一个用户消息生成
messages String // 存储完整的消息历史的JSON数据
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@map("conversations")
}