document-designs.prisma 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. @@unique([organizationId, hash])
  51. @@map("document_design_snapshots")
  52. }
  53. /// A file as it was when a document was issued. Today that is the logo: the
  54. /// upload route deletes the previous file when a new one arrives, so a path
  55. /// alone would leave old invoices printing the new mark, or none. Keyed by
  56. /// content hash for the same reason as the design snapshots.
  57. model DocumentAssetSnapshot {
  58. id String @id @default(cuid())
  59. organizationId String
  60. organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
  61. hash String
  62. mimeType String
  63. data Bytes
  64. createdAt DateTime @default(now())
  65. serviceRecords ServiceRecord[]
  66. @@unique([organizationId, hash])
  67. @@map("document_asset_snapshots")
  68. }