Files
aura-crm/production/backend/migrations/035_notifications.sql
T

30 lines
1.4 KiB
SQL

-- +goose Up
-- Internal in-app notifications (Фаза 19) — separate from internal/notify
-- (outbound Telegram push only, nothing persisted/read-tracked) and
-- internal/realtime (a content-free "something changed" SSE signal). This
-- is a real inbox: persisted, has a read state, and an actionable
-- notification can carry a one-click action a staff member resolves it
-- with (e.g. "Подтвердить производство" for a low-stock finished-toner
-- alert — see internal/manufacture's trigger_mode).
--
-- Shared/global, not per-staff — this is a small-team app (see
-- internal/notify's single shared Telegram chat for the same design
-- choice) and every notification here concerns something any staff member
-- with the right permission can act on; there is no per-user targeting
-- need yet.
CREATE TABLE notifications (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
type TEXT NOT NULL,
title TEXT NOT NULL,
body TEXT,
-- NULL action_type = informational only, dismissed by marking read.
action_type TEXT,
action_payload JSONB,
read_at TIMESTAMPTZ,
resolved_at TIMESTAMPTZ,
resolved_by_staff_name TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE INDEX notifications_unread_idx ON notifications (created_at DESC) WHERE read_at IS NULL;