a656c7685c
- Add threaded comment support (up to 5 levels deep) - Implement comment reactions (like, heart, laugh, thinking, sad, angry) - Add @mention system with user notifications - Enable comment pinning for video owners - Support comment editing with edit indicator - Build moderation system (approve/reject/delete/flag) - Create cached reaction counts for performance - Document enhanced comment system Features: - Nested comment threads with depth limiting - Six reaction types per comment - Automatic mention detection and notifications - Pin important comments - Edit history tracking - Comprehensive moderation tools - Optimized with aggregated counts - Production-ready with proper indexing
66 lines
3.0 KiB
SQL
66 lines
3.0 KiB
SQL
-- Migration: Enhance comment system with threading, reactions, and moderation
|
|
|
|
-- Add threading support to existing comments
|
|
ALTER TABLE db_comments
|
|
ADD COLUMN parent_comment_id INT DEFAULT NULL AFTER video_id,
|
|
ADD COLUMN depth INT DEFAULT 0 AFTER parent_comment_id,
|
|
ADD COLUMN is_pinned TINYINT DEFAULT 0 AFTER approved,
|
|
ADD COLUMN is_edited TINYINT DEFAULT 0 AFTER is_pinned,
|
|
ADD COLUMN edited_at DATETIME DEFAULT NULL AFTER is_edited,
|
|
ADD INDEX idx_parent (parent_comment_id),
|
|
ADD INDEX idx_pinned (video_id, is_pinned),
|
|
ADD FOREIGN KEY (parent_comment_id) REFERENCES db_comments(comment_id) ON DELETE CASCADE;
|
|
|
|
-- Comment reactions (likes, heart, laugh, etc.)
|
|
CREATE TABLE IF NOT EXISTS db_comment_reactions (
|
|
reaction_id INT AUTO_INCREMENT PRIMARY KEY,
|
|
comment_id INT NOT NULL,
|
|
usr_id INT NOT NULL,
|
|
reaction_type ENUM('like', 'heart', 'laugh', 'thinking', 'sad', 'angry') DEFAULT 'like',
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
UNIQUE KEY unique_user_comment_reaction (comment_id, usr_id, reaction_type),
|
|
INDEX idx_comment (comment_id),
|
|
FOREIGN KEY (comment_id) REFERENCES db_comments(comment_id) ON DELETE CASCADE,
|
|
FOREIGN KEY (usr_id) REFERENCES db_users(usr_id) ON DELETE CASCADE
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- Comment moderation actions
|
|
CREATE TABLE IF NOT EXISTS db_comment_moderation (
|
|
moderation_id INT AUTO_INCREMENT PRIMARY KEY,
|
|
comment_id INT NOT NULL,
|
|
moderator_id INT NOT NULL,
|
|
action ENUM('approve', 'reject', 'delete', 'flag', 'unflag') NOT NULL,
|
|
reason TEXT,
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
INDEX idx_comment (comment_id),
|
|
INDEX idx_moderator (moderator_id),
|
|
FOREIGN KEY (comment_id) REFERENCES db_comments(comment_id) ON DELETE CASCADE,
|
|
FOREIGN KEY (moderator_id) REFERENCES db_users(usr_id) ON DELETE CASCADE
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- Comment mentions (@username)
|
|
CREATE TABLE IF NOT EXISTS db_comment_mentions (
|
|
mention_id INT AUTO_INCREMENT PRIMARY KEY,
|
|
comment_id INT NOT NULL,
|
|
mentioned_user_id INT NOT NULL,
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
UNIQUE KEY unique_comment_user (comment_id, mentioned_user_id),
|
|
INDEX idx_mentioned_user (mentioned_user_id),
|
|
FOREIGN KEY (comment_id) REFERENCES db_comments(comment_id) ON DELETE CASCADE,
|
|
FOREIGN KEY (mentioned_user_id) REFERENCES db_users(usr_id) ON DELETE CASCADE
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- Aggregate reaction counts (for performance)
|
|
CREATE TABLE IF NOT EXISTS db_comment_reaction_counts (
|
|
comment_id INT PRIMARY KEY,
|
|
like_count INT DEFAULT 0,
|
|
heart_count INT DEFAULT 0,
|
|
laugh_count INT DEFAULT 0,
|
|
thinking_count INT DEFAULT 0,
|
|
sad_count INT DEFAULT 0,
|
|
angry_count INT DEFAULT 0,
|
|
total_count INT DEFAULT 0,
|
|
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
FOREIGN KEY (comment_id) REFERENCES db_comments(comment_id) ON DELETE CASCADE
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|