document-designs.prisma 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /// A look for a document, saved under a name: the arrangement the designer
  2. /// edits and the colours and type around it. A workshop keeps several, one
  3. /// of them in use by default, and points an invoice or a customer at another
  4. /// when the default is wrong for them: a business that becomes GST registered
  5. /// keeps "Invoice" for its old paper and prints "Tax Invoice" from now on.
  6. ///
  7. /// Rows used to live as one JSON list in a settings row. They are rows now
  8. /// because invoices and customers reference them, and a reference into a
  9. /// blob cannot be kept honest by the database.
  10. model DocumentDesign {
  11. id String @id @default(cuid())
  12. organizationId String
  13. organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
  14. /// invoice | quote
  15. documentType String
  16. name String
  17. /// InvoiceLayoutConfig as saved, before defaults are merged in.
  18. layout Json
  19. /// DesignerTemplate: the colours, type, header style and logo.
  20. template Json
  21. /// Picks this design by itself for one kind of job, when neither the
  22. /// invoice nor its customer chose one. Today only parts_sale, a job with
  23. /// no vehicle; vehicle jobs are what the default already covers. Null
  24. /// means only when chosen. One design per rule, which the unique index
  25. /// below keeps honest; see designRules.ts.
  26. autoRule String?
  27. createdAt DateTime @default(now())
  28. updatedAt DateTime @updatedAt
  29. serviceRecords ServiceRecord[]
  30. customers Customer[]
  31. @@unique([organizationId, documentType, autoRule])
  32. @@index([organizationId, documentType])
  33. @@map("document_designs")
  34. }
  35. /// A design exactly as it was when a document was issued, kept once per
  36. /// distinct content and shared by every document issued with it. An issued
  37. /// invoice reads its look from here and never from the live design, so
  38. /// editing or deleting a design cannot change paper a customer already holds.
  39. /// The hash is over the canonical JSON of layout and template, so the same
  40. /// design issued a thousand times costs one row.
  41. model DocumentDesignSnapshot {
  42. id String @id @default(cuid())
  43. organizationId String
  44. organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
  45. hash String
  46. layout Json
  47. template Json
  48. createdAt DateTime @default(now())
  49. serviceRecords ServiceRecord[]
  50. inspections Inspection[]
  51. @@unique([organizationId, hash])
  52. @@map("document_design_snapshots")
  53. }
  54. /// A file as it was when a document was issued: the logo, and the signature
  55. /// of whoever issued it. The upload route deletes the previous logo when a
  56. /// new one arrives and a member can redraw their signature, so a reference to
  57. /// the live one would leave old paper printing the new mark, or none. Keyed
  58. /// by content hash for the same reason as the design snapshots.
  59. model DocumentAssetSnapshot {
  60. id String @id @default(cuid())
  61. organizationId String
  62. organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
  63. hash String
  64. mimeType String
  65. data Bytes
  66. createdAt DateTime @default(now())
  67. serviceRecords ServiceRecord[] @relation("IssuedLogoSnapshot")
  68. signedServiceRecords ServiceRecord[] @relation("IssuedSignatureSnapshot")
  69. signedInspections Inspection[]
  70. @@unique([organizationId, hash])
  71. @@map("document_asset_snapshots")
  72. }