api: flesh moods

Pedro Lucas Porcellis porcellis@eletrotupi.com 2 months ago 81ea07ae23bee8fabf5e0d87cf9cb89507a00384
Parents: b13456d
2 file(s) changed
  • api/prisma/migrations/20260427222627_create_mood_and_mood_components/migration.sql +31 -0
  • api/prisma/schema.prisma +33 -0
api/prisma/migrations/20260427222627_create_mood_and_mood_components/migration.sql
@@ -0,0 +1,31 @@
1 + -- CreateEnum
2 + CREATE TYPE "IntensityLevel" AS ENUM ('LIGHT', 'MODERATE', 'HIGH');
3 +
4 + -- CreateTable
5 + CREATE TABLE "moods" (
6 + "id" SERIAL NOT NULL,
7 + "description" TEXT,
8 + "moment" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
9 + "anxiety_level" INTEGER NOT NULL,
10 + "stress_level" INTEGER NOT NULL,
11 + "energy_level" INTEGER NOT NULL,
12 + "user_id" INTEGER NOT NULL,
13 +
14 + CONSTRAINT "moods_pkey" PRIMARY KEY ("id")
15 + );
16 +
17 + -- CreateTable
18 + CREATE TABLE "mood_components" (
19 + "id" SERIAL NOT NULL,
20 + "comment" TEXT,
21 + "intensity" "IntensityLevel" NOT NULL DEFAULT 'LIGHT',
22 + "mood_id" INTEGER NOT NULL,
23 +
24 + CONSTRAINT "mood_components_pkey" PRIMARY KEY ("id")
25 + );
26 +
27 + -- AddForeignKey
28 + ALTER TABLE "moods" ADD CONSTRAINT "moods_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
29 +
30 + -- AddForeignKey
31 + ALTER TABLE "mood_components" ADD CONSTRAINT "mood_components_mood_id_fkey" FOREIGN KEY ("mood_id") REFERENCES "moods"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
api/prisma/schema.prisma
@@ -18,6 +18,39 @@ passwordResetExpires DateTime? @map("password_reset_expires")
18 18 createdAt DateTime @default(now()) @map("created_at")
19 19 updatedAt DateTime @updatedAt @map("updated_at")
20 20
21 + moods Mood[]
21 22
22 23 @@map("users")
23 24 }
25 +
26 + model Mood {
27 + id Int @id @default(autoincrement())
28 + description String? @db.Text
29 + moment DateTime @default(now())
30 + anxietyLevel Int @map("anxiety_level")
31 + stressLevel Int @map("stress_level")
32 + energyLevel Int @map("energy_level")
33 + userId Int @map("user_id")
34 + user User @relation(fields: [userId], references: [id])
35 +
36 + moodComponents MoodComponent[]
37 +
38 + @@map("moods")
39 + }
40 +
41 + model MoodComponent {
42 + id Int @id @default(autoincrement())
43 + comment String?
44 + intensity IntensityLevel @default(LIGHT)
45 +
46 + moodId Int @map("mood_id")
47 + mood Mood @relation(fields: [moodId], references: [id])
48 +
49 + @@map("mood_components")
50 + }
51 +
52 + enum IntensityLevel {
53 + LIGHT
54 + MODERATE
55 + HIGH
56 + }