api: flesh moods
Pedro Lucas Porcellis porcellis@eletrotupi.com · 6 months ago
81ea07ae23bee8fabf5e0d87cf9cb89507a00384 Browse filesParents
b13456dChanged files
2
Additions
+64
Deletions
0
/dev/null → api/prisma/migrations/20260427222627_create_mood_and_mood_components/migration.sql
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
1 1
generator client {
2 2
provider = "prisma-client-js"
3 3
//output = "../src/generated/prisma"
4 4
}
5 5
16 16
passwordResetToken String? @map("password_reset_token")
17 17
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 +
}