gitdataai/libs/migrate/sql/m20250628_000001_create_room_notifications.sql
2026-04-15 09:08:09 +08:00

32 lines
945 B
SQL

CREATE TYPE notification_type AS ENUM (
'mention',
'invitation',
'role_change',
'room_created',
'room_deleted',
'system_announcement'
);
CREATE TABLE IF NOT EXISTS room_notifications (
id UUID PRIMARY KEY,
room UUID,
project UUID,
user_id UUID,
notification_type VARCHAR(255) NOT NULL,
related_message_id UUID,
related_user_id UUID,
related_room_id UUID,
title VARCHAR(255) NOT NULL,
content TEXT,
metadata JSONB,
is_read BOOLEAN NOT NULL DEFAULT false,
is_archived BOOLEAN NOT NULL DEFAULT false,
created_at TIMESTAMPTZ NOT NULL,
read_at TIMESTAMPTZ,
expires_at TIMESTAMPTZ
);
CREATE INDEX idx_room_notifications_user_id_is_read ON room_notifications (user_id, is_read);
CREATE INDEX idx_room_notifications_user_id_created_at ON room_notifications (user_id, created_at);
CREATE INDEX idx_room_notifications_expires_at ON room_notifications (expires_at);