Files
DetnalCare/prisma/schema.prisma
Iliyan Angelov 39077550ef Dental Care
2025-11-16 14:29:51 +02:00

229 lines
6.4 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
enum role {
patient
dentist
admin
}
enum AppointmentStatus {
pending
confirmed
cancelled
completed
rescheduled
}
enum PaymentStatus {
pending
paid
failed
refunded
}
enum PaymentMethod {
card
e_wallet
bank_transfer
cash
}
model User {
id String @id @map("_id")
name String
email String
emailVerified Boolean @default(false)
image String?
role role @default(patient)
phone String?
address String?
dateOfBirth DateTime?
medicalHistory String?
stripeCustomerId String? // Stripe customer ID
// Dentist-specific fields
specialization String?
qualifications String?
experience Int? // Years of experience
workingHours Json? // {monday: {start: "9:00", end: "17:00"}, ...}
isAvailable Boolean @default(true)
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
sessions Session[]
accounts Account[]
// Relations
appointmentsAsPatient Appointment[] @relation("PatientAppointments")
appointmentsAsDentist Appointment[] @relation("DentistAppointments")
payments Payment[]
notifications Notification[]
chatMessages ChatMessage[]
@@unique([email])
@@map("user")
}
model Service {
id String @id @map("_id") // Use custom ID from seed data
name String
description String?
duration Int // in minutes
price String // Price range or single price (e.g., "₱500 ₱1,500" or "₱1,500")
category String
isActive Boolean @default(true)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
appointments Appointment[]
@@map("service")
}
model Appointment {
id String @id @default(auto()) @map("_id") @db.ObjectId
patientId String
dentistId String
serviceId String // Changed to String to match Service.id
date DateTime
timeSlot String // e.g., "09:00-10:00"
status AppointmentStatus @default(pending)
notes String?
cancelReason String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
// Relations
patient User @relation("PatientAppointments", fields: [patientId], references: [id], onDelete: Cascade)
dentist User @relation("DentistAppointments", fields: [dentistId], references: [id], onDelete: Cascade)
service Service @relation(fields: [serviceId], references: [id], onDelete: Cascade)
payment Payment?
@@map("appointment")
}
model Payment {
id String @id @default(auto()) @map("_id") @db.ObjectId
appointmentId String @unique @db.ObjectId
userId String
amount Float
method PaymentMethod
status PaymentStatus @default(pending)
transactionId String?
paidAt DateTime?
stripeCustomerId String?
stripeServicesId String?
stripePaymentIntentId String?
stripePriceId String?
stripeSubscriptionId String?
stripeInvoiceId String?
stripeRefundId String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
// Relations
appointment Appointment @relation(fields: [appointmentId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@map("payment")
}
model Notification {
id String @id @default(auto()) @map("_id") @db.ObjectId
userId String
title String
message String
type String // email, sms, push
isRead Boolean @default(false)
sentAt DateTime @default(now())
createdAt DateTime @default(now())
// Relations
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@map("notification")
}
model ChatMessage {
id String @id @default(auto()) @map("_id") @db.ObjectId
userId String
message String
isFromUser Boolean @default(true)
createdAt DateTime @default(now())
// Relations
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@map("chat_message")
}
model Session {
id String @id @map("_id")
expiresAt DateTime
token String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
ipAddress String?
userAgent String?
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
activeOrganizationId String?
impersonatedBy String?
@@unique([token])
@@map("session")
}
model Account {
id String @id @map("_id")
accountId String
providerId String
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
accessToken String?
refreshToken String?
idToken String?
accessTokenExpiresAt DateTime?
refreshTokenExpiresAt DateTime?
scope String?
password String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@map("account")
}
model Verification {
id String @id @map("_id")
identifier String
value String
expiresAt DateTime
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@map("verification")
}
model Subscription {
id String @id @default(auto()) @map("_id") @db.ObjectId
plan String
referenceId String @unique
stripeCustomerId String?
stripeSubscriptionId String?
status String @default("incomplete")
periodStart DateTime?
periodEnd DateTime?
cancelAtPeriodEnd Boolean @default(false)
seats Int?
trialStart DateTime?
trialEnd DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@map("subscription")
}