Objective
Create a user-generated content video platform with upload management, moderation, and engagement tracking. This pattern supports social video platforms and community-driven content sites.
Step 1: Create Users Table
Create a table for content creators.
CREATE TABLE video_creators (
id INTEGER PRIMARY KEY,
username VARCHAR(50) NOT NULL UNIQUE,
display_name VARCHAR(100),
email VARCHAR(255) NOT NULL,
avatar IMAGE(JPEG),
bio TEXT,
subscriber_count INTEGER DEFAULT 0,
total_views INTEGER DEFAULT 0,
video_count INTEGER DEFAULT 0,
is_verified BOOLEAN DEFAULT FALSE,
is_active BOOLEAN DEFAULT TRUE,
joined_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Step 2: Create User Videos Table
Create a table for user-uploaded videos.
CREATE TABLE user_videos (
id INTEGER PRIMARY KEY,
creator_id INTEGER NOT NULL,
title VARCHAR(255) NOT NULL,
description TEXT,
video_file VIDEO(MP4),
thumbnail IMAGE(JPEG),
duration_seconds INTEGER,
file_size BIGINT,
resolution VARCHAR(20),
view_count INTEGER DEFAULT 0,
like_count INTEGER DEFAULT 0,
dislike_count INTEGER DEFAULT 0,
comment_count INTEGER DEFAULT 0,
share_count INTEGER DEFAULT 0,
moderation_status VARCHAR(20) DEFAULT 'pending',
visibility VARCHAR(20) DEFAULT 'public',
is_monetized BOOLEAN DEFAULT FALSE,
tags VARCHAR(500),
upload_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
publish_date TIMESTAMP,
FOREIGN KEY (creator_id) REFERENCES video_creators(id)
);
Step 3: Create Moderation Table
Track video moderation history.
CREATE TABLE video_moderation (
id INTEGER PRIMARY KEY,
video_id INTEGER NOT NULL,
moderator_id VARCHAR(100),
previous_status VARCHAR(20),
new_status VARCHAR(20) NOT NULL,
reason TEXT,
notes TEXT,
moderated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (video_id) REFERENCES user_videos(id)
);
Step 4: Create Engagement Table
Track video interactions.
CREATE TABLE video_engagement (
id INTEGER PRIMARY KEY,
video_id INTEGER NOT NULL,
user_id INTEGER NOT NULL,
engagement_type VARCHAR(20) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (video_id) REFERENCES user_videos(id)
);
Step 5: Insert Sample Creators
Add sample content creators.
INSERT INTO video_creators (id, username, display_name, email, bio, subscriber_count, total_views, video_count, is_verified) VALUES
(1, 'techguru', 'Tech Guru', 'techguru@example.com', 'Tech reviews and tutorials', 150000, 5000000, 120, TRUE),
(2, 'cookingqueen', 'Cooking Queen', 'cooking@example.com', 'Delicious recipes for everyone', 85000, 2500000, 200, TRUE),
(3, 'gamerpro', 'Gamer Pro', 'gamer@example.com', 'Gaming walkthroughs and tips', 250000, 8000000, 350, TRUE),
(4, 'diycraft', 'DIY Craft', 'diy@example.com', 'Creative DIY projects', 45000, 1200000, 80, FALSE),
(5, 'fitnessfan', 'Fitness Fan', 'fitness@example.com', 'Home workout routines', 60000, 1800000, 95, FALSE);
Step 6: Insert User Videos
Add user-uploaded videos.
INSERT INTO user_videos (id, creator_id, title, description, duration_seconds, file_size, resolution, view_count, like_count, comment_count, moderation_status, visibility, tags, publish_date) VALUES
(1, 1, 'iPhone 15 Review', 'Comprehensive review of the new iPhone', 1200, 524288000, '4K', 125000, 8500, 1200, 'approved', 'public', 'iphone,apple,review,tech', '2024-01-15 10:00:00'),
(2, 1, 'Best Budget Laptops 2024', 'Top 5 affordable laptops', 900, 393216000, '1080p', 85000, 5200, 800, 'approved', 'public', 'laptop,budget,tech', '2024-01-20 14:00:00'),
(3, 2, 'Easy Pasta Recipe', '15 minute pasta dish', 600, 262144000, '1080p', 95000, 7800, 450, 'approved', 'public', 'pasta,cooking,easy', '2024-01-18 12:00:00'),
(4, 2, 'Chocolate Cake Tutorial', 'Perfect chocolate cake', 1500, 655360000, '1080p', 120000, 9500, 680, 'approved', 'public', 'cake,chocolate,baking', '2024-01-22 09:00:00'),
(5, 3, 'Game Walkthrough Part 1', 'Complete first chapter', 3600, 1572864000, '4K', 250000, 15000, 2500, 'approved', 'public', 'gaming,walkthrough', '2024-01-10 16:00:00'),
(6, 3, 'Pro Gaming Tips', 'Improve your skills', 900, 393216000, '1080p', 180000, 12000, 1800, 'approved', 'public', 'gaming,tips,tutorial', '2024-01-25 18:00:00'),
(7, 4, 'DIY Home Decor', 'Budget home decoration', 1200, 524288000, '1080p', 45000, 3200, 320, 'approved', 'public', 'diy,decor,home', '2024-01-28 11:00:00'),
(8, 5, '30 Min Full Body Workout', 'No equipment needed', 1800, 786432000, '1080p', 75000, 5500, 420, 'approved', 'public', 'workout,fitness,home', '2024-01-30 07:00:00'),
(9, 1, 'Unreleased Product Leak', 'Leaked specifications', 600, 262144000, '1080p', 0, 0, 0, 'rejected', 'private', 'leak,unreleased', NULL),
(10, 4, 'New Craft Project', 'Coming soon preview', 300, 131072000, '1080p', 0, 0, 0, 'pending', 'unlisted', 'craft,preview', NULL);