eletrotupi / tcc/ api/prisma/schema.prisma6b62f4dcf96987b8b2e55bd210139a3ac9f0d976
7.5 KB | 310 lines Raw
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
  notificationsEnabled Boolean  @default(true) @map("notifications_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

43
  @@map("users")
44
}
45

46
model Mood {
47
  id           Int            @id @default(autoincrement())
48
  annotation   String?        @db.Text
49
  moment       DateTime       @default(now())
50
  selectedMood BaseMoodOption @default(GOOD) @map("selected_mood")
51
  anxietyLevel Int            @map("anxiety_level")
52
  stressLevel  Int            @map("stress_level")
53
  energyLevel  Int            @map("energy_level")
54
  userId       Int            @map("user_id")
55
  user         User           @relation(fields: [userId], references: [id])
56

57
  moodComponents MoodComponent[]
58
  triggerLinks   TriggerMoodLink[]
59
  careActions    CareAction[]
60

61
  @@map("moods")
62
}
63

64
model MoodComponent {
65
  id        Int                 @id @default(autoincrement())
66
  component MoodComponentOption
67
  intensity IntensityLevel      @default(LIGHT)
68

69
  moodId Int  @map("mood_id")
70
  mood   Mood @relation(fields: [moodId], references: [id], onDelete: Cascade)
71

72
  @@map("mood_components")
73
}
74

75
model Trigger {
76
  id       Int         @id @default(autoincrement())
77
  comment  String?     @db.Text
78
  category TriggerType
79
  moment   DateTime    @default(now())
80

81
  userId Int  @map("user_id")
82
  user   User @relation(fields: [userId], references: [id])
83

84
  createdAt DateTime @default(now()) @map("created_at")
85
  updatedAt DateTime @updatedAt @map("updated_at")
86

87
  moodLinks   TriggerMoodLink[]
88
  careActions CareAction[]
89

90
  @@map("triggers")
91
}
92

93
model TriggerMoodLink {
94
  id              Int      @id @default(autoincrement())
95
  triggerId       Int      @map("trigger_id")
96
  moodId          Int      @map("mood_id")
97
  perceivedImpact Int      @map("perceived_impact")
98
  linkedAt        DateTime @default(now()) @map("linked_at")
99

100
  trigger Trigger @relation(fields: [triggerId], references: [id], onDelete: Cascade)
101
  mood    Mood    @relation(fields: [moodId], references: [id], onDelete: Cascade)
102

103
  @@unique([triggerId, moodId])
104
  @@map("trigger_mood_links")
105
}
106

107
model MedicineRegimen {
108
  id          Int                 @id @default(autoincrement())
109
  name        String
110
  dosage      String
111
  periodicity MedicinePeriodicity
112
  scheduledAt String[]            @default([]) @map("scheduled_at")
113
  active      Boolean             @default(true)
114
  userId      Int                 @map("user_id")
115

116
  user         User          @relation(fields: [userId], references: [id])
117
  medicineLogs MedicineLog[]
118

119
  createdAt DateTime @default(now()) @map("created_at")
120
  updatedAt DateTime @updatedAt @map("updated_at")
121

122
  @@map("medicine_regimens")
123
}
124

125
model CareAction {
126
  id     Int            @id @default(autoincrement())
127
  type   CareActionType
128
  moment DateTime       @default(now())
129
  userId Int            @map("user_id")
130

131
  triggerId Int? @map("trigger_id")
132
  moodId    Int? @map("mood_id")
133

134
  user    User     @relation(fields: [userId], references: [id])
135
  trigger Trigger? @relation(fields: [triggerId], references: [id])
136
  mood    Mood?    @relation(fields: [moodId], references: [id])
137

138
  medicineLog MedicineLog?
139
  appointment Appointment?
140
  activity    Activity?
141

142
  createdAt DateTime @default(now()) @map("created_at")
143
  updatedAt DateTime @updatedAt @map("updated_at")
144

145
  @@map("care_actions")
146
}
147

148
model MedicineLog {
149
  id           Int      @id @default(autoincrement())
150
  regimenId    Int?     @map("regimen_id")
151
  careActionId Int      @unique @map("care_action_id")
152
  takenAt      DateTime @default(now()) @map("taken_at")
153

154
  regimen    MedicineRegimen? @relation(fields: [regimenId], references: [id])
155
  careAction CareAction       @relation(fields: [careActionId], references: [id], onDelete: Cascade)
156

157
  @@map("medicine_logs")
158
}
159

160
model Appointment {
161
  id           Int             @id @default(autoincrement())
162
  careActionId Int             @unique @map("care_action_id")
163
  type         AppointmentType
164
  duration     Int
165
  note         String?         @db.Text
166

167
  careAction CareAction @relation(fields: [careActionId], references: [id], onDelete: Cascade)
168

169
  @@map("appointments")
170
}
171

172
model Activity {
173
  id           Int          @id @default(autoincrement())
174
  careActionId Int          @unique @map("care_action_id")
175
  type         ActivityType
176
  duration     Int?
177

178
  careAction CareAction @relation(fields: [careActionId], references: [id], onDelete: Cascade)
179

180
  @@map("activities")
181
}
182

183

184
model SleepRecord {
185
  id          Int      @id @default(autoincrement())
186
  average     Float
187
  date        DateTime @db.Date
188
  annotations String?  @db.Text
189

190
  userId Int  @map("user_id")
191
  user   User @relation(fields: [userId], references: [id])
192

193
  createdAt DateTime @default(now()) @map("created_at")
194
  updatedAt DateTime @updatedAt @map("updated_at")
195

196
  @@map("sleep_records")
197
}
198

199
model Insight {
200
  id     Int  @id @default(autoincrement())
201
  userId Int  @map("user_id")
202
  user   User @relation(fields: [userId], references: [id])
203

204
  type        InsightType
205
  period      InsightPeriod
206
  title       String
207
  body        String        @db.Text
208
  metadata    Json?
209
  generatedAt DateTime      @default(now()) @map("generated_at")
210
  periodStart DateTime      @map("period_start")
211
  periodEnd   DateTime      @map("period_end")
212

213
  @@unique([userId, type, periodStart])
214
  @@map("insights")
215
}
216

217
enum InsightType {
218
  MOOD_TREND
219
  ENERGY_SLEEP_CORRELATION
220
  TRIGGER_PATTERN
221
  WEEKLY_SUMMARY
222
  STREAK
223
  DAILY_ENERGY
224
  DAILY_SLEEP
225
}
226

227
enum InsightPeriod {
228
  DAILY
229
  WEEKLY
230
  MONTHLY
231
}
232

233
enum IntensityLevel {
234
  LIGHT
235
  MODERATE
236
  HIGH
237
}
238

239
enum TriggerType {
240
  SOCIAL
241
  WORK
242
  HEALTH
243
  PHYSICAL
244
  FAMILY
245
  THERAPY
246
  INTERNAL
247
  OTHER
248
}
249

250
// XXX: Keep it in sync with constants/moods.ts
251
enum BaseMoodOption {
252
  SAD
253
  NEUTRAL
254
  GOOD
255
  GREAT
256
  ANGRY
257
}
258

259
enum MoodComponentOption {
260
  JOY
261
  ANGER
262
  SADNESS
263
  FEAR
264
  GUILT
265
  FRUSTRATION
266
  // States
267
  CALM
268
  MOTIVATED
269
  TIREDNESS
270
  GRATITUDE
271
  FOCUS
272
  RESTLESS
273
  RELAXED
274
  OVERWHELMED
275
}
276

277
enum CareActionType {
278
  MEDICINE
279
  APPOINTMENT
280
  ACTIVITY
281
}
282

283
enum AppointmentType {
284
  ANALYST
285
  PSYCHIATRIST
286
  GP
287
  NUTRITIONIST
288
  PHYSIOTHERAPIST
289
  OTHER
290
}
291

292
enum ActivityType {
293
  WALK
294
  YOGA
295
  GYM
296
  MEDITATION
297
  SOCIAL
298
  CREATIVE
299
  OTHER
300
}
301

302
enum MedicinePeriodicity {
303
  ONCE
304
  DAILY
305
  TWICE_DAILY
306
  THREE_TIMES_DAILY
307
  WEEKLY
308
  BIWEEKLY
309
  MONTHLY
310
}