171 lines
5.3 KiB
Plaintext
171 lines
5.3 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"
|
|
output = "../node_modules/.prisma/client"
|
|
}
|
|
|
|
datasource db {
|
|
provider = "postgresql"
|
|
}
|
|
|
|
/// User model representing authenticated users from Friendolls auth
|
|
model User {
|
|
/// Internal unique identifier (UUID)
|
|
id String @id @default(uuid())
|
|
|
|
/// Keycloak subject identifier (legacy for migration)
|
|
/// This is the 'sub' claim from the old JWT token
|
|
keycloakSub String? @unique @map("keycloak_sub")
|
|
|
|
/// User's display name
|
|
name String
|
|
|
|
/// User's email address
|
|
email String @unique
|
|
|
|
/// User's preferred app handle used for discovery
|
|
username String @unique
|
|
|
|
/// URL to user's profile picture
|
|
picture String?
|
|
|
|
/// User's roles from Keycloak (stored as JSON array)
|
|
roles String[]
|
|
|
|
/// Password hash for local authentication
|
|
passwordHash String? @map("password_hash")
|
|
|
|
/// 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[]
|
|
authIdentities AuthIdentity[]
|
|
authSessions AuthSession[]
|
|
authExchangeCodes AuthExchangeCode[]
|
|
|
|
@@map("users")
|
|
}
|
|
|
|
model AuthIdentity {
|
|
id String @id @default(uuid())
|
|
provider AuthProvider
|
|
providerSubject String @map("provider_subject")
|
|
providerEmail String? @map("provider_email")
|
|
providerName String? @map("provider_name")
|
|
providerUsername String? @map("provider_username")
|
|
providerPicture String? @map("provider_picture")
|
|
emailVerified Boolean @default(false) @map("email_verified")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
userId String @map("user_id")
|
|
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
@@unique([provider, providerSubject])
|
|
@@index([userId])
|
|
@@map("auth_identities")
|
|
}
|
|
|
|
model AuthSession {
|
|
id String @id @default(uuid())
|
|
provider AuthProvider?
|
|
refreshTokenHash String @unique @map("refresh_token_hash")
|
|
expiresAt DateTime @map("expires_at")
|
|
revokedAt DateTime? @map("revoked_at")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
userId String @map("user_id")
|
|
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
@@index([userId])
|
|
@@map("auth_sessions")
|
|
}
|
|
|
|
model AuthExchangeCode {
|
|
id String @id @default(uuid())
|
|
provider AuthProvider
|
|
codeHash String @unique @map("code_hash")
|
|
expiresAt DateTime @map("expires_at")
|
|
consumedAt DateTime? @map("consumed_at")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
userId String @map("user_id")
|
|
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
@@index([userId])
|
|
@@map("auth_exchange_codes")
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
enum AuthProvider {
|
|
GOOGLE
|
|
DISCORD
|
|
}
|