mystuff2/prisma/schema.prisma
Greg aa0d14b679 Add favorites/library app with Coolify deployment setup
Personal favorites tracker: Next.js 16 App Router, Prisma/PostgreSQL,
NextAuth v5 credentials auth with admin/friend roles, category-driven
custom fields, lending library, optional S3 cover images.

Deployment: multi-stage Dockerfile (standalone output) whose entrypoint
runs prisma migrate deploy and the idempotent seed on every boot; env
validation made lazy so next build works in the secret-free image.
See DEPLOY.md for Coolify setup.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-12 12:20:41 +02:00

149 lines
3.8 KiB
Plaintext

generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
enum Role {
ADMIN
FRIEND
}
enum LoanStatus {
AVAILABLE
LENT_OUT
}
// --- Auth.js models (database session strategy) ---
model User {
id String @id @default(cuid())
email String @unique
passwordHash String
name String?
role Role @default(FRIEND)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
accounts Account[]
sessions Session[]
items Item[] @relation("ItemOwner")
libraryItems LibraryItem[] @relation("LibraryOwner")
}
model Account {
id String @id @default(cuid())
userId String
type String
provider String
providerAccountId String
refresh_token String? @db.Text
access_token String? @db.Text
expires_at Int?
token_type String?
scope String?
id_token String? @db.Text
session_state String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([provider, providerAccountId])
}
model Session {
id String @id @default(cuid())
sessionToken String @unique
userId String
expires DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}
model VerificationToken {
identifier String
token String @unique
expires DateTime
@@unique([identifier, token])
}
// --- Domain models ---
model Category {
id String @id @default(cuid())
key String @unique // stable slug used in code/URLs, e.g. "movies"
label String
icon String? // lucide icon name
isShared Boolean @default(false)
sortOrder Int @default(0)
fieldSchema Json // array of {key,label,type,required?,options?}
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
items Item[]
}
model Tag {
id String @id @default(cuid())
name String @unique
itemTags ItemTag[]
}
model Item {
id String @id @default(cuid())
title String
coverImageKey String? // S3 object key; public URL built at render time
categoryId String
rating Int? // 1-5, null = unrated
description String? // short plain-text blurb for cards
notesHtml String? @db.Text // sanitized Tiptap HTML
customFields Json @default("{}")
dateAdded DateTime @default(now())
ownerId String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
category Category @relation(fields: [categoryId], references: [id])
owner User @relation("ItemOwner", fields: [ownerId], references: [id])
itemTags ItemTag[]
libraryItems LibraryItem[]
@@index([categoryId])
@@index([rating])
}
model ItemTag {
itemId String
tagId String
item Item @relation(fields: [itemId], references: [id], onDelete: Cascade)
tag Tag @relation(fields: [tagId], references: [id], onDelete: Cascade)
@@id([itemId, tagId])
}
model LibraryItem {
id String @id @default(cuid())
itemId String? // optional link to a favorites Item
standaloneTitle String? // used when itemId is null
mediaType String? // "Book", "DVD", "Blu-ray", "Vinyl", ...
condition String?
loanStatus LoanStatus @default(AVAILABLE)
borrowerName String?
dateLent DateTime?
expectedReturnDate DateTime?
notes String? @db.Text
ownerId String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
item Item? @relation(fields: [itemId], references: [id], onDelete: SetNull)
owner User @relation("LibraryOwner", fields: [ownerId], references: [id])
@@index([loanStatus])
}