36 lines
1.9 KiB
Plaintext
36 lines
1.9 KiB
Plaintext
model PackagingRun {
|
|
id String @id @default(uuid()) @db.Uuid
|
|
organizationId String @map("organization_id") @db.Uuid
|
|
batchId String @unique @map("batch_id") @db.Uuid
|
|
bomId String @map("bom_id") @db.Uuid
|
|
recordedById String @map("recorded_by_id") @db.Uuid
|
|
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, organizationId], references: [id, organizationId], onDelete: Restrict)
|
|
bom ProductBom @relation(fields: [bomId, organizationId], references: [id, organizationId], onDelete: Restrict)
|
|
recordedBy User @relation(fields: [recordedById, organizationId], references: [id, organizationId], onDelete: Restrict)
|
|
lines PackagingRunLine[]
|
|
@@unique([organizationId, idempotencyKey])
|
|
@@unique([batchId, organizationId])
|
|
@@unique([id, bomId, organizationId])
|
|
@@index([organizationId, createdAt, id])
|
|
@@map("packaging_runs")
|
|
}
|
|
|
|
model PackagingRunLine {
|
|
id String @id @default(uuid()) @db.Uuid
|
|
organizationId String @map("organization_id") @db.Uuid
|
|
runId String @map("run_id") @db.Uuid
|
|
bomId String @map("bom_id") @db.Uuid
|
|
bomLineId String @map("bom_line_id") @db.Uuid
|
|
usedQuantity Decimal @map("used_quantity") @db.Decimal(12,3)
|
|
wastedQuantity Decimal @map("wasted_quantity") @db.Decimal(12,3)
|
|
wasteReason String? @map("waste_reason") @db.VarChar(500)
|
|
run PackagingRun @relation(fields: [runId, bomId, organizationId], references: [id, bomId, organizationId], onDelete: Restrict)
|
|
bomLine ProductBomLine @relation(fields: [bomLineId, bomId, organizationId], references: [id, bomId, organizationId], onDelete: Restrict)
|
|
@@unique([runId, bomLineId])
|
|
@@map("packaging_run_lines")
|
|
}
|