eletrotupi / tcc/ api/prisma/schema.prisma900f2bcfdf5d6b2d5891439eb07570fba92a49bc
4.3 KB | 188 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
  moods         Mood[]
28
  interventions Intervention[]
29
  triggers      Trigger[]
30
  reminders     Reminder[]
31
  sleepRecords  SleepRecord[]
32
  insights      Insight[]
33

34
  @@map("users")
35
}
36

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

48
  moodComponents MoodComponent[]
49

50
  @@map("moods")
51
}
52

53
model MoodComponent {
54
  id        Int                 @id @default(autoincrement())
55
  component MoodComponentOption
56
  intensity IntensityLevel      @default(LIGHT)
57

58
  moodId Int  @map("mood_id")
59
  mood   Mood @relation(fields: [moodId], references: [id], onDelete: Cascade)
60

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

64
model Intervention {
65
  id               Int              @id @default(autoincrement())
66
  comment          String?
67
  interventionType InterventionType @map("intervention_type")
68
  eficacy          Int
69
  startAt          DateTime         @map("start_at")
70
  endAt            DateTime         @map("end_at")
71

72
  userId Int  @map("user_id")
73
  user   User @relation(fields: [userId], references: [id])
74

75
  @@map("interventions")
76
}
77

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

84
  userId Int  @map("user_id")
85
  user   User @relation(fields: [userId], references: [id])
86

87
  @@map("triggers")
88
}
89

90
model Reminder {
91
  id          Int     @id @default(autoincrement())
92
  hour        Int
93
  minute      Int
94
  description String?
95
  active      Boolean @default(false)
96

97
  userId Int  @map("user_id")
98
  user   User @relation(fields: [userId], references: [id])
99

100
  @@map("reminders")
101
}
102

103
model SleepRecord {
104
  id          Int      @id @default(autoincrement())
105
  average     Float
106
  date        DateTime @db.Date
107
  annotations String?  @db.Text
108

109
  userId Int  @map("user_id")
110
  user   User @relation(fields: [userId], references: [id])
111

112
  @@map("sleep_records")
113
}
114

115
model Insight {
116
  id     Int  @id @default(autoincrement())
117
  userId Int  @map("user_id")
118
  user   User @relation(fields: [userId], references: [id])
119

120
  type        InsightType
121
  period      InsightPeriod
122
  title       String
123
  body        String        @db.Text
124
  metadata    Json? // flexible payload: correlations, deltas, scores
125
  generatedAt DateTime      @default(now()) @map("generated_at")
126
  periodStart DateTime      @map("period_start")
127
  periodEnd   DateTime      @map("period_end")
128

129
  @@unique([userId, type, periodStart])
130
  @@map("insights")
131
}
132

133
enum InsightType {
134
  MOOD_TREND
135
  ENERGY_SLEEP_CORRELATION
136
  TRIGGER_PATTERN
137
  WEEKLY_SUMMARY
138
  STREAK
139
}
140

141
enum InsightPeriod {
142
  DAILY
143
  WEEKLY
144
  MONTHLY
145
}
146

147
enum IntensityLevel {
148
  LIGHT
149
  MODERATE
150
  HIGH
151
}
152

153
enum InterventionType {
154
  MEDICATION
155
  THERAPY
156
  MEDITATION
157
  EXERCISE
158
  CONVERSATION
159
}
160

161
enum TriggerType {
162
  SOCIAL
163
  WORK
164
  HEALTH
165
  PHYSICAL
166
  FAMILY
167
  OTHER
168
}
169

170
// XXX: Keep it in sync with constants/moods.ts
171
enum BaseMoodOption {
172
  SAD
173
  NEUTRAL
174
  GOOD
175
  GREAT
176
  ANGRY
177
}
178

179
enum MoodComponentOption {
180
  JOY
181
  NEUTRAL
182
  ANGER
183
  SADNESS
184
  ANXIETY
185
  GRATITUDE
186
  FOCUS
187
  TIREDNESS
188
}