eletrotupi / tcc/ api/prisma/migrations/20261017030503_add_notifications/migration.sqlf1edb1555ea0c01ec072ceb15489d8f5fa0df5fb
936 B | 24 lines Raw
1
-- CreateEnum
2
CREATE TYPE "NotificationKind" AS ENUM ('DAILY_REMINDER', 'MEDICINE_REMINDER', 'INSIGHT_ALERT');
3

4
-- CreateTable
5
CREATE TABLE "notifications" (
6
    "id" SERIAL NOT NULL,
7
    "kind" "NotificationKind" NOT NULL,
8
    "title" TEXT NOT NULL,
9
    "body" TEXT NOT NULL,
10
    "scheduled_for" TIMESTAMP(3) NOT NULL,
11
    "expires_at" TIMESTAMP(3),
12
    "pushed_at" TIMESTAMP(3),
13
    "regimen_id" INTEGER,
14
    "user_id" INTEGER NOT NULL,
15
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
16

17
    CONSTRAINT "notifications_pkey" PRIMARY KEY ("id")
18
);
19

20
-- AddForeignKey
21
ALTER TABLE "notifications" ADD CONSTRAINT "notifications_regimen_id_fkey" FOREIGN KEY ("regimen_id") REFERENCES "medicine_regimens"("id") ON DELETE SET NULL ON UPDATE CASCADE;
22

23
-- AddForeignKey
24
ALTER TABLE "notifications" ADD CONSTRAINT "notifications_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;