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