20231004130100_create_notifications.sql

 1CREATE TABLE "notification_kinds" (
 2    "id" INTEGER PRIMARY KEY NOT NULL,
 3    "name" VARCHAR NOT NULL,
 4);
 5
 6CREATE UNIQUE INDEX "index_notification_kinds_on_name" ON "notification_kinds" ("name");
 7
 8CREATE TABLE notifications (
 9    "id" SERIAL PRIMARY KEY,
10    "created_at" TIMESTAMP NOT NULL DEFAULT now(),
11    "recipent_id" INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE,
12    "kind" INTEGER NOT NULL REFERENCES notification_kinds (id),
13    "is_read" BOOLEAN NOT NULL DEFAULT FALSE
14    "entity_id_1" INTEGER,
15    "entity_id_2" INTEGER
16);
17
18CREATE INDEX "index_notifications_on_recipient_id" ON "notifications" ("recipient_id");