eletrotupi / tcc / api/prisma/schema.prisma master
4.4 KB Raw
generator client {
  provider = "prisma-client-js"
  //output   = "../src/generated/prisma"
}

datasource db {
  provider = "postgresql"
}

model User {
  id                   Int       @id @default(autoincrement())
  firstName            String    @map("first_name")
  lastName             String?   @map("last_name")
  email                String    @unique
  encryptedPassword    String    @map("encrypted_password")
  passwordResetToken   String?   @map("password_reset_token")
  passwordResetExpires DateTime? @map("password_reset_expires")
  createdAt            DateTime  @default(now()) @map("created_at")
  updatedAt            DateTime  @updatedAt @map("updated_at")
  avatarKey            String?   @map("avatar_key")
  avatarURL            String?   @map("avatar_url")

  activationCode          String?   @map("activation_code")
  activationCodeExpiresAt DateTime? @map("activation_code_expires_at")
  active                  Boolean   @default(false) @map("active")

  pushToken String? @map("push_token")

  moods         Mood[]
  interventions Intervention[]
  triggers      Trigger[]
  reminders     Reminder[]
  sleepRecords  SleepRecord[]
  insights      Insight[]

  @@map("users")
}

model Mood {
  id           Int            @id @default(autoincrement())
  annotation   String?        @db.Text
  moment       DateTime       @default(now())
  selectedMood BaseMoodOption @default(GOOD) @map("selected_mood")
  anxietyLevel Int            @map("anxiety_level")
  stressLevel  Int            @map("stress_level")
  energyLevel  Int            @map("energy_level")
  userId       Int            @map("user_id")
  user         User           @relation(fields: [userId], references: [id])

  moodComponents MoodComponent[]

  @@map("moods")
}

model MoodComponent {
  id        Int                 @id @default(autoincrement())
  component MoodComponentOption
  intensity IntensityLevel      @default(LIGHT)

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

  @@map("mood_components")
}

model Intervention {
  id               Int              @id @default(autoincrement())
  comment          String?
  interventionType InterventionType @map("intervention_type")
  eficacy          Int
  startAt          DateTime         @map("start_at")
  endAt            DateTime         @map("end_at")

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

  @@map("interventions")
}

model Trigger {
  id       Int         @id @default(autoincrement())
  comment  String?     @db.Text
  category TriggerType
  moment   DateTime    @default(now())

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

  @@map("triggers")
}

model Reminder {
  id          Int     @id @default(autoincrement())
  hour        Int
  minute      Int
  description String?
  active      Boolean @default(false)

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

  @@map("reminders")
}

model SleepRecord {
  id          Int      @id @default(autoincrement())
  average     Float
  date        DateTime @db.Date
  annotations String?  @db.Text

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

  @@map("sleep_records")
}

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

  type        InsightType
  period      InsightPeriod
  title       String
  body        String        @db.Text
  metadata    Json? // flexible payload: correlations, deltas, scores
  generatedAt DateTime      @default(now()) @map("generated_at")
  periodStart DateTime      @map("period_start")
  periodEnd   DateTime      @map("period_end")

  @@unique([userId, type, periodStart])
  @@map("insights")
}

enum InsightType {
  MOOD_TREND
  ENERGY_SLEEP_CORRELATION
  TRIGGER_PATTERN
  WEEKLY_SUMMARY
  STREAK
  DAILY_ENERGY
  DAILY_SLEEP
}

enum InsightPeriod {
  DAILY
  WEEKLY
  MONTHLY
}

enum IntensityLevel {
  LIGHT
  MODERATE
  HIGH
}

enum InterventionType {
  MEDICATION
  THERAPY
  MEDITATION
  EXERCISE
  CONVERSATION
}

enum TriggerType {
  SOCIAL
  WORK
  HEALTH
  PHYSICAL
  FAMILY
  OTHER
}

// XXX: Keep it in sync with constants/moods.ts
enum BaseMoodOption {
  SAD
  NEUTRAL
  GOOD
  GREAT
  ANGRY
}

enum MoodComponentOption {
  JOY
  NEUTRAL
  ANGER
  SADNESS
  ANXIETY
  GRATITUDE
  FOCUS
  TIREDNESS
}