79 lines
2.0 KiB
Plaintext
79 lines
2.0 KiB
Plaintext
datasource db {
|
|
provider = "postgresql"
|
|
url = env("DATABASE_URL")
|
|
}
|
|
|
|
generator client {
|
|
provider = "prisma-client-js"
|
|
}
|
|
|
|
enum MovementKind {
|
|
Receipt
|
|
Issue
|
|
Transfer
|
|
Adjustment
|
|
}
|
|
|
|
model ProductType {
|
|
id String @id @default(uuid())
|
|
name String @unique
|
|
products Product[]
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
@@map("product_types")
|
|
}
|
|
|
|
model Product {
|
|
id String @id @default(uuid())
|
|
name String
|
|
productType ProductType @relation(fields: [productTypeId], references: [id])
|
|
productTypeId String
|
|
parent Product? @relation("ProductHierarchy", fields: [parentId], references: [id])
|
|
parentId String?
|
|
children Product[] @relation("ProductHierarchy")
|
|
stockStatus StockStatus?
|
|
lines StockMovementLine[]
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
@@map("products")
|
|
}
|
|
|
|
model StockStatus {
|
|
product Product @relation(fields: [productId], references: [id])
|
|
productId String @id @unique
|
|
quantity Decimal @default(0)
|
|
inStock Boolean @default(false)
|
|
updatedAt DateTime @default(now()) @updatedAt
|
|
|
|
@@map("stock_statuses")
|
|
}
|
|
|
|
model StockMovement {
|
|
id String @id @default(uuid())
|
|
documentDate DateTime @db.Date
|
|
kind MovementKind
|
|
lines StockMovementLine[]
|
|
comment String?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
@@map("stock_movements")
|
|
}
|
|
|
|
model StockMovementLine {
|
|
id String @id @default(uuid())
|
|
product Product @relation(fields: [productId], references: [id])
|
|
productId String
|
|
quantity Decimal
|
|
inStock Boolean
|
|
movement StockMovement @relation(fields: [movementId], references: [id])
|
|
movementId String
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
@@unique([movementId, productId])
|
|
@@map("stock_movement_lines")
|
|
}
|