api: add interventions

Pedro Lucas Porcellis porcellis@eletrotupi.com 2 months ago 95520d874f28f49a762a222a2ab593de585a0436
Parents: 81ea07a
2 file(s) changed
  • api/prisma/migrations/20260427224658_create_interventions/migration.sql +18 -0
  • api/prisma/schema.prisma +23 -0
api/prisma/migrations/20260427224658_create_interventions/migration.sql
@@ -0,0 +1,18 @@
1 + -- CreateEnum
2 + CREATE TYPE "InterventionType" AS ENUM ('MEDICATION', 'THERAPY', 'MEDITATION', 'EXERCISE', 'CONVERSATION');
3 +
4 + -- CreateTable
5 + CREATE TABLE "interventions" (
6 + "id" SERIAL NOT NULL,
7 + "comment" TEXT,
8 + "intervention_type" "InterventionType" NOT NULL,
9 + "eficacy" INTEGER NOT NULL,
10 + "start_at" TIMESTAMP(3) NOT NULL,
11 + "end_at" TIMESTAMP(3) NOT NULL,
12 + "user_id" INTEGER NOT NULL,
13 +
14 + CONSTRAINT "interventions_pkey" PRIMARY KEY ("id")
15 + );
16 +
17 + -- AddForeignKey
18 + ALTER TABLE "interventions" ADD CONSTRAINT "interventions_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
api/prisma/schema.prisma
@@ -19,6 +19,7 @@ createdAt DateTime @default(now()) @map("created_at")
19 19 updatedAt DateTime @updatedAt @map("updated_at")
20 20
21 21 moods Mood[]
22 + interventions Intervention[]
22 23
23 24 @@map("users")
24 25 }
@@ -49,8 +50,30 @@
49 50 @@map("mood_components")
50 51 }
51 52
53 + model Intervention {
54 + id Int @id @default(autoincrement())
55 + comment String?
56 + interventionType InterventionType @map("intervention_type")
57 + eficacy Int
58 + startAt DateTime @map("start_at")
59 + endAt DateTime @map("end_at")
60 +
61 + userId Int @map("user_id")
62 + user User @relation(fields: [userId], references: [id])
63 +
64 + @@map("interventions")
65 + }
66 +
52 67 enum IntensityLevel {
53 68 LIGHT
54 69 MODERATE
55 70 HIGH
56 71 }
72 +
73 + enum InterventionType {
74 + MEDICATION
75 + THERAPY
76 + MEDITATION
77 + EXERCISE
78 + CONVERSATION
79 + }