108 lines
3.2 KiB
Plaintext
108 lines
3.2 KiB
Plaintext
// This is your Prisma schema file,
|
|
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
|
|
|
generator client {
|
|
provider = "prisma-client-js"
|
|
}
|
|
|
|
datasource db {
|
|
provider = "postgresql"
|
|
}
|
|
|
|
/// User model representing authenticated users from Keycloak OIDC
|
|
model User {
|
|
/// Internal unique identifier (UUID)
|
|
id String @id @default(uuid())
|
|
|
|
/// Keycloak subject identifier (unique per user in Keycloak)
|
|
/// This is the 'sub' claim from the JWT token
|
|
keycloakSub String @unique @map("keycloak_sub")
|
|
|
|
/// User's display name
|
|
name String
|
|
|
|
/// User's email address
|
|
email String
|
|
|
|
/// User's preferred username from Keycloak
|
|
username String?
|
|
|
|
/// URL to user's profile picture
|
|
picture String?
|
|
|
|
/// User's roles from Keycloak (stored as JSON array)
|
|
roles String[]
|
|
|
|
/// Timestamp when the user was first created in the system
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
|
|
/// Timestamp when the user profile was last updated
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
/// Timestamp of last login
|
|
lastLoginAt DateTime? @map("last_login_at")
|
|
|
|
// The ID of the currently active doll for the user
|
|
activeDollId String? @map("active_doll_id")
|
|
activeDoll Doll? @relation("ActiveDoll", fields: [activeDollId], references: [id])
|
|
|
|
sentFriendRequests FriendRequest[] @relation("SentFriendRequests")
|
|
receivedFriendRequests FriendRequest[] @relation("ReceivedFriendRequests")
|
|
userFriendships Friendship[] @relation("UserFriendships")
|
|
friendFriendships Friendship[] @relation("FriendFriendships")
|
|
dolls Doll[]
|
|
|
|
@@map("users")
|
|
}
|
|
|
|
model FriendRequest {
|
|
id String @id @default(uuid())
|
|
senderId String @map("sender_id")
|
|
receiverId String @map("receiver_id")
|
|
status FriendRequestStatus @default(PENDING)
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
sender User @relation("SentFriendRequests", fields: [senderId], references: [id], onDelete: Cascade)
|
|
receiver User @relation("ReceivedFriendRequests", fields: [receiverId], references: [id], onDelete: Cascade)
|
|
|
|
@@unique([senderId, receiverId])
|
|
@@map("friend_requests")
|
|
}
|
|
|
|
model Friendship {
|
|
id String @id @default(uuid())
|
|
userId String @map("user_id")
|
|
friendId String @map("friend_id")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
|
|
user User @relation("UserFriendships", fields: [userId], references: [id], onDelete: Cascade)
|
|
friend User @relation("FriendFriendships", fields: [friendId], references: [id], onDelete: Cascade)
|
|
|
|
@@unique([userId, friendId])
|
|
@@map("friendships")
|
|
}
|
|
|
|
model Doll {
|
|
id String @id @default(uuid())
|
|
name String
|
|
configuration Json
|
|
userId String @map("user_id")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
deletedAt DateTime? @map("deleted_at")
|
|
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
// Reverse relation for the active doll
|
|
activeForUser User[] @relation("ActiveDoll")
|
|
|
|
@@map("dolls")
|
|
}
|
|
|
|
enum FriendRequestStatus {
|
|
PENDING
|
|
ACCEPTED
|
|
DENIED
|
|
}
|