migration.sql 1.3 KB

123456789101112131415161718192021222324
  1. -- Edit lock for invoices and quotes.
  2. --
  3. -- Additive and nullable throughout. Locking is off until an org turns it on,
  4. -- so every existing document stays exactly as editable as it is today and
  5. -- nothing needs backfilling.
  6. --
  7. -- sentAt is deliberately separate from sharedAt: sharedAt tracks the public
  8. -- link and is cleared when the link is revoked, whereas having sent an invoice
  9. -- is not undone by withdrawing the link. Existing invoices leave it null, so
  10. -- an org that locks on "sent" locks only what it sends from now on. That is
  11. -- the safe direction to be wrong in: nothing already issued is frozen out of
  12. -- reach on the day the setting is switched on.
  13. ALTER TABLE "service_records" ADD COLUMN "sentAt" TIMESTAMP(3);
  14. ALTER TABLE "service_records" ADD COLUMN "editUnlockedAt" TIMESTAMP(3);
  15. ALTER TABLE "service_records" ADD COLUMN "editUnlockedById" TEXT;
  16. -- Quotes get the same sentAt so an admin unlock is spent when the quote is
  17. -- issued again, exactly as it is for invoices. Without it an unlocked quote
  18. -- would stay editable forever, because its status does not change when a
  19. -- corrected copy is re-sent and re-accepted.
  20. ALTER TABLE "quotes" ADD COLUMN "sentAt" TIMESTAMP(3);
  21. ALTER TABLE "quotes" ADD COLUMN "editUnlockedAt" TIMESTAMP(3);
  22. ALTER TABLE "quotes" ADD COLUMN "editUnlockedById" TEXT;