eletrotupi / tcc/ api/prisma/schema.prismaa2d0b31fb95ea93e87b5ebca20daa4402d0a5b99
4.4 KB | 190 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
  @@map("triggers")
90
}
91

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

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

102
  @@map("reminders")
103
}
104

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

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

114
  @@map("sleep_records")
115
}
116

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

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

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

135
enum InsightType {
136
  MOOD_TREND
137
  ENERGY_SLEEP_CORRELATION
138
  TRIGGER_PATTERN
139
  WEEKLY_SUMMARY
140
  STREAK
141
}
142

143
enum InsightPeriod {
144
  DAILY
145
  WEEKLY
146
  MONTHLY
147
}
148

149
enum IntensityLevel {
150
  LIGHT
151
  MODERATE
152
  HIGH
153
}
154

155
enum InterventionType {
156
  MEDICATION
157
  THERAPY
158
  MEDITATION
159
  EXERCISE
160
  CONVERSATION
161
}
162

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

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

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