20231004130100_create_notifications.sql

 1CREATE TABLE "notification_kinds" (
 2    "id" SERIAL PRIMARY KEY,
 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    "is_read" BOOLEAN NOT NULL DEFAULT FALSE,
11    "created_at" TIMESTAMP NOT NULL DEFAULT now(),
12    "recipient_id" INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE,
13    "actor_id" INTEGER REFERENCES users (id) ON DELETE CASCADE,
14    "kind" INTEGER NOT NULL REFERENCES notification_kinds (id),
15    "content" TEXT
16);
17
18CREATE INDEX "index_notifications_on_recipient_id" ON "notifications" ("recipient_id");