Files
spark 454247364f
ci / rust (push) Successful in 6m40s
ci / typescript (push) Successful in 11m14s
feat(galleries): deliver a session as its own page on the site (#260)
A client gallery is its own module. It is built from an event and its photographs and opens at /cliente/<slug> on the events site.
2026-11-12 00:14:14 +00:00

2083 lines
89 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[]
siteGalleries SiteGallery[]
ftpAccounts FtpAccount[]
edits PhotoEdit[]
earnings Earning[]
payouts Payout[] @relation("PhotographerPayouts")
notifications Notification[]
@@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")
/// Interior brackets. Off: the area is hidden and its routes refuse work. Sports ingest is unchanged.
realEstateEnabled Boolean @default(false) @map("real_estate_enabled")
/// Workspace modules this organization has. Null: the areas that already existed (site galleries stay off).
appModules Json? @map("app_modules")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
/// Player-code generator settings (contracts CodeGeneratorSettings); null: defaults.
codeGenerator Json? @map("code_generator")
/// File name given to photos as they arrive by FTP or the desktop app (e.g. PS_{event}_{timesort}); null: keep
/// the camera's. An FTP login can have its own.
renameTemplate String? @map("rename_template")
memberships Membership[]
events Event[]
photos Photo[]
codeLists CodeList[]
ftpAccounts FtpAccount[]
targets DeliveryTarget[]
people Person[]
faces Face[]
faceGroups FaceGroup[]
deliveries DeliveryItem[]
sites Site[]
galleries Gallery[]
cloudSources CloudSource[]
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")
/// Photographers' default share of the net sales of their photos (percent; 0: no shares).
photographerSharePct Float @default(0) @map("photographer_share_pct")
/// Days an earning is held before it can be paid out (refund window).
earningsHoldDays Int @default(14) @map("earnings_hold_days")
/// Invoices for paid orders: "none" or "invoicexpress" (certified invoicing software, Portugal).
invoicingProvider String @default("none") @map("invoicing_provider")
/// InvoiceXpress account name (the subdomain) and API key (sealed).
invoicingAccount String? @map("invoicing_account")
invoicingKeySealed String? @map("invoicing_key_sealed")
/// Email the invoice to the buyer from the invoicing software.
invoicingEmail Boolean @default(true) @map("invoicing_email")
/// VAT exemption code printed on reverse-charged invoices (AT list; M40 for services to EU businesses).
reverseChargeCode String @default("M40") @map("reverse_charge_code")
/// Times a buyer can download each bought file (0: no limit); copied onto each order when it is made.
maxDownloads Int @default(20) @map("max_downloads")
ftpPlans FtpPlan[]
bundles Bundle[]
invoices Invoice[]
pressAccounts PressAccount[]
affiliates Affiliate[]
earnings Earning[]
payouts Payout[]
printEvents PrintEvent[]
printStations PrintStation[]
printers Printer[]
printJobs PrintJob[]
jerseySamples JerseySample[]
siteGalleries SiteGallery[]
siteGallerySets SiteGallerySet[]
siteGalleryPhotos SiteGalleryPhoto[]
siteGalleryShares SiteGalleryShare[]
siteGalleryReviews SiteGalleryReview[]
siteGalleryBrand SiteGalleryBrand?
@@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
/// Workspace modules for this person. Null: follow the role, inside what the organization has. Owners ignore this.
appModules Json? @map("app_modules")
/// Photographer's share of sales of their photos, in percent (null: the organization's default).
sharePct Float? @map("share_pct")
/// Stripe Connect account (under the organization's Stripe) that receives payouts by transfer.
stripeAccountId String? @map("stripe_account_id")
/// Set once Stripe says the account can receive transfers.
stripeReadyAt DateTime? @map("stripe_ready_at")
/// For payouts made by hand (bank transfer).
payoutIban String? @map("payout_iban")
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")
/// The person's calendar (secret iCal address), sealed with the secret box; the new-event form lists its entries.
calendarUrl String? @map("calendar_url")
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
/// Indexed from a Nextcloud archive (CloudSource): a preview here, the original stays in the cloud.
CLOUD
}
/// 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")
/// Autopilot settings (contracts AutopilotSettings); null: off.
autopilot Json?
/// Set when someone asks to analyse this event now: its photos jump the face queue (the backlog is oldest-first).
faceBoostedAt DateTime? @map("face_boosted_at")
/// The official match this event covers, and its teams (squads, names for codes, faces and numbers).
fixtureId String? @map("fixture_id") @db.Uuid
homeTeamId String? @map("home_team_id") @db.Uuid
awayTeamId String? @map("away_team_id") @db.Uuid
/// The match's page on fotos.zerozero.pt (game id), found from teams and time or chosen by hand.
zerozeroGameId String? @map("zerozero_game_id")
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)
fixture SportsFixture? @relation(fields: [fixtureId], references: [id], onDelete: SetNull)
homeTeam SportsTeam? @relation("eventHome", fields: [homeTeamId], references: [id], onDelete: SetNull)
awayTeam SportsTeam? @relation("eventAway", fields: [awayTeamId], references: [id], onDelete: SetNull)
assignments EventAssignment[]
photos Photo[]
deliveries DeliveryItem[]
faceGroups FaceGroup[]
galleries Gallery[]
siteGalleries SiteGallery[]
cloudFolders CloudFolder[]
/// FTP logins sending everything to this event, whatever the camera's clock says ("Receber FTP aqui").
ftpTargets FtpAccount[]
teamSides ArchiveTeamSide[]
@@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")
/// This photographer's own rename template (overrides the organisation's; "" keeps the camera names).
renameTemplate String? @map("rename_template")
/// The access plan (days, quotas); null: no limits.
planId String? @map("plan_id") @db.Uuid
/// The login stops working after this (from the plan's days, or set by hand); null: never.
expiresAt DateTime? @map("expires_at")
/// Everything this login sends goes to this event (chosen in the library), until `targetUntil`; else by the time.
targetEventId String? @map("target_event_id") @db.Uuid
targetUntil DateTime? @map("target_until")
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)
plan FtpPlan? @relation(fields: [planId], references: [id], onDelete: SetNull)
targetEvent Event? @relation(fields: [targetEventId], references: [id], onDelete: SetNull)
@@index([targetEventId])
@@map("ftp_accounts")
}
/// An FTP access package (the old app's "pacotes"): how long a login lasts and how much it can upload.
model FtpPlan {
id String @id @default(uuid()) @db.Uuid
organizationId String @map("organization_id") @db.Uuid
name String
description String?
/// Days a login lasts from when the plan is given or renewed (0: no end).
days Int @default(0)
/// Upload quota in MB and in files (0: no limit), enforced by SFTPGo.
quotaMb Int @default(0) @map("quota_mb")
quotaFiles Int @default(0) @map("quota_files")
sortOrder Int @default(0) @map("sort_order")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
accounts FtpAccount[]
@@index([organizationId])
@@map("ftp_plans")
}
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")
/// The name given on arrival by the rename template (Photo Mechanic's Live Ingest "Rename"), without the
/// extension; null keeps the camera's. Deliveries use it as {originalName}.
fileName String? @map("file_name")
/// SHA-256 of the original as shot (also when only a preview was sent: the desktop app declares it).
sha256 String
byteSize Int @map("byte_size")
storageKey String @map("storage_key")
/// False when the desktop app sent only a preview and keeps the original on the photographer's computer:
/// `storageKey` then holds that preview, and full-size exports need the original first.
originalStored Boolean @default(true) @map("original_stored")
status PhotoStatus @default(PROCESSING)
error String?
width Int?
height Int?
capturedAt DateTime? @map("captured_at")
/// When it was taken, or the game's start, or when the file arrived. Among photographs never read, face
/// analysis finishes the last month of this before the older archive. A second reading waits behind those.
takenAt DateTime @default(now()) @map("taken_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?
/// The rest of the camera's EXIF Photo Mechanic shows (exposure compensation, flash, metering, program, white
/// balance, 35 mm focal length, lens range, owner, artist, GPS...): src/ingest/exif.ts CameraExtra.
exif Json?
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")
/// Which squad-aware reread this photo has been sent through. 0: read before the season squads.
facesPass Int @default(0) @map("faces_pass")
/// When the event was asked to the front of the face queue. Null waits behind every boosted photo.
facesBoostedAt DateTime? @map("faces_boosted_at")
/// Autopilot queue (docs/photo-editing-rules.md): NONE unless the event's autopilot took this photo.
autopilotStatus FacesStatus @default(NONE) @map("autopilot_status")
/// What the autopilot saw and did: subject, crop, angle, frame score, burst decision.
autopilot Json? @map("autopilot")
/// 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[]
cloudFiles CloudFile[]
edits PhotoEdit[]
galleries GalleryPhoto[]
siteGalleryPhotos SiteGalleryPhoto[]
siteGalleryCovers SiteGallery[] @relation("siteGalleryCover")
galleryExclusions GalleryExclusion[]
favorites GalleryFavorite[]
comments GalleryComment[]
correction DevelopCorrection?
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")
}
/// How a person corrected the autopilot on one photo (docs/photo-editing-rules.md §4, learning): the difference
/// between the autopilot's settings and the final ones. The autopilot applies the consistent part of the recent
/// corrections for the same photographer (and venue, when there are enough there) to the next photos.
model DevelopCorrection {
photoId String @id @map("photo_id") @db.Uuid
organizationId String @map("organization_id") @db.Uuid
/// Whose photo it is (the uploader): styles are learnt per photographer.
photographerId String? @map("photographer_id") @db.Uuid
/// The event's venue, lower-cased (light differs from one pavilion to the next).
venue String?
/// Control id -> final minus autopilot.
deltas Json
/// Final crop area over the autopilot's (below 1: they crop tighter).
cropScale Float? @map("crop_scale")
updatedAt DateTime @updatedAt @map("updated_at")
photo Photo @relation(fields: [photoId], references: [id], onDelete: Cascade)
@@index([organizationId, photographerId, updatedAt])
@@map("develop_corrections")
}
/// 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
SFTP
FTP
DROPBOX
ZEROZERO
/// A folder on one of the organisation's computers: the desktop app there saves the rendered files.
LOCAL
/// SmugMug guest upload link (https://site.smugmug.com/upload/{album}/{key}).
SMUGMUG
}
enum DeliveryStatus {
QUEUED
RUNNING
/// LOCAL: rendered and kept on the server until the computer's desktop app takes it.
WAITING
DONE
FAILED
/// Taken back from the destination after the photo was rejected, un-picked, or cancelled before upload.
RETRACTED
}
/// 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)
/// NEXTCLOUD: https://cloud.photoreport.pt; SFTP: sftp://host[:port]; FTP: ftp:// or ftps://host[:port];
/// DROPBOX: https://www.dropbox.com (unused).
baseUrl String @map("base_url")
/// DROPBOX: the app key (empty when the secret is a long-lived access token).
username String
/// Password, app password, private key or Dropbox refresh token, encrypted with DELIVERY_SECRET_KEY
/// (AES-256-GCM). Never returned by the API.
secretEnc String @map("secret_enc")
/// SFTP: the server's host key (SHA-256), remembered on first contact and checked from then on.
hostFingerprint String? @map("host_fingerprint")
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")
/// Output sharpening after resizing, pixels per inch, camera EXIF kept, conversion to sRGB (as in Photo
/// Mechanic's uploader).
sharpen Boolean @default(false)
dpi Int @default(300)
keepExif Boolean @default(true) @map("keep_exif")
srgb Boolean @default(false)
/// The original as it arrived (no resizing, no recompression), with the metadata written into it and renamed:
/// a copy for one's own backup, like Photo Mechanic's Live Ingest destination.
originals Boolean @default(false)
/// Wait a little for faces when the pad/path needs `{players}` (automatic every-arrival or when opted in).
/// Off by default: a send the photographer asked for leaves at once; names can update the file later.
waitForFaces Boolean @default(false) @map("wait_for_faces")
/// Every photo that arrives (FTP, the desktop app, uploads) is sent here on its own, as soon as it is in an event.
onArrival Boolean @default(false) @map("on_arrival")
/// With `onArrival`: only the photos of these FTP logins (ids; empty: everyone's). The central FTP then works as
/// a relay to a photographer's computer, as if the camera had sent to the FTP there.
arrivalLogins String[] @default([]) @map("arrival_logins") @db.Uuid
/// With `originals`: the file exactly as it arrived (no metadata written), for a local Live Ingest to take.
untouched Boolean @default(false)
/// IPTC fields this client gets instead of the event's (packages/metadata IptcTemplate, partial; variables allowed):
/// e.g. the agency a photographer works for at this client in Creator, or `{players}` in Title. Applied last.
iptcOverrides Json? @map("iptc_overrides")
/// Everything sent here is also sent to this target (usually a folder on a computer), with this target's IPTC:
/// a local copy of what a client got. Same organization; null: none.
copyTargetId String? @map("copy_target_id") @db.Uuid
/// A folder on one computer that also receives every file this destination exports (FTP and the rest stay as
/// they are). Not for a LOCAL target. The desktop app of `localMachine` writes under this path.
localFolder String? @map("local_folder")
/// That computer's id (`delivery_machine`).
localMachine String? @map("local_machine")
/// Subfolders under `localFolder`. `{destination}` is this target's name.
localFolderTemplate String? @map("local_folder_template")
/// Set only on the hidden LOCAL target that holds those copies; points at the export it mirrors.
mirrorOfId String? @unique @map("mirror_of_id") @db.Uuid
/// Library colour that routes a photo to this delivery (paint → send here). Null: no colour route.
colorLabel ColorLabel? @map("color_label")
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[]
mirrorOf DeliveryTarget? @relation("LocalMirror", fields: [mirrorOfId], references: [id], onDelete: Cascade)
localMirror DeliveryTarget? @relation("LocalMirror")
@@unique([organizationId, name])
@@unique([organizationId, colorLabel])
@@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
/// A copy of a delivery to that target (its `copyTargetId`): written with that target's IPTC, so it is the same file.
viaTargetId String? @map("via_target_id") @db.Uuid
status DeliveryStatus @default(QUEUED)
attempts Int @default(0)
lastError String? @map("last_error")
remotePath String? @map("remote_path")
/// The photo's edit (op-log sequence) the delivered file shows: edited again after it, it is sent again.
deliveredSeq Int? @map("delivered_seq")
/// Being sent again after an edit: where the previous version is (the old file is removed once the new one lands).
replacesPath String? @map("replaces_path")
/// Queued to be taken back from the destination (the photo was rejected or un-picked): the worker removes it.
retract Boolean @default(false)
/// This send asked for the camera original (overrides the destination's resize recipe for this item only).
forceOriginals Boolean @default(false) @map("force_originals")
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")
/// The squad entry this person came from (kept in step when squads change).
sportsPlayerId String? @map("sports_player_id") @db.Uuid
/// Handball: the federation licence number (CIPA), when the person was added by it or seen on a match report.
licence String?
/// Face recognition turned off for this person (an archive editor): no centroid, no reference, never suggested;
/// still named by hand.
recognitionOffAt DateTime? @map("recognition_off_at")
recognitionOffBy String? @map("recognition_off_by")
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")
rejections FaceGroupRejection[]
@@unique([organizationId, name])
@@unique([organizationId, sportsPlayerId])
@@unique([organizationId, licence])
@@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[]
videoFaces VideoFace[]
rejections FaceGroupRejection[]
@@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")
/// The set of number crops its training samples were made with (`JERSEY_CROPS` in jersey/service.ts); 0: none yet.
jerseyCrops Int @default(0) @map("jersey_crops")
/// Median RGB of the kit under the face (chest): tells the two teams apart when both have a player with a number.
kitColour Float[] @default([]) @map("kit_colour")
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)
jerseySamples 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")
}
/// Live galleries fill themselves from their event while the match is on.
enum GalleryLive {
OFF
/// Photos flagged as picks (and taken out again when unpicked).
PICKS
/// Every photo of the event once it is ready (rejects left out).
ALL
}
enum CommentStatus {
PENDING
APPROVED
REJECTED
}
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")
live GalleryLive @default(OFF)
/// Clients mark favourites and comment on photos (selection for an album, prints, publication).
proofing Boolean @default(false)
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[]
exclusions GalleryExclusion[]
visitors GalleryVisitor[]
comments GalleryComment[]
bundles Bundle[]
views GalleryView[]
@@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
/// Added by the live mode (and removed by it when the photo stops matching).
auto Boolean @default(false)
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")
}
/// Visits to a gallery's public page, per day (the site's "Mais vistas"). One per browser session.
model GalleryView {
galleryId String @map("gallery_id") @db.Uuid
day DateTime @db.Date
views Int @default(0)
gallery Gallery @relation(fields: [galleryId], references: [id], onDelete: Cascade)
@@id([galleryId, day])
@@index([day])
@@map("gallery_views")
}
/// Photos taken out of a live gallery by hand: the live mode never adds them back.
model GalleryExclusion {
galleryId String @map("gallery_id") @db.Uuid
photoId String @map("photo_id") @db.Uuid
createdAt DateTime @default(now()) @map("created_at")
gallery Gallery @relation(fields: [galleryId], references: [id], onDelete: Cascade)
photo Photo @relation(fields: [photoId], references: [id], onDelete: Cascade)
@@id([galleryId, photoId])
@@map("gallery_exclusions")
}
/// Someone proofing a gallery (one per browser; name and email optional).
model GalleryVisitor {
id String @id @default(uuid()) @db.Uuid
galleryId String @map("gallery_id") @db.Uuid
name String?
email String?
createdAt DateTime @default(now()) @map("created_at")
lastSeenAt DateTime @default(now()) @map("last_seen_at")
gallery Gallery @relation(fields: [galleryId], references: [id], onDelete: Cascade)
favorites GalleryFavorite[]
comments GalleryComment[]
@@index([galleryId])
@@map("gallery_visitors")
}
model GalleryFavorite {
visitorId String @map("visitor_id") @db.Uuid
photoId String @map("photo_id") @db.Uuid
createdAt DateTime @default(now()) @map("created_at")
visitor GalleryVisitor @relation(fields: [visitorId], references: [id], onDelete: Cascade)
photo Photo @relation(fields: [photoId], references: [id], onDelete: Cascade)
@@id([visitorId, photoId])
@@index([photoId])
@@map("gallery_favorites")
}
/// A client's comment on one photo; others see it only once approved.
model GalleryComment {
id String @id @default(uuid()) @db.Uuid
galleryId String @map("gallery_id") @db.Uuid
visitorId String @map("visitor_id") @db.Uuid
photoId String @map("photo_id") @db.Uuid
body String
status CommentStatus @default(PENDING)
moderatedAt DateTime? @map("moderated_at")
moderatedById String? @map("moderated_by_id") @db.Uuid
createdAt DateTime @default(now()) @map("created_at")
gallery Gallery @relation(fields: [galleryId], references: [id], onDelete: Cascade)
visitor GalleryVisitor @relation(fields: [visitorId], references: [id], onDelete: Cascade)
photo Photo @relation(fields: [photoId], references: [id], onDelete: Cascade)
@@index([galleryId, status])
@@index([photoId])
@@map("gallery_comments")
}
/// A session delivered as its own page. Not a shop gallery and not a file delivery.
model SiteGallery {
id String @id @default(uuid()) @db.Uuid
organizationId String @map("organization_id") @db.Uuid
eventId String? @map("event_id") @db.Uuid
createdById String? @map("created_by_id") @db.Uuid
title String
dateLabel String @default("") @map("date_label")
/// Public address, unique across organizations: /cliente/<slug>.
slug String @unique
language String @default("pt")
passwordHash String? @map("password_hash")
favorites Boolean @default(true)
reviews Boolean @default(false)
/// SiteGalleryDesign.
design Json
/// StoredDownloads (the PIN is a hash).
downloads Json
coverPhotoId String? @map("cover_photo_id") @db.Uuid
publishedAt DateTime? @map("published_at")
offlineAt DateTime? @map("offline_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)
createdBy User? @relation(fields: [createdById], references: [id], onDelete: SetNull)
coverPhoto Photo? @relation("siteGalleryCover", fields: [coverPhotoId], references: [id], onDelete: SetNull)
sets SiteGallerySet[]
shares SiteGalleryShare[]
reviewRows SiteGalleryReview[]
views SiteGalleryView[]
@@index([organizationId])
@@map("site_galleries")
}
model SiteGallerySet {
id String @id @default(uuid()) @db.Uuid
organizationId String @map("organization_id") @db.Uuid
galleryId String @map("gallery_id") @db.Uuid
name String
position Int
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
gallery SiteGallery @relation(fields: [galleryId], references: [id], onDelete: Cascade)
photos SiteGalleryPhoto[]
@@index([galleryId, position])
@@map("site_gallery_sets")
}
model SiteGalleryPhoto {
setId String @map("set_id") @db.Uuid
photoId String @map("photo_id") @db.Uuid
organizationId String @map("organization_id") @db.Uuid
position Int
set SiteGallerySet @relation(fields: [setId], references: [id], onDelete: Cascade)
photo Photo @relation(fields: [photoId], references: [id], onDelete: Cascade)
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
@@id([setId, photoId])
@@index([photoId])
@@map("site_gallery_photos")
}
model SiteGalleryShare {
id String @id @default(uuid()) @db.Uuid
organizationId String @map("organization_id") @db.Uuid
galleryId String @map("gallery_id") @db.Uuid
email String
subject String
message String @default("")
/// Null when the message was kept but no mail server sent it.
sentAt DateTime? @map("sent_at")
createdAt DateTime @default(now()) @map("created_at")
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
gallery SiteGallery @relation(fields: [galleryId], references: [id], onDelete: Cascade)
@@index([galleryId, createdAt])
@@map("site_gallery_shares")
}
model SiteGalleryReview {
id String @id @default(uuid()) @db.Uuid
organizationId String @map("organization_id") @db.Uuid
galleryId String @map("gallery_id") @db.Uuid
name String
message String
recommends Boolean
createdAt DateTime @default(now()) @map("created_at")
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
gallery SiteGallery @relation(fields: [galleryId], references: [id], onDelete: Cascade)
@@index([galleryId, createdAt])
@@map("site_gallery_reviews")
}
model SiteGalleryView {
galleryId String @map("gallery_id") @db.Uuid
day DateTime @db.Date
views Int @default(0)
gallery SiteGallery @relation(fields: [galleryId], references: [id], onDelete: Cascade)
@@id([galleryId, day])
@@map("site_gallery_views")
}
/// The name and the contact a client gallery shows. One per organization.
model SiteGalleryBrand {
organizationId String @id @map("organization_id") @db.Uuid
studio String
contactEmail String? @map("contact_email")
instagram String?
website String?
termsUrl String? @map("terms_url")
privacyUrl String? @map("privacy_url")
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
@@map("site_gallery_brands")
}
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[]
bundles Bundle[]
@@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")
/// A press account's order: no payment at checkout, invoiced with the month's others.
pressAccountId String? @map("press_account_id") @db.Uuid
/// Times each file can be downloaded (0: no limit), from the organization's setting when the order was made.
maxDownloads Int @default(20) @map("max_downloads")
/// Who sent the buyer (`?ref=CODE` on a site), credited when the order is paid.
affiliateId String? @map("affiliate_id") @db.Uuid
refundedAt DateTime? @map("refunded_at")
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[]
affiliate Affiliate? @relation(fields: [affiliateId], references: [id], onDelete: SetNull)
earnings Earning[]
invoice Invoice?
pressAccount PressAccount? @relation(fields: [pressAccountId], references: [id], onDelete: SetNull)
@@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
/// Kiosk mode (a tablet at the event): SHA-256 of the secret in the kiosk link; null: no kiosk.
kioskTokenHash String? @map("kiosk_token_hash")
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)
/// Set when this upload is a preview standing in for an original kept on the desktop: {sha256, size, width, height}.
original Json?
/// An original sent by the desktop app's ingest (its local FTP): edited by the event's autopilot like FTP photos.
fromDesktop Boolean @default(false) @map("from_desktop")
/// Photo attributed to this org member (local FTP second photographer); null: `userId` (who uploaded).
uploaderUserId String? @map("uploader_user_id") @db.Uuid
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@index([userId, fingerprint])
@@map("pending_uploads")
}
/// Where a shirt-number crop is taken from, under the face.
enum JerseyRegion {
/// Chest and belly: the front number of handball (and most other) kits.
CHEST
/// Waist to mid-thigh: the front number of football kits (Liga Portugal shirts have none on the chest).
SHORTS
}
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 @map("face_id") @db.Uuid
/// Where on the player the crop is: football kits carry the front number on the shorts, handball on the chest.
region JerseyRegion @default(CHEST)
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)
@@unique([faceId, region])
@@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")
}
// ---------------------------------------------------------------------------------------------------------------
// Sports data: competitions, teams, squads and fixtures read from the federations (public facts, shared by all
// organisations, refreshed by the worker). Organisations turn them into code lists, people and events.
enum SportsProvider {
LIGA // ligaportugal.pt API (football: teams, squads with numbers and headshots, fixtures)
FPF // resultados.fpf.pt (football below the Liga: teams, fixtures, line-ups per match)
FPA // ws.fpa.pt (handball: teams and fixtures)
UEFA // match.uefa.com (club competitions: fixtures, referee teams, line-ups with numbers and headshots)
EHF // ehfcl/ehfel/ehfec.eurohandball.com (club handball: fixtures, match-sheet squads and staff)
}
model SportsCompetition {
id String @id @default(uuid()) @db.Uuid
provider SportsProvider
/// Liga: competition slug; FPF: competitionId; FPA: PROVA code (PO01).
externalId String @map("external_id")
sport String
name String
gender String?
/// Season being read, e.g. 20262027 (FPF: the site's seasonId).
season String
/// Read by the worker on its schedule.
active Boolean @default(true)
lastIngestAt DateTime? @map("last_ingest_at")
lastError String? @map("last_error")
counts Json?
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
teams SportsCompetitionTeam[]
fixtures SportsFixture[]
@@unique([provider, externalId])
@@map("sports_competitions")
}
model SportsTeam {
id String @id @default(uuid()) @db.Uuid
provider SportsProvider
externalId String @map("external_id")
sport String
name String
abbreviation String?
/// Lower-case, accent-free name with dashes; codes are derived from it (sl-benfica: b / slb).
slug String
logoUrl String? @map("logo_url")
/// The hall or stadium the club plays at.
venue String?
/// The club's town, kept apart from the stadium name.
city String?
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
competitions SportsCompetitionTeam[]
players SportsPlayer[]
homeFixtures SportsFixture[] @relation("home")
awayFixtures SportsFixture[] @relation("away")
homeEvents Event[] @relation("eventHome")
awayEvents Event[] @relation("eventAway")
@@unique([provider, externalId])
@@index([slug])
@@map("sports_teams")
}
model SportsCompetitionTeam {
competitionId String @map("competition_id") @db.Uuid
teamId String @map("team_id") @db.Uuid
season String
competition SportsCompetition @relation(fields: [competitionId], references: [id], onDelete: Cascade)
team SportsTeam @relation(fields: [teamId], references: [id], onDelete: Cascade)
@@id([competitionId, teamId, season])
@@map("sports_competition_teams")
}
model SportsPlayer {
id String @id @default(uuid()) @db.Uuid
teamId String @map("team_id") @db.Uuid
season String
externalId String? @map("external_id")
number String?
/// Name as printed (shirt name), used in captions.
name String
fullName String? @map("full_name")
position String?
photoUrl String? @map("photo_url")
birthDate String? @map("birth_date")
nationality String?
/// api: official squad; lineup: from a match sheet.
source String @default("api")
/// Not in the latest squad read (left the club); kept so old photos keep their names.
goneAt DateTime? @map("gone_at")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
team SportsTeam @relation(fields: [teamId], references: [id], onDelete: Cascade)
@@unique([teamId, season, name])
@@map("sports_players")
}
model SportsFixture {
id String @id @default(uuid()) @db.Uuid
competitionId String @map("competition_id") @db.Uuid
season String
externalId String @map("external_id")
homeTeamId String @map("home_team_id") @db.Uuid
awayTeamId String @map("away_team_id") @db.Uuid
startsAt DateTime @map("starts_at")
/// False when only the day is known.
timeKnown Boolean @default(true) @map("time_known")
round String?
matchNumber String? @map("match_number")
/// Stadium or hall, without the town.
venue String?
/// Town of the home club.
city String?
homeScore Int? @map("home_score")
awayScore Int? @map("away_score")
/// FPF and UEFA: when the line-ups were read from the match sheet.
lineupAt DateTime? @map("lineup_at")
/// The referee team ({name, role}[]), when the provider publishes it (UEFA).
officials Json?
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
competition SportsCompetition @relation(fields: [competitionId], references: [id], onDelete: Cascade)
homeTeam SportsTeam @relation("home", fields: [homeTeamId], references: [id], onDelete: Cascade)
awayTeam SportsTeam @relation("away", fields: [awayTeamId], references: [id], onDelete: Cascade)
events Event[]
@@unique([competitionId, externalId])
@@index([startsAt])
@@map("sports_fixtures")
}
/// Someone paid a commission on the sales they bring (a club, a blog, a team page): links carry `?ref=CODE`.
model Affiliate {
id String @id @default(uuid()) @db.Uuid
organizationId String @map("organization_id") @db.Uuid
name String
email String?
/// What goes in links (`?ref=`), upper-case, unique per organization.
code String
/// Commission on the order's net amount, in percent.
ratePct Float @default(10) @map("rate_pct")
active Boolean @default(true)
stripeAccountId String? @map("stripe_account_id")
stripeReadyAt DateTime? @map("stripe_ready_at")
payoutIban String? @map("payout_iban")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
orders Order[]
earnings Earning[]
payouts Payout[]
@@unique([organizationId, code])
@@map("affiliates")
}
enum EarningKind {
/// The photographer's share of a sold photo.
PHOTOGRAPHER
/// An affiliate's commission on an order they brought.
AFFILIATE
}
enum EarningStatus {
/// Owed; payable once `availableAt` has passed.
OPEN
PAID
/// The order was refunded before it was paid out.
CANCELLED
}
/// What a paid order owes to a photographer or an affiliate. Written when the order is paid; never changed by
/// later price or share changes.
model Earning {
id String @id @default(uuid()) @db.Uuid
organizationId String @map("organization_id") @db.Uuid
orderId String @map("order_id") @db.Uuid
orderItemId String? @map("order_item_id") @db.Uuid
kind EarningKind
photographerId String? @map("photographer_id") @db.Uuid
affiliateId String? @map("affiliate_id") @db.Uuid
/// Net amount (VAT excluded) the share is taken from, the rate, and the amount owed, in cents.
baseCents Int @map("base_cents")
ratePct Float @map("rate_pct")
amountCents Int @map("amount_cents")
status EarningStatus @default(OPEN)
availableAt DateTime @map("available_at")
payoutId String? @map("payout_id") @db.Uuid
createdAt DateTime @default(now()) @map("created_at")
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
order Order @relation(fields: [orderId], references: [id], onDelete: Cascade)
photographer User? @relation(fields: [photographerId], references: [id], onDelete: SetNull)
affiliate Affiliate? @relation(fields: [affiliateId], references: [id], onDelete: SetNull)
payout Payout? @relation(fields: [payoutId], references: [id], onDelete: SetNull)
/// One photographer earning per order line, one affiliate earning per order.
@@unique([orderItemId, kind])
@@unique([orderId, affiliateId])
@@index([organizationId, status, availableAt])
@@index([photographerId])
@@map("earnings")
}
enum PayoutStatus {
/// Being sent (a Stripe transfer in flight).
PENDING
PAID
FAILED
}
/// Money sent to one photographer or affiliate: a Stripe Connect transfer, or a bank transfer recorded by hand.
model Payout {
id String @id @default(uuid()) @db.Uuid
organizationId String @map("organization_id") @db.Uuid
photographerId String? @map("photographer_id") @db.Uuid
affiliateId String? @map("affiliate_id") @db.Uuid
amountCents Int @map("amount_cents")
currency String @default("EUR")
/// "stripe" or "manual".
method String
/// Stripe transfer id, or the bank transfer's reference.
reference String?
status PayoutStatus @default(PENDING)
error String?
createdById String? @map("created_by_id") @db.Uuid
createdAt DateTime @default(now()) @map("created_at")
paidAt DateTime? @map("paid_at")
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
photographer User? @relation("PhotographerPayouts", fields: [photographerId], references: [id], onDelete: SetNull)
affiliate Affiliate? @relation(fields: [affiliateId], references: [id], onDelete: SetNull)
earnings Earning[]
@@index([organizationId, createdAt])
@@map("payouts")
}
/// Something a person should know about (a sale of their photo, a comment to approve, a payout, a failed
/// delivery). Shown under the bell in the app; similar unread ones are folded into one (`key`, `count`).
model Notification {
id String @id @default(uuid()) @db.Uuid
userId String @map("user_id") @db.Uuid
organizationId String? @map("organization_id") @db.Uuid
/// photo_sold, order_paid, comment_pending, payout_paid, delivery_failed.
type String
/// What to fold on while unread (e.g. the gallery of pending comments, the delivery target).
key String?
count Int @default(1)
payload Json
readAt DateTime? @map("read_at")
createdAt DateTime @default(now()) @map("created_at")
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@index([userId, readAt, createdAt])
@@map("notifications")
}
enum InvoiceStatus {
/// Waiting to be issued (or to be tried again).
PENDING
ISSUED
/// Gave up after several tries: fix the settings and retry from the app.
FAILED
}
/// The certified invoice of a paid order, issued in the organization's invoicing software by the worker.
model Invoice {
id String @id @default(uuid()) @db.Uuid
organizationId String @map("organization_id") @db.Uuid
orderId String? @unique @map("order_id") @db.Uuid
/// A press account's monthly invoice: its orders of `period` (YYYY-MM).
pressAccountId String? @map("press_account_id") @db.Uuid
period String?
/// invoice_receipts (paid at once) or invoices (paid later).
kind String @default("invoice_receipts")
status InvoiceStatus @default(PENDING)
attempts Int @default(0)
nextAttemptAt DateTime @default(now()) @map("next_attempt_at")
/// The document in the invoicing software: id, number (e.g. FR 2026/12) and public link.
externalId String? @map("external_id")
number String?
url String?
error String?
totalCents Int @map("total_cents")
issuedAt DateTime? @map("issued_at")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
order Order? @relation(fields: [orderId], references: [id], onDelete: SetNull)
pressAccount PressAccount? @relation(fields: [pressAccountId], references: [id], onDelete: SetNull)
@@unique([pressAccountId, period])
@@index([status, nextAttemptAt])
@@index([organizationId, createdAt])
@@map("invoices")
}
/// A newspaper, agency or club that buys on account: it signs in on the site, orders without paying at checkout
/// and gets one invoice a month for everything it bought (payment within 30 days).
model PressAccount {
id String @id @default(uuid()) @db.Uuid
organizationId String @map("organization_id") @db.Uuid
name String
/// Billing: VAT number (NIF, with country prefix outside Portugal), country and address.
vatNumber String? @map("vat_number")
country String @default("PT")
address String?
/// Signs in on the site with this email and password; invoices go to it.
email String
passwordHash String @map("password_hash")
/// Off the listed prices, in percent.
discountPct Float @default(0) @map("discount_pct")
active Boolean @default(true)
lastLoginAt DateTime? @map("last_login_at")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
orders Order[]
invoices Invoice[]
@@unique([organizationId, email])
@@map("press_accounts")
}
/**
* A photo package (the old storefront's "pacotes"): N photos, or the whole gallery, at one price.
*/
model Bundle {
id String @id @default(uuid()) @db.Uuid
organizationId String @map("organization_id") @db.Uuid
/// Null: offered in every gallery of the organization.
galleryId String? @map("gallery_id") @db.Uuid
name String
/// The digital product (size) the photos come as.
productId String @map("product_id") @db.Uuid
/// Photos in the package; 0: the whole gallery.
photoCount Int @map("photo_count")
priceCents Int @map("price_cents")
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)
gallery Gallery? @relation(fields: [galleryId], references: [id], onDelete: Cascade)
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
@@index([organizationId])
@@map("bundles")
}
// ---------------------------------------------------------------------------------------------------------------
// Archive: photos that live on a Nextcloud, indexed for search, faces and galleries without copying the originals.
/// A Nextcloud folder the organization's archive is read from, with the account that sees it (an app password
/// from Nextcloud's login flow, sealed). One per cloud and root folder.
model CloudSource {
id String @id @default(uuid()) @db.Uuid
organizationId String @map("organization_id") @db.Uuid
name String
baseUrl String @map("base_url")
/// The Nextcloud login name (from the login flow); empty while the person has not authorised yet.
username String @default("")
secretEnc String? @map("secret_enc")
/// The folder indexed, from the account's root ("/FPA/Fotos").
rootPath String @map("root_path")
/// Who connected it: the photos count as theirs (uploader).
ownerId String? @map("owner_id") @db.Uuid
/// LOGIN (waiting for the person to authorise), READY, SCANNING, ERROR, PAUSED.
status String @default("LOGIN")
/// How the archive's site looks: "liga" (Liga Portugal), "fpa" (Federação de Andebol), or null (PhotoReport).
look String?
/// Editors on the cloud may upload a photo and search for that face across the archive (news desk). Off by default.
photoFindEnabled Boolean @default(false) @map("photo_find_enabled")
/// The archive's own address ("arquivo.ligaportugal.pt"): the site serves this archive at its root there.
hostname String? @unique
/// Nextcloud login flow v2: where to poll for the app password while status is LOGIN (sealed token).
loginPoll String? @map("login_poll")
loginExpires DateTime? @map("login_expires")
lastScanAt DateTime? @map("last_scan_at")
nextScanAt DateTime? @map("next_scan_at")
lastError String? @map("last_error")
/// When the worker last wrote this archive's teams. Null until that first write: the site keeps loading.
directoryBuiltAt DateTime? @map("directory_built_at")
/// Set when a match, a club alias or a known team changed. The worker rewrites the teams, then clears it.
directoryDirtyAt DateTime? @map("directory_dirty_at")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
folders CloudFolder[]
files CloudFile[]
videos CloudVideo[]
grants ArchiveGrant[]
faceActions ArchiveFaceAction[]
clubAliases ArchiveClubAlias[]
teamSides ArchiveTeamSide[]
@@index([organizationId])
@@map("cloud_sources")
}
/// A folder seen in a cloud source, by Nextcloud's file id (stable when moved or renamed). A folder with photos
/// is a gallery: matched to a game (and its event) from its name and place.
model CloudFolder {
id String @id @default(uuid()) @db.Uuid
sourceId String @map("source_id") @db.Uuid
fileId String @map("file_id")
path String
/// Nextcloud's etag: unchanged means nothing inside changed since the last scan (the walk skips it).
etag String?
parentId String? @map("parent_id") @db.Uuid
/// Images directly inside.
photoCount Int @default(0) @map("photo_count")
/// Videos directly inside (a gallery can hold photos, videos or both).
videoCount Int @default(0) @map("video_count")
eventId String? @map("event_id") @db.Uuid
/// How the event was found: FIXTURE (the official game), NAME (from the folder name), MANUAL, or null.
matchedBy String? @map("matched_by")
/// Its photos were taken on another day than the official game it was matched to: never matched to one again.
fixtureRejected Boolean @default(false) @map("fixture_rejected")
/// On the public archive site. The app's admin turns this off; the site has no control of its own. Default on.
published Boolean @default(true)
/// The gallery this folder belongs to. A game or a dated session takes the folders inside it; anything else
/// points at itself. Written when the folder is scanned or moved, and again on the periodic check. The site reads it.
galleryFolderId String? @map("gallery_folder_id") @db.Uuid
seenAt DateTime @default(now()) @map("seen_at")
createdAt DateTime @default(now()) @map("created_at")
source CloudSource @relation(fields: [sourceId], references: [id], onDelete: Cascade)
event Event? @relation(fields: [eventId], references: [id], onDelete: SetNull)
galleryFolder CloudFolder? @relation("GalleryMembers", fields: [galleryFolderId], references: [id], onDelete: SetNull)
galleryMembers CloudFolder[] @relation("GalleryMembers")
files CloudFile[]
videos CloudVideo[]
grants ArchiveGrantFolder[]
@@unique([sourceId, fileId])
@@index([sourceId, path])
@@index([parentId])
@@index([sourceId, galleryFolderId])
@@map("cloud_folders")
}
/// An image in a cloud source and its library photo once indexed (preview and metadata here, original there).
model CloudFile {
id String @id @default(uuid()) @db.Uuid
sourceId String @map("source_id") @db.Uuid
folderId String @map("folder_id") @db.Uuid
fileId String @map("file_id")
path String
etag String?
size BigInt?
/// The same picture in two folders (or twice in one) is one photo.
photoId String? @map("photo_id") @db.Uuid
/// PENDING (to index), DONE, FAILED.
status String @default("PENDING")
attempts Int @default(0)
error String?
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
source CloudSource @relation(fields: [sourceId], references: [id], onDelete: Cascade)
folder CloudFolder @relation(fields: [folderId], references: [id], onDelete: Cascade)
photo Photo? @relation(fields: [photoId], references: [id], onDelete: SetNull)
@@unique([sourceId, fileId])
@@index([status, sourceId])
@@index([photoId])
@@index([folderId, status, path])
@@map("cloud_files")
}
/// A video in an archive folder. The original stays on the cloud; the archive keeps a web copy (H.264 MP4, at most
/// 1080p, faststart), a poster and a thumbnail under `storageKey` (a folder: web.mp4, poster.jpg, thumb.jpg).
model CloudVideo {
id String @id @default(uuid()) @db.Uuid
sourceId String @map("source_id") @db.Uuid
folderId String @map("folder_id") @db.Uuid
fileId String @map("file_id")
path String
etag String?
size BigInt?
/// PENDING (to make its web copy), WORKING, DONE, FAILED.
status String @default("PENDING")
attempts Int @default(0)
error String?
durationMs Int? @map("duration_ms")
width Int?
height Int?
/// The camera's time, when the file says it.
capturedAt DateTime? @map("captured_at")
/// Folder of its files in storage ("<org>/videos/<id>"), set once made.
storageKey String? @map("storage_key")
/// Size of the web copy.
webBytes BigInt? @map("web_bytes")
/// Faces in the video (frames through the same engine as the photos): NONE (organization without biometrics),
/// PENDING, RUNNING, DONE, FAILED.
facesStatus FacesStatus @default(NONE) @map("faces_status")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
source CloudSource @relation(fields: [sourceId], references: [id], onDelete: Cascade)
folder CloudFolder @relation(fields: [folderId], references: [id], onDelete: Cascade)
faces VideoFace[]
@@unique([sourceId, fileId])
@@index([status, sourceId])
@@index([folderId, status, path])
@@index([facesStatus])
@@map("cloud_videos")
}
/// One appearance of a face in an archive video: the same face followed through consecutive frames (each frame
/// analysed by the same engine as the photos). It joins the event's face groups like a photo's face, so naming,
/// suggestions, "não é" and false positives are the photos' own.
model VideoFace {
id String @id @default(uuid()) @db.Uuid
videoId String @map("video_id") @db.Uuid
groupId String? @map("group_id") @db.Uuid
/// When it is on screen (ms from the start), and the frame it is clearest in.
startMs Int @map("start_ms")
endMs Int @map("end_ms")
atMs Int @map("at_ms")
/// Box in that frame, in fractions (0 to 1, y down).
x0 Float
y0 Float
x1 Float
y1 Float
score Float
sharpness Float?
/// Mean of the appearance's sharp embeddings (unit length), from `model`.
embedding Float[] @default([])
model String
/// Frames it was found in.
frames Int
/// That frame as a JPEG in storage (shown when the face is reviewed).
frameKey String @map("frame_key")
createdAt DateTime @default(now()) @map("created_at")
video CloudVideo @relation(fields: [videoId], references: [id], onDelete: Cascade)
group FaceGroup? @relation(fields: [groupId], references: [id], onDelete: SetNull)
@@index([videoId])
@@index([groupId])
@@map("video_faces")
}
/// What one viewer may see, written when they sign in. Later pages read this row; they do not call the cloud again.
/// Shares stay as they were at sign-in until the session ends.
model ArchiveGrant {
id String @id @default(uuid()) @db.Uuid
sourceId String @map("source_id") @db.Uuid
viewerName String @map("viewer_name")
seesAll Boolean @default(false) @map("sees_all")
/// May review faces everywhere in the source (the indexing account, or a share of its root with edit rights),
/// and turn a person's recognition off.
editsAll Boolean @default(false) @map("edits_all")
/// Sealed app password of the viewer's own cloud account ("Manter sessão"): what is shared with them is read
/// again with it, so the archive never shows more than the cloud does. Null: not kept (revoked at sign-in).
secretEnc String? @map("secret_enc")
/// Kept signed in: the session slides by REMEMBER_IDLE while used; otherwise it ends after SHORT_IDLE.
remember Boolean @default(false)
/// Last time the shares were read from the cloud.
checkedAt DateTime @default(now()) @map("checked_at")
expiresAt DateTime @map("expires_at")
createdAt DateTime @default(now()) @map("created_at")
source CloudSource @relation(fields: [sourceId], references: [id], onDelete: Cascade)
folders ArchiveGrantFolder[]
@@index([sourceId, expiresAt])
@@map("archive_grants")
}
model ArchiveGrantFolder {
grantId String @map("grant_id") @db.Uuid
folderId String @map("folder_id") @db.Uuid
/// Shared with edit rights on the cloud (update or create): its faces, and those of the folders below, may be
/// reviewed by this viewer.
canEdit Boolean @default(false) @map("can_edit")
grant ArchiveGrant @relation(fields: [grantId], references: [id], onDelete: Cascade)
folder CloudFolder @relation(fields: [folderId], references: [id], onDelete: Cascade)
@@id([grantId, folderId])
@@index([folderId])
@@map("archive_grant_folders")
}
/// "Não é": a face group said not to be this person; never suggested as them again.
model FaceGroupRejection {
groupId String @map("group_id") @db.Uuid
personId String @map("person_id") @db.Uuid
/// Who said so (an archive viewer's name on the cloud, or a user).
by String
createdAt DateTime @default(now()) @map("created_at")
group FaceGroup @relation(fields: [groupId], references: [id], onDelete: Cascade)
person Person @relation(fields: [personId], references: [id], onDelete: Cascade)
@@id([groupId, personId])
@@index([personId])
@@map("face_group_rejections")
}
/// What archive viewers did to faces (confirm, "não é", false positive, recognition off): the person's history.
model ArchiveFaceAction {
id String @id @default(uuid()) @db.Uuid
sourceId String @map("source_id") @db.Uuid
personId String? @map("person_id") @db.Uuid
groupId String? @map("group_id") @db.Uuid
viewer String
action String
faces Int @default(0)
createdAt DateTime @default(now()) @map("created_at")
source CloudSource @relation(fields: [sourceId], references: [id], onDelete: Cascade)
@@index([personId, createdAt])
@@index([sourceId, createdAt])
@@map("archive_face_actions")
}
/// "Juntar nomes": another name of a club in one archive ("Sporting" → "Sporting CP"). By the folded name.
model ArchiveClubAlias {
id String @id @default(uuid()) @db.Uuid
sourceId String @map("source_id") @db.Uuid
/// The other name, folded (lowercase, no accents, single spaces): how it is matched.
aliasKey String @map("alias_key")
/// The other name as it was first written.
alias String
/// The club it is.
name String
by String @default("")
createdAt DateTime @default(now()) @map("created_at")
source CloudSource @relation(fields: [sourceId], references: [id], onDelete: Cascade)
@@unique([sourceId, aliasKey])
@@map("archive_club_aliases")
}
/// One side of one game in an archive, under the single name the teams list shows. Written by the worker.
model ArchiveTeamSide {
sourceId String @map("source_id") @db.Uuid
eventId String @map("event_id") @db.Uuid
/// The side as the event stores it (or one club of a "A / B" side). What the gallery filter matches.
raw String
/// The directory's name for it.
name String
source CloudSource @relation(fields: [sourceId], references: [id], onDelete: Cascade)
event Event @relation(fields: [eventId], references: [id], onDelete: Cascade)
@@id([sourceId, eventId, raw])
@@index([sourceId, name])
@@map("archive_team_sides")
}