-- Create notifications table for backend-to-frontend notifications CREATE TABLE IF NOT EXISTS notifications ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE, notification_type VARCHAR(20) NOT NULL CHECK (notification_type IN ('success', 'error', 'info', 'warning')), title VARCHAR(255) NOT NULL, message TEXT NOT NULL, read BOOLEAN DEFAULT FALSE, action_url VARCHAR(500), metadata JSONB, created_at TIMESTAMPTZ DEFAULT NOW() ); -- Index for efficient user queries CREATE INDEX IF NOT EXISTS idx_notifications_user_id_created_at ON notifications(user_id, created_at DESC); -- Index for unread notifications CREATE INDEX IF NOT EXISTS idx_notifications_user_unread ON notifications(user_id, read) WHERE read = FALSE;