Files
photoreport/apps/api/prisma/schema.prisma
T
2026-10-12 00:35:21 +01:00

909 lines
35 KiB
Plaintext

// PhotoReport database schema. Every row owned by someone carries organization_id (AGENTS.md rule 4).
generator client {
provider = "prisma-client"
output = "../src/generated/prisma"
}
datasource db {
provider = "postgresql"
}
enum OrganizationMode {
AGENCY // photos belong to the organization; only admins grant access
INDEPENDENT // a photographer working on their own account
}
enum Role {
OWNER
ADMIN
EDITOR
INGESTER
PHOTOGRAPHER
CLIENT
}
enum ClientKind {
WEB
DESKTOP
}
model User {
id String @id @default(uuid()) @db.Uuid
email String @unique // stored lower-cased
name String
passwordHash String @map("password_hash")
locale String @default("pt-PT")
emailVerifiedAt DateTime? @map("email_verified_at")
disabledAt DateTime? @map("disabled_at")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
memberships Membership[]
sessions Session[]
preferences UserPreferences?
deviceGrants DeviceAuthorization[]
assignments EventAssignment[]
uploads Photo[]
ftpAccounts FtpAccount[]
edits PhotoEdit[]
@@map("users")
}
model Organization {
id String @id @default(uuid()) @db.Uuid
slug String @unique
name String
mode OrganizationMode @default(AGENCY)
/// Face recognition is biometric data: off unless enabled with a recorded legal basis.
biometricsEnabled Boolean @default(false) @map("biometrics_enabled")
biometricsLegalBasis String? @map("biometrics_legal_basis")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
memberships Membership[]
events Event[]
photos Photo[]
codeLists CodeList[]
ftpAccounts FtpAccount[]
targets DeliveryTarget[]
people Person[]
faces Face[]
faceGroups FaceGroup[]
deliveries DeliveryItem[]
sites Site[]
galleries Gallery[]
products Product[]
orders Order[]
/// Shop: Stripe keys (AES-GCM sealed, like delivery passwords). Payments go to the organization's account.
stripeSecretSealed String? @map("stripe_secret_sealed")
stripeWebhookSealed String? @map("stripe_webhook_sealed")
/// Seller details printed on orders: legal name and VAT number (NIF).
legalName String? @map("legal_name")
vatNumber String? @map("vat_number")
/// The seller's country (ISO 3166-1 alpha-2) and VAT rate (percent) for sales without reverse charge.
country String @default("PT")
vatRate Float @default(23) @map("vat_rate")
printEvents PrintEvent[]
printStations PrintStation[]
printers Printer[]
printJobs PrintJob[]
jerseySamples JerseySample[]
@@map("organizations")
}
model Membership {
id String @id @default(uuid()) @db.Uuid
userId String @map("user_id") @db.Uuid
organizationId String @map("organization_id") @db.Uuid
role Role
createdAt DateTime @default(now()) @map("created_at")
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
@@unique([userId, organizationId])
@@index([organizationId])
@@map("memberships")
}
/// One refresh-token chain per login. Tokens rotate on every refresh; presenting a rotated token again
/// revokes the whole family (stolen-token detection).
model Session {
id String @id @default(uuid()) @db.Uuid
userId String @map("user_id") @db.Uuid
familyId String @map("family_id") @db.Uuid
tokenHash String @unique @map("token_hash")
clientKind ClientKind @map("client_kind")
deviceLabel String? @map("device_label")
createdAt DateTime @default(now()) @map("created_at")
expiresAt DateTime @map("expires_at")
rotatedAt DateTime? @map("rotated_at")
revokedAt DateTime? @map("revoked_at")
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@index([familyId])
@@index([userId])
@@map("sessions")
}
/// OAuth-style device authorization (RFC 8628) used by the desktop app to sign in through the browser.
model DeviceAuthorization {
id String @id @default(uuid()) @db.Uuid
deviceCodeHash String @unique @map("device_code_hash")
userCode String @unique @map("user_code")
clientLabel String? @map("client_label")
intervalSec Int @default(5) @map("interval_sec")
createdAt DateTime @default(now()) @map("created_at")
expiresAt DateTime @map("expires_at")
lastPolledAt DateTime? @map("last_polled_at")
approvedUserId String? @map("approved_user_id") @db.Uuid
approvedAt DateTime? @map("approved_at")
deniedAt DateTime? @map("denied_at")
consumedAt DateTime? @map("consumed_at")
approvedUser User? @relation(fields: [approvedUserId], references: [id], onDelete: Cascade)
@@map("device_authorizations")
}
/// Per-user settings that follow the user across web and desktop.
model UserPreferences {
userId String @id @map("user_id") @db.Uuid
editorModules String[] @default(["crop", "basic"]) @map("editor_modules")
updatedAt DateTime @updatedAt @map("updated_at")
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@map("user_preferences")
}
enum PhotoFlag {
NONE
PICK
REJECT
}
enum ColorLabel {
NONE
RED
YELLOW
GREEN
BLUE
PURPLE
}
enum PhotoStatus {
PROCESSING
READY
FAILED
}
enum PhotoSource {
FTP
UPLOAD
DESKTOP
}
/// A match or other coverage. Admins and editors create it with the details every template needs.
model Event {
id String @id @default(uuid()) @db.Uuid
organizationId String @map("organization_id") @db.Uuid
home String
away String
homeShort String? @map("home_short")
awayShort String? @map("away_short")
venue String?
city String?
sport String?
competition String?
competitionCode String? @map("competition_code")
round String?
matchNumber String? @map("match_number")
startsAt DateTime @map("starts_at")
/// Photos captured between ingest_from and ingest_until by an assigned photographer land here.
ingestFrom DateTime @map("ingest_from")
ingestUntil DateTime @map("ingest_until")
/// IPTC template (packages/metadata IptcTemplate), filled for every photo of the event.
iptcTemplate Json @map("iptc_template")
createdById String? @map("created_by_id") @db.Uuid
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
archivedAt DateTime? @map("archived_at")
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
assignments EventAssignment[]
photos Photo[]
deliveries DeliveryItem[]
faceGroups FaceGroup[]
galleries Gallery[]
@@index([organizationId, startsAt])
@@map("events")
}
/// The agenda: which photographers cover which event (set by admins and editors).
model EventAssignment {
eventId String @map("event_id") @db.Uuid
userId String @map("user_id") @db.Uuid
event Event @relation(fields: [eventId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@id([eventId, userId])
@@index([userId])
@@map("event_assignments")
}
/// An FTP/SFTP login (SFTPGo). Files under <INGEST_ROOT>/<login>/ belong to this user and organization.
model FtpAccount {
id String @id @default(uuid()) @db.Uuid
organizationId String @map("organization_id") @db.Uuid
userId String @map("user_id") @db.Uuid
login String @unique
/// Seconds to add to the camera clock (cameras drift; set once per body).
clockOffsetSec Int @default(0) @map("clock_offset_sec")
/// Argon2 hash of the FTP password; SFTPGo asks the API to check it (external authentication hook).
passwordHash String? @map("password_hash")
lastLoginAt DateTime? @map("last_login_at")
createdAt DateTime @default(now()) @map("created_at")
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@map("ftp_accounts")
}
model Photo {
id String @id @default(uuid()) @db.Uuid
organizationId String @map("organization_id") @db.Uuid
/// Null while no event matches (the editor's inbox).
eventId String? @map("event_id") @db.Uuid
uploaderId String? @map("uploader_id") @db.Uuid
source PhotoSource
originalName String @map("original_name")
sha256 String
byteSize Int @map("byte_size")
storageKey String @map("storage_key")
status PhotoStatus @default(PROCESSING)
error String?
width Int?
height Int?
capturedAt DateTime? @map("captured_at")
cameraMake String? @map("camera_make")
cameraModel String? @map("camera_model")
cameraSerial String? @map("camera_serial")
lens String?
focalLength Float? @map("focal_length")
aperture Float?
exposureTime Float? @map("exposure_time")
iso Int?
rating Int @default(0)
flag PhotoFlag @default(NONE)
colorLabel ColorLabel @default(NONE) @map("color_label")
/// Names of the people in the photo (go to IPTC Title and Persons Shown).
players String[] @default([])
/// Per-photo IPTC overrides on top of the event template (packages/metadata IptcTemplate).
iptcOverrides Json? @map("iptc_overrides")
/// IPTC found in the file as it arrived (camera presets or an earlier caption), for reference.
embeddedIptc Json? @map("embedded_iptc")
/// Face analysis: NONE (organization without biometrics), PENDING, DONE or FAILED.
facesStatus FacesStatus @default(NONE) @map("faces_status")
/// Last op-log sequence number (0: never edited).
developSeq Int @default(0) @map("develop_seq")
/// Develop settings replayed up to `snapshotSeq` by the render worker (LightCraft JSON); clients
/// replay the ops after it.
developSnapshot Json? @map("develop_snapshot")
snapshotSeq Int @default(0) @map("snapshot_seq")
/// Edited thumb/preview: PENDING after an edit, rendered by the worker once edits pause.
renderStatus RenderStatus @default(NONE) @map("render_status")
/// The op-log sequence the edited thumb/preview show (0: they show the original).
renderedSeq Int @default(0) @map("rendered_seq")
editedAt DateTime? @map("edited_at")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
event Event? @relation(fields: [eventId], references: [id], onDelete: SetNull)
uploader User? @relation(fields: [uploaderId], references: [id], onDelete: SetNull)
deliveries DeliveryItem[]
faces Face[]
edits PhotoEdit[]
galleries GalleryPhoto[]
orderItems OrderItem[]
/// The same file sent twice (FTP retries, two cards) is stored once.
@@unique([organizationId, sha256])
@@index([eventId, capturedAt])
@@index([organizationId, eventId])
@@map("photos")
}
enum RenderStatus {
NONE
PENDING
RUNNING
DONE
FAILED
}
/// The develop op log: every edit command, in the order the server accepted it. Last writer wins per control.
model PhotoEdit {
id String @id @default(uuid()) @db.Uuid
photoId String @map("photo_id") @db.Uuid
seq Int
/// Client-generated id: a retried send (offline queue) is stored once.
opId String @map("op_id")
/// The window that sent it, so it can skip its own echo.
clientId String @map("client_id")
command Json
userId String? @map("user_id") @db.Uuid
createdAt DateTime @default(now()) @map("created_at")
photo Photo @relation(fields: [photoId], references: [id], onDelete: Cascade)
user User? @relation(fields: [userId], references: [id], onDelete: SetNull)
@@unique([photoId, seq])
@@unique([photoId, opId])
@@map("photo_edits")
}
/// Code replacements (`\v7\`), one list per organization, kept as the tab-separated text people edit.
model CodeList {
id String @id @default(uuid()) @db.Uuid
organizationId String @map("organization_id") @db.Uuid
name String
content String
updatedAt DateTime @updatedAt @map("updated_at")
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
@@unique([organizationId, name])
@@map("code_lists")
}
enum DeliveryKind {
NEXTCLOUD
}
enum DeliveryStatus {
QUEUED
RUNNING
DONE
FAILED
}
/// Where a client's photos go, and how folders and files are named there (each client has its own rules).
model DeliveryTarget {
id String @id @default(uuid()) @db.Uuid
organizationId String @map("organization_id") @db.Uuid
name String
kind DeliveryKind @default(NEXTCLOUD)
/// e.g. https://cloud.photoreport.pt
baseUrl String @map("base_url")
username String
/// App password, encrypted with DELIVERY_SECRET_KEY (AES-256-GCM). Never returned by the API.
secretEnc String @map("secret_enc")
folderTemplate String @map("folder_template")
fileNameTemplate String @map("file_name_template")
longEdge Int @default(4000) @map("long_edge")
jpegQuality Int @default(100) @map("jpeg_quality")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
disabledAt DateTime? @map("disabled_at")
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
items DeliveryItem[]
@@unique([organizationId, name])
@@map("delivery_targets")
}
/// One photo on its way to one target. The queue retries with back-off; a failure never blocks the rest.
model DeliveryItem {
id String @id @default(uuid()) @db.Uuid
organizationId String @map("organization_id") @db.Uuid
targetId String @map("target_id") @db.Uuid
photoId String @map("photo_id") @db.Uuid
eventId String @map("event_id") @db.Uuid
/// Position in this event's delivery to this target: the {n} in file names. Never reused.
sequence Int
status DeliveryStatus @default(QUEUED)
attempts Int @default(0)
lastError String? @map("last_error")
remotePath String? @map("remote_path")
byteSize Int? @map("byte_size")
requestedById String? @map("requested_by_id") @db.Uuid
nextAttemptAt DateTime @default(now()) @map("next_attempt_at")
startedAt DateTime? @map("started_at")
finishedAt DateTime? @map("finished_at")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
target DeliveryTarget @relation(fields: [targetId], references: [id], onDelete: Cascade)
photo Photo @relation(fields: [photoId], references: [id], onDelete: Cascade)
event Event @relation(fields: [eventId], references: [id], onDelete: Cascade)
@@unique([targetId, eventId, sequence])
@@index([status, nextAttemptAt])
@@index([organizationId, targetId, createdAt])
@@map("delivery_items")
}
enum FacesStatus {
NONE
PENDING
RUNNING
DONE
FAILED
}
/// Someone photographed again and again: a player, a coach, a referee. Named by an editor, once.
model Person {
id String @id @default(uuid()) @db.Uuid
organizationId String @map("organization_id") @db.Uuid
name String
club String?
number String?
/// Mean face embedding of everything confirmed as this person (unit length), per recognition model.
centroid Float[] @default([])
model String?
faceCount Int @default(0) @map("face_count")
/// A reference photo (squad headshot) so the person is suggested from the first match on.
referenceKey String? @map("reference_key")
referenceStatus FacesStatus @default(NONE) @map("reference_status")
referenceEmbedding Float[] @default([]) @map("reference_embedding")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
groups FaceGroup[] @relation("confirmed")
suggested FaceGroup[] @relation("suggested")
@@unique([organizationId, name])
@@map("people")
}
/// Faces of one person within one event, grouped automatically. Confirming a group names every photo in it,
/// and later photos that join the group are named as they arrive.
model FaceGroup {
id String @id @default(uuid()) @db.Uuid
organizationId String @map("organization_id") @db.Uuid
eventId String @map("event_id") @db.Uuid
personId String? @map("person_id") @db.Uuid
suggestedPersonId String? @map("suggested_person_id") @db.Uuid
suggestionScore Float? @map("suggestion_score")
/// Not someone to name (public, staff): kept so their faces stop showing up.
ignoredAt DateTime? @map("ignored_at")
centroid Float[] @default([])
model String
size Int @default(0)
confirmedById String? @map("confirmed_by_id") @db.Uuid
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
event Event @relation(fields: [eventId], references: [id], onDelete: Cascade)
person Person? @relation("confirmed", fields: [personId], references: [id], onDelete: SetNull)
suggested Person? @relation("suggested", fields: [suggestedPersonId], references: [id], onDelete: SetNull)
faces Face[]
@@index([eventId])
@@map("face_groups")
}
model Face {
id String @id @default(uuid()) @db.Uuid
organizationId String @map("organization_id") @db.Uuid
photoId String @map("photo_id") @db.Uuid
groupId String? @map("group_id") @db.Uuid
/// Box in fractions of the photo (0 to 1, y down).
x0 Float
y0 Float
x1 Float
y1 Float
score Float
/// Variance of the Laplacian of the aligned face; below MIN_SHARPNESS the face is kept but not grouped.
sharpness Float?
/// Unit-length embedding from `model`; empty when the face was too small or turned to align.
embedding Float[] @default([])
model String
/// Shirt number read under the face by the jersey model (null: not run, or not legible) and its confidence.
jerseyNumber String? @map("jersey_number")
jerseyScore Float? @map("jersey_score")
createdAt DateTime @default(now()) @map("created_at")
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
photo Photo @relation(fields: [photoId], references: [id], onDelete: Cascade)
group FaceGroup? @relation(fields: [groupId], references: [id], onDelete: SetNull)
jerseySample JerseySample?
@@index([photoId])
@@index([groupId])
@@map("faces")
}
/// A public website of an organization (photoreport.pt, shootyourmove.com...). The domain picks the
/// organization, the skin and the texts; every skin shows the same galleries and shop.
model Site {
id String @id @default(uuid()) @db.Uuid
organizationId String @map("organization_id") @db.Uuid
domain String @unique
/// Skin: "photoreport" (editorial, light) or "shootyourmove" (dark, red).
skin String @default("photoreport")
name String
/// Free settings per skin: tagline, contact email, social links, accent colour.
settings Json @default("{}")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
orders Order[]
@@map("sites")
}
enum GalleryVisibility {
/// Listed on the site.
PUBLIC
/// Reachable by link only.
UNLISTED
/// Link plus password (clients, teams, families).
PRIVATE
}
model Gallery {
id String @id @default(uuid()) @db.Uuid
organizationId String @map("organization_id") @db.Uuid
eventId String? @map("event_id") @db.Uuid
slug String
title String
description String?
visibility GalleryVisibility @default(PUBLIC)
passwordHash String? @map("password_hash")
coverPhotoId String? @map("cover_photo_id") @db.Uuid
/// Unpublished galleries are only visible in the app.
publishedAt DateTime? @map("published_at")
/// Selling switched off: a news gallery, or a client gallery paid upfront (downloads free).
forSale Boolean @default(true) @map("for_sale")
freeDownloads Boolean @default(false) @map("free_downloads")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
event Event? @relation(fields: [eventId], references: [id], onDelete: SetNull)
photos GalleryPhoto[]
@@unique([organizationId, slug])
@@index([organizationId, publishedAt])
@@map("galleries")
}
model GalleryPhoto {
galleryId String @map("gallery_id") @db.Uuid
photoId String @map("photo_id") @db.Uuid
position Int
addedAt DateTime @default(now()) @map("added_at")
gallery Gallery @relation(fields: [galleryId], references: [id], onDelete: Cascade)
photo Photo @relation(fields: [photoId], references: [id], onDelete: Cascade)
@@id([galleryId, photoId])
@@index([galleryId, position])
@@map("gallery_photos")
}
enum ProductKind {
/// A JPEG to download, at `longEdge` px (0: full size).
DIGITAL
/// A print, made and sent (or handed over) by the organization.
PRINT
}
model Product {
id String @id @default(uuid()) @db.Uuid
organizationId String @map("organization_id") @db.Uuid
kind ProductKind
name String
longEdge Int? @map("long_edge")
/// Print size label (15x20, 20x30...).
printSize String? @map("print_size")
/// Gross price (VAT included) in cents, as shown to consumers.
priceCents Int @map("price_cents")
/// Working days until a print ships.
leadDays Int? @map("lead_days")
active Boolean @default(true)
position Int @default(0)
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
orderItems OrderItem[]
@@map("products")
}
enum OrderStatus {
/// Created, waiting for the payment (Multibanco references can take days).
PENDING
PAID
/// Downloads ready and prints shipped.
FULFILLED
CANCELLED
REFUNDED
}
model Order {
id String @id @default(uuid()) @db.Uuid
organizationId String @map("organization_id") @db.Uuid
siteId String? @map("site_id") @db.Uuid
/// Human order number per organization (PR-2026-000123).
number String
status OrderStatus @default(PENDING)
email String
name String
/// Buyer's VAT number (with country prefix) when buying as a company.
vatNumber String? @map("vat_number")
/// Buyer's country (ISO alpha-2).
country String
/// EU business buyer with a VIES-valid number in another member state: VAT reverse-charged.
reverseCharge Boolean @default(false) @map("reverse_charge")
viesName String? @map("vies_name")
currency String @default("EUR")
netCents Int @map("net_cents")
vatCents Int @map("vat_cents")
totalCents Int @map("total_cents")
/// Secret for the buyer's order page and downloads (sent by email; never listed).
accessToken String @unique @map("access_token")
provider String @default("stripe")
providerRef String? @map("provider_ref")
checkoutUrl String? @map("checkout_url")
paidAt DateTime? @map("paid_at")
fulfilledAt DateTime? @map("fulfilled_at")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
site Site? @relation(fields: [siteId], references: [id], onDelete: SetNull)
items OrderItem[]
@@unique([organizationId, number])
@@index([organizationId, createdAt])
@@map("orders")
}
enum FulfilmentStatus {
PENDING
RUNNING
READY
SHIPPED
FAILED
}
model OrderItem {
id String @id @default(uuid()) @db.Uuid
orderId String @map("order_id") @db.Uuid
photoId String? @map("photo_id") @db.Uuid
productId String? @map("product_id") @db.Uuid
/// Copied at purchase: later price or product changes never alter an order.
productName String @map("product_name")
kind ProductKind
longEdge Int? @map("long_edge")
quantity Int
unitCents Int @map("unit_cents")
vatRate Float @map("vat_rate")
totalCents Int @map("total_cents")
status FulfilmentStatus @default(PENDING)
/// Rendered download (DIGITAL), relative to storage.
fileKey String? @map("file_key")
downloads Int @default(0)
error String?
updatedAt DateTime @updatedAt @map("updated_at")
order Order @relation(fields: [orderId], references: [id], onDelete: Cascade)
photo Photo? @relation(fields: [photoId], references: [id], onDelete: SetNull)
product Product? @relation(fields: [productId], references: [id], onDelete: SetNull)
@@index([orderId])
@@index([status])
@@map("order_items")
}
/// A party, wedding, corporate event or match day where guests get prints on the spot (events.photoreport.pt).
model PrintEvent {
id String @id @default(uuid()) @db.Uuid
organizationId String @map("organization_id") @db.Uuid
slug String @unique
name String
startsAt DateTime? @map("starts_at")
endsAt DateTime? @map("ends_at")
/// Guests open the QR page while this is on.
active Boolean @default(true)
/// Jobs wait for an operator's OK before printing (photo booths at sensitive events).
requireApproval Boolean @default(false) @map("require_approval")
/// Prints per guest (0: no limit).
guestLimit Int @default(0) @map("guest_limit")
/// Price per print paid by the guest before it prints (Stripe; 0: free).
priceCents Int @default(0) @map("price_cents")
/// Print size (15x20, 10x15, 20x30) and the frame: band text, colours, border.
size String @default("15x20")
template Json @default("{}")
/// Guests can also pick from the photographer's photos of this gallery (kiosk / web gallery).
galleryId String? @map("gallery_id") @db.Uuid
/// The printer jobs go to unless an operator moves them.
printerId String? @map("printer_id") @db.Uuid
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
printer Printer? @relation(fields: [printerId], references: [id], onDelete: SetNull)
jobs PrintJob[]
@@map("print_events")
}
/// A computer next to the printers running apps/print-agent, paired with a one-time code.
model PrintStation {
id String @id @default(uuid()) @db.Uuid
organizationId String @map("organization_id") @db.Uuid
name String
/// One-time pairing code (hashed) and its expiry, until the agent pairs.
pairingHash String? @unique @map("pairing_hash")
pairingExpires DateTime? @map("pairing_expires")
/// SHA-256 of the agent's bearer token.
tokenHash String? @unique @map("token_hash")
platform String?
agentVersion String? @map("agent_version")
lastSeenAt DateTime? @map("last_seen_at")
createdAt DateTime @default(now()) @map("created_at")
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
printers Printer[]
@@map("print_stations")
}
model Printer {
id String @id @default(uuid()) @db.Uuid
organizationId String @map("organization_id") @db.Uuid
stationId String @map("station_id") @db.Uuid
/// The operating system's queue name (CUPS `lpstat -p`), reported by the agent.
systemName String @map("system_name")
name String
/// Sizes loaded (the operator says which media is in it).
sizes String[] @default(["15x20"])
enabled Boolean @default(true)
/// Last state the agent saw: idle, printing, error text.
state String?
updatedAt DateTime @updatedAt @map("updated_at")
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
station PrintStation @relation(fields: [stationId], references: [id], onDelete: Cascade)
jobs PrintJob[]
events PrintEvent[]
@@unique([stationId, systemName])
@@map("printers")
}
enum PrintJobStatus {
/// Waiting for the guest to pay (events with a price).
PAYMENT
/// Waiting for an operator (events with approval).
APPROVAL
QUEUED
/// Taken by an agent.
PRINTING
DONE
FAILED
CANCELLED
}
model PrintJob {
id String @id @default(uuid()) @db.Uuid
organizationId String @map("organization_id") @db.Uuid
printEventId String @map("print_event_id") @db.Uuid
printerId String? @map("printer_id") @db.Uuid
/// GUEST (phone upload), GALLERY (a photographer's photo), OPERATOR (sent from the app).
source String
photoId String? @map("photo_id") @db.Uuid
/// The print-ready file (template applied, 300 dpi), relative to storage.
fileKey String @map("file_key")
size String
copies Int @default(1)
status PrintJobStatus @default(QUEUED)
guestName String? @map("guest_name")
/// The guest's browser: limits per guest and lets the guest follow the job.
guestKey String? @map("guest_key")
/// Stripe Checkout session of a paid print.
paymentRef String? @map("payment_ref")
error String?
attempts Int @default(0)
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
printedAt DateTime? @map("printed_at")
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
printEvent PrintEvent @relation(fields: [printEventId], references: [id], onDelete: Cascade)
printer Printer? @relation(fields: [printerId], references: [id], onDelete: SetNull)
@@index([printEventId, createdAt])
@@index([status, printerId])
@@map("print_jobs")
}
/// A browser/desktop upload sent in chunks, so a dropped connection resumes where it stopped.
model PendingUpload {
id String @id @default(uuid()) @db.Uuid
organizationId String @map("organization_id") @db.Uuid
userId String @map("user_id") @db.Uuid
eventId String? @map("event_id") @db.Uuid
fileName String @map("file_name")
size Int
/// Client-side identity of the file (name, size, modified time): the same file after a reload resumes.
fingerprint String
offset Int @default(0)
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@index([userId, fingerprint])
@@map("pending_uploads")
}
enum JerseySampleStatus {
/// Made from a confirmed face and the squad's number; waiting for a person to check it.
PENDING
/// The number is right (or was corrected): training data.
CONFIRMED
/// The number cannot be read on this crop (back turned, covered, blurred): also training data, as "not legible".
ILLEGIBLE
/// Not a shirt at all (wrong crop): left out of training.
SKIPPED
}
/**
* Training data for the shirt-number model: the torso under a confirmed face, labelled with the number the squad
* gives that person, checked by a person in the app.
*/
model JerseySample {
id String @id @default(uuid()) @db.Uuid
organizationId String @map("organization_id") @db.Uuid
faceId String @unique @map("face_id") @db.Uuid
photoId String @map("photo_id") @db.Uuid
personId String? @map("person_id") @db.Uuid
/// Torso box in fractions of the photo.
x0 Float
y0 Float
x1 Float
y1 Float
/// The number the squad says (the starting point), and the checked one.
suggested String?
label String?
status JerseySampleStatus @default(PENDING)
reviewedById String? @map("reviewed_by_id") @db.Uuid
reviewedAt DateTime? @map("reviewed_at")
createdAt DateTime @default(now()) @map("created_at")
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
face Face @relation(fields: [faceId], references: [id], onDelete: Cascade)
@@index([organizationId, status])
@@map("jersey_samples")
}
/// What was brought over from the old systems (app.photoreport.pt), so an import can run again without duplicating.
model LegacyImport {
source String
kind String
legacyId String @map("legacy_id")
targetId String @map("target_id")
createdAt DateTime @default(now()) @map("created_at")
@@id([source, kind, legacyId])
@@map("legacy_imports")
}