Skip to content

Commit 73f1dcc

Browse files
committed
Add missing migration
1 parent 14216b5 commit 73f1dcc

File tree

2 files changed

+56
-3
lines changed

2 files changed

+56
-3
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
-- CreateEnum
2+
CREATE TYPE "NotificationPayloadType" AS ENUM ('URL', 'EVENT', 'ARTICLE', 'GROUP', 'USER', 'OFFLINE', 'JOB_LISTING', 'NONE');
3+
4+
-- CreateEnum
5+
CREATE TYPE "NotificationType" AS ENUM ('BROADCAST', 'BROADCAST_IMPORTANT', 'EVENT_REGISTRATION', 'EVENT_REMINDER', 'EVENT_UPDATE', 'JOB_LISTING_REMINDER', 'NEW_ARTICLE', 'NEW_EVENT', 'NEW_INTEREST_GROUP', 'NEW_JOB_LISTING', 'NEW_OFFLINE', 'NEW_MARK', 'NEW_FEEDBACK_FORM');
6+
7+
-- CreateTable
8+
CREATE TABLE "NotificationRecipient" (
9+
"id" TEXT NOT NULL,
10+
"read_at" TIMESTAMPTZ(3) NOT NULL,
11+
"notification_id" TEXT NOT NULL,
12+
"user_id" TEXT NOT NULL,
13+
14+
CONSTRAINT "NotificationRecipient_pkey" PRIMARY KEY ("id")
15+
);
16+
17+
-- CreateTable
18+
CREATE TABLE "notification" (
19+
"id" TEXT NOT NULL,
20+
"created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
21+
"updated_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
22+
"title" TEXT NOT NULL,
23+
"short_description" TEXT,
24+
"content" TEXT NOT NULL,
25+
"type" "NotificationType" NOT NULL,
26+
"payload" TEXT,
27+
"payload_type" "NotificationPayloadType" NOT NULL,
28+
"actor_group_id" TEXT NOT NULL,
29+
"created_by_id" TEXT,
30+
"last_updated_by_id" TEXT,
31+
"task_id" TEXT,
32+
33+
CONSTRAINT "notification_pkey" PRIMARY KEY ("id")
34+
);
35+
36+
-- AddForeignKey
37+
ALTER TABLE "NotificationRecipient" ADD CONSTRAINT "NotificationRecipient_notification_id_fkey" FOREIGN KEY ("notification_id") REFERENCES "notification"("id") ON DELETE CASCADE ON UPDATE CASCADE;
38+
39+
-- AddForeignKey
40+
ALTER TABLE "NotificationRecipient" ADD CONSTRAINT "NotificationRecipient_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "ow_user"("id") ON DELETE CASCADE ON UPDATE CASCADE;
41+
42+
-- AddForeignKey
43+
ALTER TABLE "notification" ADD CONSTRAINT "notification_actor_group_id_fkey" FOREIGN KEY ("actor_group_id") REFERENCES "group"("slug") ON DELETE RESTRICT ON UPDATE CASCADE;
44+
45+
-- AddForeignKey
46+
ALTER TABLE "notification" ADD CONSTRAINT "notification_created_by_id_fkey" FOREIGN KEY ("created_by_id") REFERENCES "ow_user"("id") ON DELETE SET NULL ON UPDATE CASCADE;
47+
48+
-- AddForeignKey
49+
ALTER TABLE "notification" ADD CONSTRAINT "notification_last_updated_by_id_fkey" FOREIGN KEY ("last_updated_by_id") REFERENCES "ow_user"("id") ON DELETE SET NULL ON UPDATE CASCADE;
50+
51+
-- AddForeignKey
52+
ALTER TABLE "notification" ADD CONSTRAINT "notification_task_id_fkey" FOREIGN KEY ("task_id") REFERENCES "task"("id") ON DELETE SET NULL ON UPDATE CASCADE;

packages/db/prisma/schema.prisma

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ model User {
8686
attendeesRefunded Attendee[] @relation(name: "RefundedBy")
8787
auditLogs AuditLog[]
8888
deregisterReasons DeregisterReason[]
89-
notificationsCreated Notification[]
9089
notificationsReceived NotificationRecipient[]
90+
notificationsCreated Notification[] @relation("created_by")
91+
notificationsUpdated Notification[] @relation("last_updated_by")
9192
9293
@@map("ow_user")
9394
}
@@ -813,9 +814,9 @@ model Notification {
813814
/// The specific user that created the notification. This is meant for logging purposes. Nullable because the system
814815
/// can create notifications without a specific user to link it to, for example with recurring tasks.
815816
createdById String? @map("created_by_id")
816-
createdBy User? @relation(fields: [createdById], references: [id])
817+
createdBy User? @relation("created_by", fields: [createdById], references: [id])
817818
lastUpdatedById String? @map("last_updated_by_id")
818-
lastUpdatedBy User? @relation(fields: [lastUpdatedById], references: [id])
819+
lastUpdatedBy User? @relation("last_updated_by", fields: [lastUpdatedById], references: [id])
819820
/// The task that created the notification. Useful for tracing and retrieving deadlines that could be useful for the
820821
/// notification.
821822
taskId String? @map("task_id")

0 commit comments

Comments
 (0)