eletrotupi / tcc/ api/prisma/schema.prisma16c9c0853325dd37cc7356b2ca8dabee4bf0113b
7.3 KB | 305 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?   @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

31
  moods            Mood[]
32
  triggers         Trigger[]
33
  sleepRecords     SleepRecord[]
34
  insights         Insight[]
35
  medicineRegimens MedicineRegimen[]
36
  careActions      CareAction[]
37

38
  @@map("users")
39
}
40

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

52
  moodComponents MoodComponent[]
53
  triggerLinks   TriggerMoodLink[]
54
  careActions    CareAction[]
55

56
  @@map("moods")
57
}
58

59
model MoodComponent {
60
  id        Int                 @id @default(autoincrement())
61
  component MoodComponentOption
62
  intensity IntensityLevel      @default(LIGHT)
63

64
  moodId Int  @map("mood_id")
65
  mood   Mood @relation(fields: [moodId], references: [id], onDelete: Cascade)
66

67
  @@map("mood_components")
68
}
69

70
model Trigger {
71
  id       Int         @id @default(autoincrement())
72
  comment  String?     @db.Text
73
  category TriggerType
74
  moment   DateTime    @default(now())
75

76
  userId Int  @map("user_id")
77
  user   User @relation(fields: [userId], references: [id])
78

79
  createdAt DateTime @default(now()) @map("created_at")
80
  updatedAt DateTime @updatedAt @map("updated_at")
81

82
  moodLinks   TriggerMoodLink[]
83
  careActions CareAction[]
84

85
  @@map("triggers")
86
}
87

88
model TriggerMoodLink {
89
  id              Int      @id @default(autoincrement())
90
  triggerId       Int      @map("trigger_id")
91
  moodId          Int      @map("mood_id")
92
  perceivedImpact Int      @map("perceived_impact")
93
  linkedAt        DateTime @default(now()) @map("linked_at")
94

95
  trigger Trigger @relation(fields: [triggerId], references: [id], onDelete: Cascade)
96
  mood    Mood    @relation(fields: [moodId], references: [id], onDelete: Cascade)
97

98
  @@unique([triggerId, moodId])
99
  @@map("trigger_mood_links")
100
}
101

102
model MedicineRegimen {
103
  id          Int                 @id @default(autoincrement())
104
  name        String
105
  dosage      String
106
  periodicity MedicinePeriodicity
107
  scheduledAt String[]            @default([]) @map("scheduled_at")
108
  active      Boolean             @default(true)
109
  userId      Int                 @map("user_id")
110

111
  user         User          @relation(fields: [userId], references: [id])
112
  medicineLogs MedicineLog[]
113

114
  createdAt DateTime @default(now()) @map("created_at")
115
  updatedAt DateTime @updatedAt @map("updated_at")
116

117
  @@map("medicine_regimens")
118
}
119

120
model CareAction {
121
  id     Int            @id @default(autoincrement())
122
  type   CareActionType
123
  moment DateTime       @default(now())
124
  userId Int            @map("user_id")
125

126
  triggerId Int? @map("trigger_id")
127
  moodId    Int? @map("mood_id")
128

129
  user    User     @relation(fields: [userId], references: [id])
130
  trigger Trigger? @relation(fields: [triggerId], references: [id])
131
  mood    Mood?    @relation(fields: [moodId], references: [id])
132

133
  medicineLog MedicineLog?
134
  appointment Appointment?
135
  activity    Activity?
136

137
  createdAt DateTime @default(now()) @map("created_at")
138
  updatedAt DateTime @updatedAt @map("updated_at")
139

140
  @@map("care_actions")
141
}
142

143
model MedicineLog {
144
  id           Int      @id @default(autoincrement())
145
  regimenId    Int?     @map("regimen_id")
146
  careActionId Int      @unique @map("care_action_id")
147
  takenAt      DateTime @default(now()) @map("taken_at")
148

149
  regimen    MedicineRegimen? @relation(fields: [regimenId], references: [id])
150
  careAction CareAction       @relation(fields: [careActionId], references: [id], onDelete: Cascade)
151

152
  @@map("medicine_logs")
153
}
154

155
model Appointment {
156
  id           Int             @id @default(autoincrement())
157
  careActionId Int             @unique @map("care_action_id")
158
  type         AppointmentType
159
  duration     Int
160
  note         String?         @db.Text
161

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

164
  @@map("appointments")
165
}
166

167
model Activity {
168
  id           Int          @id @default(autoincrement())
169
  careActionId Int          @unique @map("care_action_id")
170
  type         ActivityType
171
  duration     Int?
172

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

175
  @@map("activities")
176
}
177

178

179
model SleepRecord {
180
  id          Int      @id @default(autoincrement())
181
  average     Float
182
  date        DateTime @db.Date
183
  annotations String?  @db.Text
184

185
  userId Int  @map("user_id")
186
  user   User @relation(fields: [userId], references: [id])
187

188
  createdAt DateTime @default(now()) @map("created_at")
189
  updatedAt DateTime @updatedAt @map("updated_at")
190

191
  @@map("sleep_records")
192
}
193

194
model Insight {
195
  id     Int  @id @default(autoincrement())
196
  userId Int  @map("user_id")
197
  user   User @relation(fields: [userId], references: [id])
198

199
  type        InsightType
200
  period      InsightPeriod
201
  title       String
202
  body        String        @db.Text
203
  metadata    Json?
204
  generatedAt DateTime      @default(now()) @map("generated_at")
205
  periodStart DateTime      @map("period_start")
206
  periodEnd   DateTime      @map("period_end")
207

208
  @@unique([userId, type, periodStart])
209
  @@map("insights")
210
}
211

212
enum InsightType {
213
  MOOD_TREND
214
  ENERGY_SLEEP_CORRELATION
215
  TRIGGER_PATTERN
216
  WEEKLY_SUMMARY
217
  STREAK
218
  DAILY_ENERGY
219
  DAILY_SLEEP
220
}
221

222
enum InsightPeriod {
223
  DAILY
224
  WEEKLY
225
  MONTHLY
226
}
227

228
enum IntensityLevel {
229
  LIGHT
230
  MODERATE
231
  HIGH
232
}
233

234
enum TriggerType {
235
  SOCIAL
236
  WORK
237
  HEALTH
238
  PHYSICAL
239
  FAMILY
240
  THERAPY
241
  INTERNAL
242
  OTHER
243
}
244

245
// XXX: Keep it in sync with constants/moods.ts
246
enum BaseMoodOption {
247
  SAD
248
  NEUTRAL
249
  GOOD
250
  GREAT
251
  ANGRY
252
}
253

254
enum MoodComponentOption {
255
  JOY
256
  ANGER
257
  SADNESS
258
  FEAR
259
  GUILT
260
  FRUSTRATION
261
  // States
262
  CALM
263
  MOTIVATED
264
  TIREDNESS
265
  GRATITUDE
266
  FOCUS
267
  RESTLESS
268
  RELAXED
269
  OVERWHELMED
270
}
271

272
enum CareActionType {
273
  MEDICINE
274
  APPOINTMENT
275
  ACTIVITY
276
}
277

278
enum AppointmentType {
279
  ANALYST
280
  PSYCHIATRIST
281
  GP
282
  NUTRITIONIST
283
  PHYSIOTHERAPIST
284
  OTHER
285
}
286

287
enum ActivityType {
288
  WALK
289
  YOGA
290
  GYM
291
  MEDITATION
292
  SOCIAL
293
  CREATIVE
294
  OTHER
295
}
296

297
enum MedicinePeriodicity {
298
  ONCE
299
  DAILY
300
  TWICE_DAILY
301
  THREE_TIMES_DAILY
302
  WEEKLY
303
  BIWEEKLY
304
  MONTHLY
305
}