Files
stock-manager/prisma/schema.prisma
T

186 lines
4.9 KiB
Plaintext

// This is your Prisma schema file,
// learn more about the docs: https://pris.ly/d/prisma-schema
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init
generator client {
provider = "prisma-client"
output = "../src/generated/prisma"
binaryTargets = ["native", "debian-openssl-1.1.x"]
}
datasource db {
provider = "postgresql"
}
enum UserRole {
ADMIN
MANAGER
STAFF
VIEWER
}
model User {
id String @id @default(uuid())
username String @unique
name String
email String @unique
password String
role UserRole @default(STAFF)
isActive Boolean @default(true)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
movements Movement[]
assignments Assignment[]
person Person?
}
enum PersonDepartment {
IT
ENGINEERING
LOGISTICS
TRAFFIC
DRIVER
ADMINISTRATION
SALES
OTHER
}
model Person {
id String @id @default(uuid())
firstName String
lastName String
department PersonDepartment?
email String? @unique
phone String?
userId String? @unique
user User? @relation(fields: [userId], references: [id], onDelete: SetNull, onUpdate: Cascade)
isActive Boolean @default(true)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
assignments Assignment[]
movements Movement[]
@@index([lastName, firstName])
@@index([department])
}
model Category {
id String @id @default(uuid())
name String @unique
description String?
isActive Boolean @default(true)
items Item[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([name])
}
enum ItemStatus {
AVAILABLE
ASSIGNED
RESERVED
IN_REPAIR
BROKEN
STOLEN
DISPOSED
}
model Item {
id String @id @default(uuid())
name String @unique
description String?
categoryId String
category Category @relation(fields: [categoryId], references: [id])
stock Int @default(0)
minStock Int?
maxStock Int?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deletedAt DateTime?
movements Movement[]
assignments Assignment[]
assets Asset[]
@@index([categoryId])
}
model Asset {
id String @id @default(uuid())
itemId String?
item Item? @relation(fields: [itemId], references: [id])
serialNumber String @unique
deliveryNote String?
status ItemStatus @default(AVAILABLE)
notes String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
movements Movement[]
assignment Assignment?
@@index([serialNumber])
@@index([itemId])
@@index([status])
}
model Assignment {
id String @id @default(uuid())
quantity Int?
notes String?
itemId String?
item Item? @relation(fields: [itemId], references: [id], onDelete: SetNull, onUpdate: Cascade)
assetId String? @unique
asset Asset? @relation(fields: [assetId], references: [id], onDelete: SetNull, onUpdate: Cascade)
personId String?
person Person? @relation(fields: [personId], references: [id], onDelete: Cascade, onUpdate: Cascade)
assignmentDate DateTime @default(now())
returnDate DateTime?
createdBy String
createdUser User @relation(fields: [createdBy], references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
movement Movement[]
@@index([itemId])
@@index([assetId])
@@index([personId])
@@index([createdBy])
}
enum MovementType {
IN
OUT
ASSIGNMENT
RETURN
ADJUSTMENT
DELETED
}
model Movement {
id String @id @default(uuid())
type MovementType @default(IN)
quantity Int
details String?
notes String?
itemId String?
item Item? @relation(fields: [itemId], references: [id], onDelete: SetNull, onUpdate: Cascade)
assetId String?
asset Asset? @relation(fields: [assetId], references: [id], onDelete: SetNull, onUpdate: Cascade)
previousStock Int?
newStock Int?
personId String?
person Person? @relation(fields: [personId], references: [id], onDelete: SetNull, onUpdate: Cascade)
assignmentId String?
assignment Assignment? @relation(fields: [assignmentId], references: [id], onDelete: SetNull, onUpdate: Cascade)
userId String
user User @relation(fields: [userId], references: [id])
createdAt DateTime @default(now())
@@index([itemId])
@@index([assetId])
@@index([personId])
@@index([type])
@@index([userId])
}