manicanldes-backend/prisma/documents.prisma

67 lines
3.0 KiB
Plaintext

enum SupplierDocumentKind {
REGISTRATION
TAX_CERTIFICATE
COMPLIANCE_CERTIFICATE
OTHER
}
enum SupplierDocumentOutcome {
APPROVED
REJECTED
}
model SupplierDocument {
id String @id @default(uuid()) @db.Uuid
organizationId String @map("organization_id") @db.Uuid
supplierId String @map("supplier_id") @db.Uuid
createdById String @map("created_by_id") @db.Uuid
code String @db.VarChar(32)
kind SupplierDocumentKind
title String @db.VarChar(160)
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Restrict)
supplier Supplier @relation(fields: [supplierId, organizationId], references: [id, organizationId], onDelete: Restrict)
createdBy User @relation(fields: [createdById, organizationId], references: [id, organizationId], onDelete: Restrict)
versions SupplierDocumentVersion[]
@@unique([organizationId, supplierId, code])
@@unique([id, organizationId])
@@index([organizationId, supplierId, createdAt, id], map: "supplier_documents_supplier_created_idx")
@@map("supplier_documents")
}
model SupplierDocumentVersion {
id String @id @default(uuid()) @db.Uuid
organizationId String @map("organization_id") @db.Uuid
documentId String @map("document_id") @db.Uuid
uploadedById String @map("uploaded_by_id") @db.Uuid
version Int
filename String @db.VarChar(120)
mimeType String @map("mime_type") @db.VarChar(32)
sha256 String @db.Char(64)
size Int
content Bytes @db.ByteA
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Restrict)
document SupplierDocument @relation(fields: [documentId, organizationId], references: [id, organizationId], onDelete: Restrict)
uploadedBy User @relation(fields: [uploadedById, organizationId], references: [id, organizationId], onDelete: Restrict)
decision SupplierDocumentDecision?
@@unique([documentId, version])
@@unique([id, organizationId])
@@index([organizationId, documentId, version])
@@map("supplier_document_versions")
}
model SupplierDocumentDecision {
versionId String @id @map("version_id") @db.Uuid
organizationId String @map("organization_id") @db.Uuid
validatedById String @map("validated_by_id") @db.Uuid
outcome SupplierDocumentOutcome
reason String? @db.VarChar(500)
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Restrict)
version SupplierDocumentVersion @relation(fields: [versionId, organizationId], references: [id, organizationId], onDelete: Restrict, map: "supplier_document_decision_version_scope_fkey")
validatedBy User @relation(fields: [validatedById, organizationId], references: [id, organizationId], onDelete: Restrict, map: "supplier_document_decision_actor_scope_fkey")
@@unique([versionId, organizationId])
@@map("supplier_document_decisions")
}