eletrotupi / tcc/ api/prisma/schema.prisma0df6beae35dccec34c54d7848d067aca2070eb29
4.6 KB | 202 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

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
  @@map("sleep_records")
118
}
119

120
model Insight {
121
  id     Int  @id @default(autoincrement())
122
  userId Int  @map("user_id")
123
  user   User @relation(fields: [userId], references: [id])
124

125
  type        InsightType
126
  period      InsightPeriod
127
  title       String
128
  body        String        @db.Text
129
  metadata    Json? // flexible payload: correlations, deltas, scores
130
  generatedAt DateTime      @default(now()) @map("generated_at")
131
  periodStart DateTime      @map("period_start")
132
  periodEnd   DateTime      @map("period_end")
133

134
  @@unique([userId, type, periodStart])
135
  @@map("insights")
136
}
137

138
enum InsightType {
139
  MOOD_TREND
140
  ENERGY_SLEEP_CORRELATION
141
  TRIGGER_PATTERN
142
  WEEKLY_SUMMARY
143
  STREAK
144
  DAILY_ENERGY
145
  DAILY_SLEEP
146
}
147

148
enum InsightPeriod {
149
  DAILY
150
  WEEKLY
151
  MONTHLY
152
}
153

154
enum IntensityLevel {
155
  LIGHT
156
  MODERATE
157
  HIGH
158
}
159

160
enum InterventionType {
161
  MEDICATION
162
  THERAPY
163
  MEDITATION
164
  EXERCISE
165
  CONVERSATION
166
}
167

168
enum TriggerType {
169
  SOCIAL
170
  WORK
171
  HEALTH
172
  PHYSICAL
173
  FAMILY
174
  OTHER
175
}
176

177
// XXX: Keep it in sync with constants/moods.ts
178
enum BaseMoodOption {
179
  SAD
180
  NEUTRAL
181
  GOOD
182
  GREAT
183
  ANGRY
184
}
185

186
enum MoodComponentOption {
187
  JOY
188
  ANGER
189
  SADNESS
190
  FEAR
191
  GUILT
192
  FRUSTRATION
193
  // States
194
  CALM
195
  MOTIVATED
196
  TIREDNESS
197
  GRATITUDE
198
  FOCUS
199
  RESTLESS
200
  RELAXED
201
  OVERWHELMED
202
}