135 lines
3.5 KiB
Plaintext
135 lines
3.5 KiB
Plaintext
|
|
generator client {
|
||
|
|
provider = "prisma-client-js"
|
||
|
|
}
|
||
|
|
|
||
|
|
datasource db {
|
||
|
|
provider = "sqlite"
|
||
|
|
url = env("DATABASE_URL")
|
||
|
|
}
|
||
|
|
|
||
|
|
model Vendor {
|
||
|
|
id String @id @default(cuid())
|
||
|
|
name String
|
||
|
|
businessNum String?
|
||
|
|
taxSettings String? // JSON string
|
||
|
|
createdAt DateTime @default(now())
|
||
|
|
updatedAt DateTime @updatedAt
|
||
|
|
|
||
|
|
users User[]
|
||
|
|
categories Category[]
|
||
|
|
products Product[]
|
||
|
|
taxes Tax[]
|
||
|
|
transactions Transaction[]
|
||
|
|
}
|
||
|
|
|
||
|
|
model Role {
|
||
|
|
id String @id @default(cuid())
|
||
|
|
name String @unique // cashier | manager | owner
|
||
|
|
|
||
|
|
users User[]
|
||
|
|
}
|
||
|
|
|
||
|
|
model User {
|
||
|
|
id String @id @default(cuid())
|
||
|
|
email String @unique
|
||
|
|
passwordHash String
|
||
|
|
name String
|
||
|
|
vendorId String
|
||
|
|
roleId String
|
||
|
|
createdAt DateTime @default(now())
|
||
|
|
updatedAt DateTime @updatedAt
|
||
|
|
|
||
|
|
vendor Vendor @relation(fields: [vendorId], references: [id])
|
||
|
|
role Role @relation(fields: [roleId], references: [id])
|
||
|
|
refreshTokens RefreshToken[]
|
||
|
|
transactions Transaction[]
|
||
|
|
}
|
||
|
|
|
||
|
|
model RefreshToken {
|
||
|
|
id String @id @default(cuid())
|
||
|
|
token String @unique
|
||
|
|
userId String
|
||
|
|
expiresAt DateTime
|
||
|
|
createdAt DateTime @default(now())
|
||
|
|
|
||
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||
|
|
}
|
||
|
|
|
||
|
|
model Category {
|
||
|
|
id String @id @default(cuid())
|
||
|
|
name String
|
||
|
|
vendorId String
|
||
|
|
createdAt DateTime @default(now())
|
||
|
|
updatedAt DateTime @updatedAt
|
||
|
|
|
||
|
|
vendor Vendor @relation(fields: [vendorId], references: [id])
|
||
|
|
products Product[]
|
||
|
|
}
|
||
|
|
|
||
|
|
model Tax {
|
||
|
|
id String @id @default(cuid())
|
||
|
|
name String
|
||
|
|
rate Float
|
||
|
|
vendorId String
|
||
|
|
createdAt DateTime @default(now())
|
||
|
|
updatedAt DateTime @updatedAt
|
||
|
|
|
||
|
|
vendor Vendor @relation(fields: [vendorId], references: [id])
|
||
|
|
products Product[]
|
||
|
|
}
|
||
|
|
|
||
|
|
model Product {
|
||
|
|
id String @id @default(cuid())
|
||
|
|
name String
|
||
|
|
sku String?
|
||
|
|
description String?
|
||
|
|
price Float
|
||
|
|
vendorId String
|
||
|
|
categoryId String?
|
||
|
|
taxId String?
|
||
|
|
tags String? // comma-separated or JSON string
|
||
|
|
version Int @default(1)
|
||
|
|
createdAt DateTime @default(now())
|
||
|
|
updatedAt DateTime @updatedAt
|
||
|
|
|
||
|
|
vendor Vendor @relation(fields: [vendorId], references: [id])
|
||
|
|
category Category? @relation(fields: [categoryId], references: [id])
|
||
|
|
tax Tax? @relation(fields: [taxId], references: [id])
|
||
|
|
transactionItems TransactionItem[]
|
||
|
|
}
|
||
|
|
|
||
|
|
model Transaction {
|
||
|
|
id String @id @default(cuid())
|
||
|
|
idempotencyKey String @unique
|
||
|
|
vendorId String
|
||
|
|
userId String
|
||
|
|
status String // pending | completed | failed | refunded
|
||
|
|
paymentMethod String // cash | card
|
||
|
|
subtotal Float
|
||
|
|
taxTotal Float
|
||
|
|
discountTotal Float
|
||
|
|
total Float
|
||
|
|
notes String?
|
||
|
|
createdAt DateTime @default(now())
|
||
|
|
updatedAt DateTime @updatedAt
|
||
|
|
|
||
|
|
vendor Vendor @relation(fields: [vendorId], references: [id])
|
||
|
|
user User @relation(fields: [userId], references: [id])
|
||
|
|
items TransactionItem[]
|
||
|
|
}
|
||
|
|
|
||
|
|
model TransactionItem {
|
||
|
|
id String @id @default(cuid())
|
||
|
|
transactionId String
|
||
|
|
productId String
|
||
|
|
productName String
|
||
|
|
quantity Int
|
||
|
|
unitPrice Float
|
||
|
|
taxRate Float
|
||
|
|
discount Float
|
||
|
|
total Float
|
||
|
|
|
||
|
|
transaction Transaction @relation(fields: [transactionId], references: [id])
|
||
|
|
product Product @relation(fields: [productId], references: [id])
|
||
|
|
}
|