188 lines
4.9 KiB
Plaintext
188 lines
4.9 KiB
Plaintext
generator client {
|
|
provider = "prisma-client-js"
|
|
}
|
|
|
|
datasource db {
|
|
provider = "postgresql"
|
|
url = env("DATABASE_URL")
|
|
}
|
|
|
|
// ─── Auth (NextAuth v5) ────────────────────────────────────────────────────
|
|
|
|
model User {
|
|
id String @id @default(cuid())
|
|
name String?
|
|
email String @unique
|
|
emailVerified DateTime?
|
|
image String?
|
|
role Role @default(CUSTOMER)
|
|
password String?
|
|
|
|
accounts Account[]
|
|
sessions Session[]
|
|
orders Order[]
|
|
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
}
|
|
|
|
model Account {
|
|
id String @id @default(cuid())
|
|
userId String
|
|
type String
|
|
provider String
|
|
providerAccountId String
|
|
refresh_token String?
|
|
access_token String?
|
|
expires_at Int?
|
|
token_type String?
|
|
scope String?
|
|
id_token String?
|
|
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 String
|
|
expires DateTime
|
|
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
}
|
|
|
|
model VerificationToken {
|
|
identifier String
|
|
token String
|
|
expires DateTime
|
|
|
|
@@unique([identifier, token])
|
|
}
|
|
|
|
enum Role {
|
|
CUSTOMER
|
|
ADMIN
|
|
}
|
|
|
|
// ─── Katalog ──────────────────────────────────────────────────────────────
|
|
|
|
model Category {
|
|
id String @id @default(cuid())
|
|
name String
|
|
slug String @unique
|
|
description String?
|
|
image String?
|
|
products Product[]
|
|
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
}
|
|
|
|
model Product {
|
|
id String @id @default(cuid())
|
|
name String
|
|
slug String @unique
|
|
description String?
|
|
image String?
|
|
published Boolean @default(false)
|
|
categoryId String
|
|
|
|
category Category @relation(fields: [categoryId], references: [id])
|
|
variants ProductVariant[]
|
|
orderItems OrderItem[]
|
|
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
}
|
|
|
|
model ProductVariant {
|
|
id String @id @default(cuid())
|
|
name String
|
|
price Int // cena v haléřích (CZK)
|
|
stock Int @default(0)
|
|
sku String? @unique
|
|
productId String
|
|
|
|
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
|
|
cartItems CartItem[]
|
|
orderItems OrderItem[]
|
|
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
}
|
|
|
|
// ─── Košík ────────────────────────────────────────────────────────────────
|
|
|
|
model Cart {
|
|
id String @id @default(cuid())
|
|
sessionId String? @unique // pro guest uživatele
|
|
userId String? @unique // pro přihlášené
|
|
items CartItem[]
|
|
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
}
|
|
|
|
model CartItem {
|
|
id String @id @default(cuid())
|
|
cartId String
|
|
variantId String
|
|
quantity Int
|
|
|
|
cart Cart @relation(fields: [cartId], references: [id], onDelete: Cascade)
|
|
variant ProductVariant @relation(fields: [variantId], references: [id])
|
|
|
|
@@unique([cartId, variantId])
|
|
}
|
|
|
|
// ─── Objednávky ───────────────────────────────────────────────────────────
|
|
|
|
model Order {
|
|
id String @id @default(cuid())
|
|
userId String?
|
|
guestEmail String?
|
|
status OrderStatus @default(PENDING)
|
|
totalAmount Int // v haléřích
|
|
stripeSessionId String? @unique
|
|
|
|
shippingName String
|
|
shippingEmail String
|
|
shippingPhone String?
|
|
shippingStreet String
|
|
shippingCity String
|
|
shippingZip String
|
|
shippingCountry String @default("CZ")
|
|
|
|
user User? @relation(fields: [userId], references: [id])
|
|
items OrderItem[]
|
|
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
}
|
|
|
|
model OrderItem {
|
|
id String @id @default(cuid())
|
|
orderId String
|
|
productId String
|
|
variantId String
|
|
quantity Int
|
|
unitPrice Int // cena v době objednávky (snapshot)
|
|
|
|
order Order @relation(fields: [orderId], references: [id], onDelete: Cascade)
|
|
product Product @relation(fields: [productId], references: [id])
|
|
variant ProductVariant @relation(fields: [variantId], references: [id])
|
|
}
|
|
|
|
enum OrderStatus {
|
|
PENDING
|
|
PAID
|
|
PROCESSING
|
|
SHIPPED
|
|
DELIVERED
|
|
CANCELLED
|
|
REFUNDED
|
|
}
|