manicanldes-backend/prisma/material-usage.prisma

27 lines
1.5 KiB
Plaintext

enum MaterialUsageKind {
CONSUMED
WASTED
}
model ProductionMaterialUsage {
id String @id @default(uuid()) @db.Uuid
organizationId String @map("organization_id") @db.Uuid
batchId String @map("batch_id") @db.Uuid
bomId String @map("bom_id") @db.Uuid
bomLineId String @map("bom_line_id") @db.Uuid
recordedById String @map("recorded_by_id") @db.Uuid
kind MaterialUsageKind
quantity Decimal @db.Decimal(12,3)
reason String? @db.VarChar(500)
idempotencyKey String @map("idempotency_key") @db.Uuid
requestHash String @map("request_hash") @db.Char(64)
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Restrict)
batch ProductionBatch @relation(fields: [batchId, bomId, organizationId], references: [id, bomId, organizationId], onDelete: Restrict, map: "production_material_usage_batch_scope_fkey")
bomLine ProductBomLine @relation(fields: [bomLineId, bomId, organizationId], references: [id, bomId, organizationId], onDelete: Restrict, map: "production_material_usage_line_scope_fkey")
recordedBy User @relation(fields: [recordedById, organizationId], references: [id, organizationId], onDelete: Restrict, map: "production_material_usage_actor_scope_fkey")
@@unique([organizationId, idempotencyKey], map: "production_material_usage_idempotency_key")
@@index([organizationId, batchId, createdAt, id], map: "production_material_usage_batch_created_idx")
@@map("production_material_usage")
}