Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HT6iXLYUUp9pJz5Kza9xCW
132 lines
4.3 KiB
Plaintext
132 lines
4.3 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[]
|
|
|
|
@@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[]
|
|
|
|
@@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")
|
|
}
|