[BE-DB-008] be-db: Create migration for notifications table

This commit is contained in:
senke 2025-12-24 15:12:11 +01:00
parent 5c8a49d4f5
commit 974ef31a9c
2 changed files with 41 additions and 2 deletions

View file

@ -3175,7 +3175,7 @@
"description": "Add table for user notifications",
"owner": "backend",
"estimated_hours": 3,
"status": "todo",
"status": "completed",
"files_involved": [],
"implementation_steps": [
{
@ -3196,7 +3196,9 @@
"Unit tests",
"Integration tests"
],
"notes": ""
"notes": "",
"completed_at": "2025-12-24T15:12:10.659377",
"implementation_notes": "Created migration 047_notifications.sql for notifications table. Migration includes: id (UUID), user_id (FK to users), type (VARCHAR), title (VARCHAR), content (TEXT), link (VARCHAR), read (BOOLEAN), timestamps (created_at, updated_at, read_at), and appropriate indexes for user_id, read status, created_at, and type. Table structure matches NotificationService usage."
},
{
"id": "BE-DB-009",

View file

@ -0,0 +1,37 @@
-- 047_notifications.sql
-- User Notifications (BE-DB-008: Create migration for notifications table)
-- Add table for user notifications
-- === NOTIFICATIONS ===
-- Table for storing user notifications
CREATE TABLE IF NOT EXISTS public.notifications (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_id UUID NOT NULL REFERENCES public.users(id) ON DELETE CASCADE,
-- Notification Content
type VARCHAR(50) NOT NULL,
title VARCHAR(255) NOT NULL,
content TEXT,
link VARCHAR(500),
-- Status
read BOOLEAN NOT NULL DEFAULT FALSE,
-- Timestamps
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
read_at TIMESTAMPTZ
);
-- Indexes
CREATE INDEX IF NOT EXISTS idx_notifications_user_id ON public.notifications(user_id);
CREATE INDEX IF NOT EXISTS idx_notifications_user_id_read ON public.notifications(user_id, read) WHERE read = FALSE;
CREATE INDEX IF NOT EXISTS idx_notifications_created_at_desc ON public.notifications(created_at DESC);
CREATE INDEX IF NOT EXISTS idx_notifications_type ON public.notifications(type);
-- Comments
COMMENT ON TABLE public.notifications IS 'User notifications for various events';
COMMENT ON COLUMN public.notifications.type IS 'Type of notification (e.g., follow, like, comment, message)';
COMMENT ON COLUMN public.notifications.read IS 'Whether the notification has been read';
COMMENT ON COLUMN public.notifications.read_at IS 'Timestamp when the notification was marked as read';