eletrotupi / tcc/ api/prisma/schema.prisma491dca79fa09cef036acd73efc346039c3d1140d
7.5 KB | 309 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

31
  onboardingSeenAt DateTime? @map("onboarding_seen_at")
32
  termsAcceptedAt  DateTime? @map("terms_accepted_at")
33
  termsVersion     String?   @map("terms_version")
34

35
  moods            Mood[]
36
  triggers         Trigger[]
37
  sleepRecords     SleepRecord[]
38
  insights         Insight[]
39
  medicineRegimens MedicineRegimen[]
40
  careActions      CareAction[]
41

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

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

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

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

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

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

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

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

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

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

86
  moodLinks   TriggerMoodLink[]
87
  careActions CareAction[]
88

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

182

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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