Objective
Create a hierarchical category system for organizing video content. This enables structured content browsing, improved discovery, and organized video libraries.
Step 1: Create Categories Table
Create a hierarchical category structure.
CREATE TABLE video_categories (
id INTEGER PRIMARY KEY,
name VARCHAR(100) NOT NULL,
slug VARCHAR(100) NOT NULL UNIQUE,
description TEXT,
parent_id INTEGER,
level INTEGER DEFAULT 0,
sort_order INTEGER DEFAULT 0,
is_active BOOLEAN DEFAULT TRUE,
video_count INTEGER DEFAULT 0,
icon VARCHAR(50),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (parent_id) REFERENCES video_categories(id)
);
Step 2: Create Videos Table
Create a table for categorized videos.
CREATE TABLE categorized_videos (
id INTEGER PRIMARY KEY,
title VARCHAR(255) NOT NULL,
video_file VIDEO(MP4),
description TEXT,
category_id INTEGER NOT NULL,
duration_seconds INTEGER,
view_count INTEGER DEFAULT 0,
is_featured BOOLEAN DEFAULT FALSE,
publish_status VARCHAR(20) DEFAULT 'published',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (category_id) REFERENCES video_categories(id)
);
Step 3: Insert Categories
Create the category hierarchy.
INSERT INTO video_categories (id, name, slug, description, parent_id, level, sort_order, icon) VALUES
-- Top level categories
(1, 'Education', 'education', 'Educational and learning content', NULL, 0, 1, 'book'),
(2, 'Entertainment', 'entertainment', 'Entertainment and leisure content', NULL, 0, 2, 'film'),
(3, 'Business', 'business', 'Business and professional content', NULL, 0, 3, 'briefcase'),
(4, 'Technology', 'technology', 'Technology and software content', NULL, 0, 4, 'cpu'),
-- Education subcategories
(5, 'Tutorials', 'tutorials', 'Step-by-step learning guides', 1, 1, 1, 'play-circle'),
(6, 'Courses', 'courses', 'Complete learning courses', 1, 1, 2, 'graduation-cap'),
(7, 'Webinars', 'webinars', 'Live and recorded webinars', 1, 1, 3, 'video'),
-- Entertainment subcategories
(8, 'Vlogs', 'vlogs', 'Personal video blogs', 2, 1, 1, 'user'),
(9, 'Reviews', 'reviews', 'Product and service reviews', 2, 1, 2, 'star'),
(10, 'Behind the Scenes', 'behind-scenes', 'Making-of content', 2, 1, 3, 'camera'),
-- Business subcategories
(11, 'Marketing', 'marketing', 'Marketing and promotional content', 3, 1, 1, 'megaphone'),
(12, 'Training', 'training', 'Employee training videos', 3, 1, 2, 'users'),
(13, 'Presentations', 'presentations', 'Business presentations', 3, 1, 3, 'presentation'),
-- Technology subcategories
(14, 'Software Demos', 'software-demos', 'Software demonstrations', 4, 1, 1, 'monitor'),
(15, 'Tech News', 'tech-news', 'Technology news and updates', 4, 1, 2, 'newspaper'),
(16, 'Coding', 'coding', 'Programming tutorials', 4, 1, 3, 'code');
Step 4: Insert Sample Videos
Add videos to categories.
INSERT INTO categorized_videos (id, title, description, category_id, duration_seconds, view_count, is_featured) VALUES
-- Tutorials
(1, 'Getting Started Guide', 'Complete beginner guide', 5, 900, 15000, TRUE),
(2, 'Advanced Techniques', 'Pro tips and tricks', 5, 1200, 8500, FALSE),
-- Courses
(3, 'Python Fundamentals', 'Learn Python from scratch', 6, 7200, 25000, TRUE),
(4, 'Data Science Basics', 'Introduction to data science', 6, 5400, 18000, FALSE),
-- Marketing
(5, 'Brand Story', 'Our company journey', 11, 300, 5000, TRUE),
(6, 'Product Launch 2024', 'New product announcement', 11, 600, 12000, TRUE),
-- Software Demos
(7, 'Feature Walkthrough', 'Complete feature tour', 14, 1500, 9000, FALSE),
(8, 'API Integration Guide', 'How to integrate our API', 14, 1800, 6500, FALSE),
-- Coding
(9, 'JavaScript Basics', 'JS fundamentals tutorial', 16, 2400, 20000, TRUE),
(10, 'React Components', 'Building React components', 16, 1800, 15000, FALSE);