| 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 | interventions Intervention[]
|
| 31 | triggers Trigger[]
|
| 32 | reminders Reminder[]
|
| 33 | sleepRecords SleepRecord[]
|
| 34 | insights Insight[]
|
| 35 |
|
| 36 | @@map("users")
|
| 37 | }
|
| 38 |
|
| 39 | model Mood {
|
| 40 | id Int @id @default(autoincrement())
|
| 41 | annotation String? @db.Text
|
| 42 | moment DateTime @default(now())
|
| 43 | selectedMood BaseMoodOption @default(GOOD) @map("selected_mood")
|
| 44 | anxietyLevel Int @map("anxiety_level")
|
| 45 | stressLevel Int @map("stress_level")
|
| 46 | energyLevel Int @map("energy_level")
|
| 47 | userId Int @map("user_id")
|
| 48 | user User @relation(fields: [userId], references: [id])
|
| 49 |
|
| 50 | moodComponents MoodComponent[]
|
| 51 |
|
| 52 | @@map("moods")
|
| 53 | }
|
| 54 |
|
| 55 | model MoodComponent {
|
| 56 | id Int @id @default(autoincrement())
|
| 57 | component MoodComponentOption
|
| 58 | intensity IntensityLevel @default(LIGHT)
|
| 59 |
|
| 60 | moodId Int @map("mood_id")
|
| 61 | mood Mood @relation(fields: [moodId], references: [id], onDelete: Cascade)
|
| 62 |
|
| 63 | @@map("mood_components")
|
| 64 | }
|
| 65 |
|
| 66 | model Intervention {
|
| 67 | id Int @id @default(autoincrement())
|
| 68 | comment String?
|
| 69 | interventionType InterventionType @map("intervention_type")
|
| 70 | eficacy Int
|
| 71 | startAt DateTime @map("start_at")
|
| 72 | endAt DateTime @map("end_at")
|
| 73 |
|
| 74 | userId Int @map("user_id")
|
| 75 | user User @relation(fields: [userId], references: [id])
|
| 76 |
|
| 77 | @@map("interventions")
|
| 78 | }
|
| 79 |
|
| 80 | model Trigger {
|
| 81 | id Int @id @default(autoincrement())
|
| 82 | comment String? @db.Text
|
| 83 | category TriggerType
|
| 84 | moment DateTime @default(now())
|
| 85 |
|
| 86 | userId Int @map("user_id")
|
| 87 | user User @relation(fields: [userId], references: [id])
|
| 88 |
|
| 89 | createdAt DateTime @default(now()) @map("created_at")
|
| 90 | updatedAt DateTime @updatedAt @map("updated_at")
|
| 91 |
|
| 92 | @@map("triggers")
|
| 93 | }
|
| 94 |
|
| 95 | model Reminder {
|
| 96 | id Int @id @default(autoincrement())
|
| 97 | hour Int
|
| 98 | minute Int
|
| 99 | description String?
|
| 100 | active Boolean @default(false)
|
| 101 |
|
| 102 | userId Int @map("user_id")
|
| 103 | user User @relation(fields: [userId], references: [id])
|
| 104 |
|
| 105 | @@map("reminders")
|
| 106 | }
|
| 107 |
|
| 108 | model SleepRecord {
|
| 109 | id Int @id @default(autoincrement())
|
| 110 | average Float
|
| 111 | date DateTime @db.Date
|
| 112 | annotations String? @db.Text
|
| 113 |
|
| 114 | userId Int @map("user_id")
|
| 115 | user User @relation(fields: [userId], references: [id])
|
| 116 |
|
| 117 | createdAt DateTime @default(now()) @map("created_at")
|
| 118 | updatedAt DateTime @updatedAt @map("updated_at")
|
| 119 |
|
| 120 | @@map("sleep_records")
|
| 121 | }
|
| 122 |
|
| 123 | model Insight {
|
| 124 | id Int @id @default(autoincrement())
|
| 125 | userId Int @map("user_id")
|
| 126 | user User @relation(fields: [userId], references: [id])
|
| 127 |
|
| 128 | type InsightType
|
| 129 | period InsightPeriod
|
| 130 | title String
|
| 131 | body String @db.Text
|
| 132 | metadata Json? // flexible payload: correlations, deltas, scores
|
| 133 | generatedAt DateTime @default(now()) @map("generated_at")
|
| 134 | periodStart DateTime @map("period_start")
|
| 135 | periodEnd DateTime @map("period_end")
|
| 136 |
|
| 137 | @@unique([userId, type, periodStart])
|
| 138 | @@map("insights")
|
| 139 | }
|
| 140 |
|
| 141 | enum InsightType {
|
| 142 | MOOD_TREND
|
| 143 | ENERGY_SLEEP_CORRELATION
|
| 144 | TRIGGER_PATTERN
|
| 145 | WEEKLY_SUMMARY
|
| 146 | STREAK
|
| 147 | DAILY_ENERGY
|
| 148 | DAILY_SLEEP
|
| 149 | }
|
| 150 |
|
| 151 | enum InsightPeriod {
|
| 152 | DAILY
|
| 153 | WEEKLY
|
| 154 | MONTHLY
|
| 155 | }
|
| 156 |
|
| 157 | enum IntensityLevel {
|
| 158 | LIGHT
|
| 159 | MODERATE
|
| 160 | HIGH
|
| 161 | }
|
| 162 |
|
| 163 | enum InterventionType {
|
| 164 | MEDICATION
|
| 165 | THERAPY
|
| 166 | MEDITATION
|
| 167 | EXERCISE
|
| 168 | CONVERSATION
|
| 169 | }
|
| 170 |
|
| 171 | enum TriggerType {
|
| 172 | SOCIAL
|
| 173 | WORK
|
| 174 | HEALTH
|
| 175 | PHYSICAL
|
| 176 | FAMILY
|
| 177 | OTHER
|
| 178 | }
|
| 179 |
|
| 180 | // XXX: Keep it in sync with constants/moods.ts
|
| 181 | enum BaseMoodOption {
|
| 182 | SAD
|
| 183 | NEUTRAL
|
| 184 | GOOD
|
| 185 | GREAT
|
| 186 | ANGRY
|
| 187 | }
|
| 188 |
|
| 189 | enum MoodComponentOption {
|
| 190 | JOY
|
| 191 | ANGER
|
| 192 | SADNESS
|
| 193 | FEAR
|
| 194 | GUILT
|
| 195 | FRUSTRATION
|
| 196 | // States
|
| 197 | CALM
|
| 198 | MOTIVATED
|
| 199 | TIREDNESS
|
| 200 | GRATITUDE
|
| 201 | FOCUS
|
| 202 | RESTLESS
|
| 203 | RELAXED
|
| 204 | OVERWHELMED
|
| 205 | }
|