Files
friendolls-server/prisma/schema.prisma

87 lines
2.6 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"
previewFeatures = ["driverAdapters"]
}
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")
sentFriendRequests FriendRequest[] @relation("SentFriendRequests")
receivedFriendRequests FriendRequest[] @relation("ReceivedFriendRequests")
userFriendships Friendship[] @relation("UserFriendships")
friendFriendships Friendship[] @relation("FriendFriendships")
@@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")
}
enum FriendRequestStatus {
PENDING
ACCEPTED
DENIED
}