generator client { provider = "prisma-client-js" //output = "../src/generated/prisma" } datasource db { provider = "postgresql" } model User { id Int @id @default(autoincrement()) firstName String @map("first_name") lastName String? @map("last_name") email String @unique encryptedPassword String @map("encrypted_password") passwordResetToken String? @map("password_reset_token") passwordResetExpires DateTime? @map("password_reset_expires") createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") avatarKey String? @map("avatar_key") avatarURL String? @map("avatar_url") activationCode String? @unique @map("activation_code") activationCodeExpiresAt DateTime? @map("activation_code_expires_at") active Boolean @default(false) @map("active") pushToken String? @map("push_token") pushEnabled Boolean @default(true) @map("push_enabled") dailyReminderTime String? @map("daily_reminder_time") weeklyResumeEnabled Boolean @default(false) @map("weekly_resume_enabled") onboardingSeenAt DateTime? @map("onboarding_seen_at") termsAcceptedAt DateTime? @map("terms_accepted_at") termsVersion String? @map("terms_version") moods Mood[] triggers Trigger[] sleepRecords SleepRecord[] insights Insight[] medicineRegimens MedicineRegimen[] careActions CareAction[] notifications Notification[] @@map("users") } model Mood { id Int @id @default(autoincrement()) annotation String? @db.Text moment DateTime @default(now()) selectedMood BaseMoodOption @default(GOOD) @map("selected_mood") anxietyLevel Int @map("anxiety_level") stressLevel Int @map("stress_level") energyLevel Int @map("energy_level") userId Int @map("user_id") user User @relation(fields: [userId], references: [id]) moodComponents MoodComponent[] triggerLinks TriggerMoodLink[] careActions CareAction[] @@map("moods") } model MoodComponent { id Int @id @default(autoincrement()) component MoodComponentOption intensity IntensityLevel @default(LIGHT) moodId Int @map("mood_id") mood Mood @relation(fields: [moodId], references: [id], onDelete: Cascade) @@map("mood_components") } model Trigger { id Int @id @default(autoincrement()) comment String? @db.Text category TriggerType moment DateTime @default(now()) userId Int @map("user_id") user User @relation(fields: [userId], references: [id]) createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") moodLinks TriggerMoodLink[] careActions CareAction[] @@map("triggers") } model TriggerMoodLink { id Int @id @default(autoincrement()) triggerId Int @map("trigger_id") moodId Int @map("mood_id") perceivedImpact Int @map("perceived_impact") linkedAt DateTime @default(now()) @map("linked_at") trigger Trigger @relation(fields: [triggerId], references: [id], onDelete: Cascade) mood Mood @relation(fields: [moodId], references: [id], onDelete: Cascade) @@unique([triggerId, moodId]) @@map("trigger_mood_links") } model MedicineRegimen { id Int @id @default(autoincrement()) name String dosage String periodicity MedicinePeriodicity scheduledAt String[] @default([]) @map("scheduled_at") active Boolean @default(true) userId Int @map("user_id") user User @relation(fields: [userId], references: [id]) medicineLogs MedicineLog[] notifications Notification[] createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") @@map("medicine_regimens") } model CareAction { id Int @id @default(autoincrement()) type CareActionType moment DateTime @default(now()) userId Int @map("user_id") triggerId Int? @map("trigger_id") moodId Int? @map("mood_id") user User @relation(fields: [userId], references: [id]) trigger Trigger? @relation(fields: [triggerId], references: [id]) mood Mood? @relation(fields: [moodId], references: [id]) medicineLog MedicineLog? appointment Appointment? activity Activity? createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") @@map("care_actions") } model MedicineLog { id Int @id @default(autoincrement()) regimenId Int? @map("regimen_id") careActionId Int @unique @map("care_action_id") takenAt DateTime @default(now()) @map("taken_at") regimen MedicineRegimen? @relation(fields: [regimenId], references: [id]) careAction CareAction @relation(fields: [careActionId], references: [id], onDelete: Cascade) @@map("medicine_logs") } model Appointment { id Int @id @default(autoincrement()) careActionId Int @unique @map("care_action_id") type AppointmentType duration Int note String? @db.Text careAction CareAction @relation(fields: [careActionId], references: [id], onDelete: Cascade) @@map("appointments") } model Activity { id Int @id @default(autoincrement()) careActionId Int @unique @map("care_action_id") type ActivityType duration Int? careAction CareAction @relation(fields: [careActionId], references: [id], onDelete: Cascade) @@map("activities") } model SleepRecord { id Int @id @default(autoincrement()) average Float date DateTime @db.Date annotations String? @db.Text userId Int @map("user_id") user User @relation(fields: [userId], references: [id]) createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") @@map("sleep_records") } model Insight { id Int @id @default(autoincrement()) userId Int @map("user_id") user User @relation(fields: [userId], references: [id]) type InsightType period InsightPeriod title String body String @db.Text metadata Json? generatedAt DateTime @default(now()) @map("generated_at") periodStart DateTime @map("period_start") periodEnd DateTime @map("period_end") @@unique([userId, type, periodStart]) @@map("insights") } model Notification { id Int @id @default(autoincrement()) kind NotificationKind title String body String @db.Text scheduledFor DateTime @map("scheduled_for") expiresAt DateTime? @map("expires_at") pushedAt DateTime? @map("pushed_at") regimenId Int? @map("regimen_id") userId Int @map("user_id") regimen MedicineRegimen? @relation(fields: [regimenId], references: [id]) user User @relation(fields: [userId], references: [id]) createdAt DateTime @default(now()) @map("created_at") @@map("notifications") } enum NotificationKind { DAILY_REMINDER MEDICINE_REMINDER INSIGHT_ALERT } enum InsightType { MOOD_TREND ENERGY_SLEEP_CORRELATION TRIGGER_PATTERN WEEKLY_SUMMARY STREAK DAILY_ENERGY DAILY_SLEEP } enum InsightPeriod { DAILY WEEKLY MONTHLY } enum IntensityLevel { LIGHT MODERATE HIGH } enum TriggerType { SOCIAL WORK HEALTH PHYSICAL FAMILY THERAPY INTERNAL OTHER } // XXX: Keep it in sync with constants/moods.ts enum BaseMoodOption { SAD NEUTRAL GOOD GREAT ANGRY } enum MoodComponentOption { JOY ANGER SADNESS FEAR GUILT FRUSTRATION // States CALM MOTIVATED TIREDNESS GRATITUDE FOCUS RESTLESS RELAXED OVERWHELMED } enum CareActionType { MEDICINE APPOINTMENT ACTIVITY } enum AppointmentType { ANALYST PSYCHIATRIST GP NUTRITIONIST PHYSIOTHERAPIST OTHER } enum ActivityType { WALK YOGA GYM MEDITATION SOCIAL CREATIVE OTHER } enum MedicinePeriodicity { ONCE DAILY TWICE_DAILY THREE_TIMES_DAILY WEEKLY BIWEEKLY MONTHLY }