Files
easystream/__install/migrations/002_add_notifications_system.sql
T
Krystie f50b493df2 feat: Add comprehensive notification system with email support
- Create notification management system with VNotifications class
- Build notification API endpoints (get, mark read, delete, preferences)
- Implement notification bell UI widget with real-time polling
- Add email queue system with digest support (instant/hourly/daily/weekly)
- Create notification trigger helpers for common events
- Add fine-grained user preference controls
- Implement cron script for email processing and cleanup
- Document setup and usage in docs/NOTIFICATIONS.md

Features:
- In-app notifications with dropdown
- Email delivery with batching
- 6 notification types (comment, like, subscribe, upload, mention, system)
- User preference controls per notification type
- Lightweight polling (30s interval)
- Auto-cleanup of old notifications (90 days)
- Production-ready with proper error handling
2026-03-30 17:11:08 -07:00

61 lines
2.4 KiB
SQL

-- Migration: Add notification system tables
-- Main notifications table
CREATE TABLE IF NOT EXISTS db_notifications (
notification_id INT AUTO_INCREMENT PRIMARY KEY,
usr_id INT NOT NULL,
type ENUM('comment', 'like', 'subscribe', 'video_upload', 'mention', 'system') NOT NULL,
title VARCHAR(255) NOT NULL,
message TEXT,
link VARCHAR(512),
actor_id INT,
related_video_id INT,
related_comment_id INT,
is_read TINYINT(1) DEFAULT 0,
is_seen TINYINT(1) DEFAULT 0,
email_sent TINYINT(1) DEFAULT 0,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
read_at DATETIME NULL,
INDEX idx_user_read (usr_id, is_read),
INDEX idx_user_created (usr_id, created_at),
INDEX idx_type (type),
INDEX idx_actor (actor_id),
FOREIGN KEY (usr_id) REFERENCES db_accountuser(usr_id) ON DELETE CASCADE,
FOREIGN KEY (actor_id) REFERENCES db_accountuser(usr_id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- User notification preferences
CREATE TABLE IF NOT EXISTS db_notification_preferences (
preference_id INT AUTO_INCREMENT PRIMARY KEY,
usr_id INT NOT NULL UNIQUE,
email_comments TINYINT(1) DEFAULT 1,
email_likes TINYINT(1) DEFAULT 1,
email_subscribes TINYINT(1) DEFAULT 1,
email_uploads TINYINT(1) DEFAULT 1,
email_mentions TINYINT(1) DEFAULT 1,
email_digest ENUM('instant', 'hourly', 'daily', 'weekly', 'never') DEFAULT 'instant',
push_enabled TINYINT(1) DEFAULT 1,
push_comments TINYINT(1) DEFAULT 1,
push_likes TINYINT(1) DEFAULT 1,
push_subscribes TINYINT(1) DEFAULT 1,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (usr_id) REFERENCES db_accountuser(usr_id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- Email queue for batched/delayed sending
CREATE TABLE IF NOT EXISTS db_email_queue (
queue_id INT AUTO_INCREMENT PRIMARY KEY,
usr_id INT NOT NULL,
email VARCHAR(255) NOT NULL,
subject VARCHAR(255) NOT NULL,
body TEXT NOT NULL,
scheduled_for DATETIME NOT NULL,
sent_at DATETIME NULL,
attempts INT DEFAULT 0,
last_error TEXT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
INDEX idx_scheduled (scheduled_for, sent_at),
INDEX idx_user (usr_id),
FOREIGN KEY (usr_id) REFERENCES db_accountuser(usr_id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;