| 1 | generator client {
|
| 2 | provider = "prisma-client-js"
|
| 3 | //output = "../src/generated/prisma"
|
| 4 | }
|
| 5 |
|
| 6 | datasource db {
|
| 7 | provider = "postgresql"
|
| 8 | }
|
| 9 |
|
| 10 | model User {
|
| 11 | id Int @id @default(autoincrement())
|
| 12 | firstName String @map("first_name")
|
| 13 | lastName String? @map("last_name")
|
| 14 | email String @unique
|
| 15 | encryptedPassword String @map("encrypted_password")
|
| 16 | passwordResetToken String? @map("password_reset_token")
|
| 17 | passwordResetExpires DateTime? @map("password_reset_expires")
|
| 18 | createdAt DateTime @default(now()) @map("created_at")
|
| 19 | updatedAt DateTime @updatedAt @map("updated_at")
|
| 20 | avatarKey String? @map("avatar_key")
|
| 21 | avatarURL String? @map("avatar_url")
|
| 22 |
|
| 23 | activationCode String? @unique @map("activation_code")
|
| 24 | activationCodeExpiresAt DateTime? @map("activation_code_expires_at")
|
| 25 | active Boolean @default(false) @map("active")
|
| 26 |
|
| 27 | pushToken String? @map("push_token")
|
| 28 | pushEnabled Boolean @default(true) @map("push_enabled")
|
| 29 | dailyReminderTime String? @map("daily_reminder_time")
|
| 30 | weeklyResumeEnabled Boolean @default(false) @map("weekly_resume_enabled")
|
| 31 |
|
| 32 | onboardingSeenAt DateTime? @map("onboarding_seen_at")
|
| 33 | termsAcceptedAt DateTime? @map("terms_accepted_at")
|
| 34 | termsVersion String? @map("terms_version")
|
| 35 |
|
| 36 | moods Mood[]
|
| 37 | triggers Trigger[]
|
| 38 | sleepRecords SleepRecord[]
|
| 39 | insights Insight[]
|
| 40 | medicineRegimens MedicineRegimen[]
|
| 41 | careActions CareAction[]
|
| 42 | notifications Notification[]
|
| 43 |
|
| 44 | @@map("users")
|
| 45 | }
|
| 46 |
|
| 47 | model Mood {
|
| 48 | id Int @id @default(autoincrement())
|
| 49 | annotation String? @db.Text
|
| 50 | moment DateTime @default(now())
|
| 51 | selectedMood BaseMoodOption @default(GOOD) @map("selected_mood")
|
| 52 | anxietyLevel Int @map("anxiety_level")
|
| 53 | stressLevel Int @map("stress_level")
|
| 54 | energyLevel Int @map("energy_level")
|
| 55 | userId Int @map("user_id")
|
| 56 | user User @relation(fields: [userId], references: [id])
|
| 57 |
|
| 58 | moodComponents MoodComponent[]
|
| 59 | triggerLinks TriggerMoodLink[]
|
| 60 | careActions CareAction[]
|
| 61 |
|
| 62 | @@map("moods")
|
| 63 | }
|
| 64 |
|
| 65 | model MoodComponent {
|
| 66 | id Int @id @default(autoincrement())
|
| 67 | component MoodComponentOption
|
| 68 | intensity IntensityLevel @default(LIGHT)
|
| 69 |
|
| 70 | moodId Int @map("mood_id")
|
| 71 | mood Mood @relation(fields: [moodId], references: [id], onDelete: Cascade)
|
| 72 |
|
| 73 | @@map("mood_components")
|
| 74 | }
|
| 75 |
|
| 76 | model Trigger {
|
| 77 | id Int @id @default(autoincrement())
|
| 78 | comment String? @db.Text
|
| 79 | category TriggerType
|
| 80 | moment DateTime @default(now())
|
| 81 |
|
| 82 | userId Int @map("user_id")
|
| 83 | user User @relation(fields: [userId], references: [id])
|
| 84 |
|
| 85 | createdAt DateTime @default(now()) @map("created_at")
|
| 86 | updatedAt DateTime @updatedAt @map("updated_at")
|
| 87 |
|
| 88 | moodLinks TriggerMoodLink[]
|
| 89 | careActions CareAction[]
|
| 90 |
|
| 91 | @@map("triggers")
|
| 92 | }
|
| 93 |
|
| 94 | model TriggerMoodLink {
|
| 95 | id Int @id @default(autoincrement())
|
| 96 | triggerId Int @map("trigger_id")
|
| 97 | moodId Int @map("mood_id")
|
| 98 | perceivedImpact Int @map("perceived_impact")
|
| 99 | linkedAt DateTime @default(now()) @map("linked_at")
|
| 100 |
|
| 101 | trigger Trigger @relation(fields: [triggerId], references: [id], onDelete: Cascade)
|
| 102 | mood Mood @relation(fields: [moodId], references: [id], onDelete: Cascade)
|
| 103 |
|
| 104 | @@unique([triggerId, moodId])
|
| 105 | @@map("trigger_mood_links")
|
| 106 | }
|
| 107 |
|
| 108 | model MedicineRegimen {
|
| 109 | id Int @id @default(autoincrement())
|
| 110 | name String
|
| 111 | dosage String
|
| 112 | periodicity MedicinePeriodicity
|
| 113 | scheduledAt String[] @default([]) @map("scheduled_at")
|
| 114 | active Boolean @default(true)
|
| 115 | userId Int @map("user_id")
|
| 116 |
|
| 117 | user User @relation(fields: [userId], references: [id])
|
| 118 | medicineLogs MedicineLog[]
|
| 119 | notifications Notification[]
|
| 120 |
|
| 121 | createdAt DateTime @default(now()) @map("created_at")
|
| 122 | updatedAt DateTime @updatedAt @map("updated_at")
|
| 123 |
|
| 124 | @@map("medicine_regimens")
|
| 125 | }
|
| 126 |
|
| 127 | model CareAction {
|
| 128 | id Int @id @default(autoincrement())
|
| 129 | type CareActionType
|
| 130 | moment DateTime @default(now())
|
| 131 | userId Int @map("user_id")
|
| 132 |
|
| 133 | triggerId Int? @map("trigger_id")
|
| 134 | moodId Int? @map("mood_id")
|
| 135 |
|
| 136 | user User @relation(fields: [userId], references: [id])
|
| 137 | trigger Trigger? @relation(fields: [triggerId], references: [id])
|
| 138 | mood Mood? @relation(fields: [moodId], references: [id])
|
| 139 |
|
| 140 | medicineLog MedicineLog?
|
| 141 | appointment Appointment?
|
| 142 | activity Activity?
|
| 143 |
|
| 144 | createdAt DateTime @default(now()) @map("created_at")
|
| 145 | updatedAt DateTime @updatedAt @map("updated_at")
|
| 146 |
|
| 147 | @@map("care_actions")
|
| 148 | }
|
| 149 |
|
| 150 | model MedicineLog {
|
| 151 | id Int @id @default(autoincrement())
|
| 152 | regimenId Int? @map("regimen_id")
|
| 153 | careActionId Int @unique @map("care_action_id")
|
| 154 | takenAt DateTime @default(now()) @map("taken_at")
|
| 155 |
|
| 156 | regimen MedicineRegimen? @relation(fields: [regimenId], references: [id])
|
| 157 | careAction CareAction @relation(fields: [careActionId], references: [id], onDelete: Cascade)
|
| 158 |
|
| 159 | @@map("medicine_logs")
|
| 160 | }
|
| 161 |
|
| 162 | model Appointment {
|
| 163 | id Int @id @default(autoincrement())
|
| 164 | careActionId Int @unique @map("care_action_id")
|
| 165 | type AppointmentType
|
| 166 | duration Int
|
| 167 | note String? @db.Text
|
| 168 |
|
| 169 | careAction CareAction @relation(fields: [careActionId], references: [id], onDelete: Cascade)
|
| 170 |
|
| 171 | @@map("appointments")
|
| 172 | }
|
| 173 |
|
| 174 | model Activity {
|
| 175 | id Int @id @default(autoincrement())
|
| 176 | careActionId Int @unique @map("care_action_id")
|
| 177 | type ActivityType
|
| 178 | duration Int?
|
| 179 |
|
| 180 | careAction CareAction @relation(fields: [careActionId], references: [id], onDelete: Cascade)
|
| 181 |
|
| 182 | @@map("activities")
|
| 183 | }
|
| 184 |
|
| 185 |
|
| 186 | model SleepRecord {
|
| 187 | id Int @id @default(autoincrement())
|
| 188 | average Float
|
| 189 | date DateTime @db.Date
|
| 190 | annotations String? @db.Text
|
| 191 |
|
| 192 | userId Int @map("user_id")
|
| 193 | user User @relation(fields: [userId], references: [id])
|
| 194 |
|
| 195 | createdAt DateTime @default(now()) @map("created_at")
|
| 196 | updatedAt DateTime @updatedAt @map("updated_at")
|
| 197 |
|
| 198 | @@map("sleep_records")
|
| 199 | }
|
| 200 |
|
| 201 | model Insight {
|
| 202 | id Int @id @default(autoincrement())
|
| 203 | userId Int @map("user_id")
|
| 204 | user User @relation(fields: [userId], references: [id])
|
| 205 |
|
| 206 | type InsightType
|
| 207 | period InsightPeriod
|
| 208 | title String
|
| 209 | body String @db.Text
|
| 210 | metadata Json?
|
| 211 | generatedAt DateTime @default(now()) @map("generated_at")
|
| 212 | periodStart DateTime @map("period_start")
|
| 213 | periodEnd DateTime @map("period_end")
|
| 214 |
|
| 215 | @@unique([userId, type, periodStart])
|
| 216 | @@map("insights")
|
| 217 | }
|
| 218 |
|
| 219 | model Notification {
|
| 220 | id Int @id @default(autoincrement())
|
| 221 | kind NotificationKind
|
| 222 | title String
|
| 223 | body String @db.Text
|
| 224 | scheduledFor DateTime @map("scheduled_for")
|
| 225 | expiresAt DateTime? @map("expires_at")
|
| 226 | pushedAt DateTime? @map("pushed_at")
|
| 227 |
|
| 228 | regimenId Int? @map("regimen_id")
|
| 229 | userId Int @map("user_id")
|
| 230 |
|
| 231 | regimen MedicineRegimen? @relation(fields: [regimenId], references: [id])
|
| 232 | user User @relation(fields: [userId], references: [id])
|
| 233 |
|
| 234 | createdAt DateTime @default(now()) @map("created_at")
|
| 235 |
|
| 236 | @@map("notifications")
|
| 237 | }
|
| 238 |
|
| 239 | enum NotificationKind {
|
| 240 | DAILY_REMINDER
|
| 241 | MEDICINE_REMINDER
|
| 242 | INSIGHT_ALERT
|
| 243 | }
|
| 244 |
|
| 245 | enum InsightType {
|
| 246 | MOOD_TREND
|
| 247 | ENERGY_SLEEP_CORRELATION
|
| 248 | TRIGGER_PATTERN
|
| 249 | WEEKLY_SUMMARY
|
| 250 | STREAK
|
| 251 | DAILY_ENERGY
|
| 252 | DAILY_SLEEP
|
| 253 | }
|
| 254 |
|
| 255 | enum InsightPeriod {
|
| 256 | DAILY
|
| 257 | WEEKLY
|
| 258 | MONTHLY
|
| 259 | }
|
| 260 |
|
| 261 | enum IntensityLevel {
|
| 262 | LIGHT
|
| 263 | MODERATE
|
| 264 | HIGH
|
| 265 | }
|
| 266 |
|
| 267 | enum TriggerType {
|
| 268 | SOCIAL
|
| 269 | WORK
|
| 270 | HEALTH
|
| 271 | PHYSICAL
|
| 272 | FAMILY
|
| 273 | THERAPY
|
| 274 | INTERNAL
|
| 275 | OTHER
|
| 276 | }
|
| 277 |
|
| 278 | // XXX: Keep it in sync with constants/moods.ts
|
| 279 | enum BaseMoodOption {
|
| 280 | SAD
|
| 281 | NEUTRAL
|
| 282 | GOOD
|
| 283 | GREAT
|
| 284 | ANGRY
|
| 285 | }
|
| 286 |
|
| 287 | enum MoodComponentOption {
|
| 288 | JOY
|
| 289 | ANGER
|
| 290 | SADNESS
|
| 291 | FEAR
|
| 292 | GUILT
|
| 293 | FRUSTRATION
|
| 294 | // States
|
| 295 | CALM
|
| 296 | MOTIVATED
|
| 297 | TIREDNESS
|
| 298 | GRATITUDE
|
| 299 | FOCUS
|
| 300 | RESTLESS
|
| 301 | RELAXED
|
| 302 | OVERWHELMED
|
| 303 | }
|
| 304 |
|
| 305 | enum CareActionType {
|
| 306 | MEDICINE
|
| 307 | APPOINTMENT
|
| 308 | ACTIVITY
|
| 309 | }
|
| 310 |
|
| 311 | enum AppointmentType {
|
| 312 | ANALYST
|
| 313 | PSYCHIATRIST
|
| 314 | GP
|
| 315 | NUTRITIONIST
|
| 316 | PHYSIOTHERAPIST
|
| 317 | OTHER
|
| 318 | }
|
| 319 |
|
| 320 | enum ActivityType {
|
| 321 | WALK
|
| 322 | YOGA
|
| 323 | GYM
|
| 324 | MEDITATION
|
| 325 | SOCIAL
|
| 326 | CREATIVE
|
| 327 | OTHER
|
| 328 | }
|
| 329 |
|
| 330 | enum MedicinePeriodicity {
|
| 331 | ONCE
|
| 332 | DAILY
|
| 333 | TWICE_DAILY
|
| 334 | THREE_TIMES_DAILY
|
| 335 | WEEKLY
|
| 336 | BIWEEKLY
|
| 337 | MONTHLY
|
| 338 | }
|