-- ============================================================================ -- EasyStream Template Builder Database Schema -- ============================================================================ -- This schema adds drag-and-drop template builder functionality to EasyStream -- Users can create custom page layouts using a visual drag-and-drop interface -- ============================================================================ -- Template Builder: Store custom user-created templates CREATE TABLE IF NOT EXISTS `db_templatebuilder_templates` ( `template_id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, `user_id` INT(11) UNSIGNED NOT NULL, `template_name` VARCHAR(255) NOT NULL, `template_slug` VARCHAR(255) NOT NULL, `template_type` ENUM('homepage', 'channel', 'browse', 'custom_page', 'landing') DEFAULT 'custom_page', `is_active` TINYINT(1) DEFAULT 0, `is_default` TINYINT(1) DEFAULT 0, `template_structure` LONGTEXT NOT NULL COMMENT 'JSON structure of template layout', `template_settings` TEXT COMMENT 'JSON settings (colors, fonts, spacing)', `custom_css` LONGTEXT COMMENT 'User custom CSS', `custom_js` TEXT COMMENT 'User custom JavaScript', `preview_image` VARCHAR(255) DEFAULT NULL, `views` INT(11) DEFAULT 0, `created_at` DATETIME DEFAULT CURRENT_TIMESTAMP, `updated_at` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`template_id`), UNIQUE KEY `unique_slug` (`template_slug`), KEY `idx_user` (`user_id`), KEY `idx_type` (`template_type`), KEY `idx_active` (`is_active`), CONSTRAINT `fk_template_user` FOREIGN KEY (`user_id`) REFERENCES `db_accountuser` (`usr_id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='User-created custom templates'; -- Template Builder: Component library (pre-built blocks users can drag) CREATE TABLE IF NOT EXISTS `db_templatebuilder_components` ( `component_id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, `component_name` VARCHAR(255) NOT NULL, `component_slug` VARCHAR(255) NOT NULL, `component_category` ENUM('header', 'hero', 'video_grid', 'video_list', 'sidebar', 'footer', 'text', 'image', 'custom') DEFAULT 'custom', `component_html` LONGTEXT NOT NULL COMMENT 'Smarty template HTML', `component_css` TEXT COMMENT 'Component-specific CSS', `component_settings_schema` TEXT COMMENT 'JSON schema for configurable settings', `is_system` TINYINT(1) DEFAULT 1 COMMENT 'System component (cannot be deleted)', `thumbnail` VARCHAR(255) DEFAULT NULL, `description` TEXT, `created_by` INT(11) UNSIGNED DEFAULT NULL, `created_at` DATETIME DEFAULT CURRENT_TIMESTAMP, `updated_at` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`component_id`), UNIQUE KEY `unique_slug` (`component_slug`), KEY `idx_category` (`component_category`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Reusable template components'; -- Template Builder: Page assignments (which templates apply to which pages) CREATE TABLE IF NOT EXISTS `db_templatebuilder_assignments` ( `assignment_id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, `template_id` INT(11) UNSIGNED NOT NULL, `page_type` VARCHAR(100) NOT NULL COMMENT 'e.g., tpl_browse, tpl_view, tpl_index', `apply_to` ENUM('global', 'user_only', 'channel') DEFAULT 'user_only', `priority` INT(11) DEFAULT 0, `is_active` TINYINT(1) DEFAULT 1, `created_at` DATETIME DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`assignment_id`), KEY `idx_template` (`template_id`), KEY `idx_page` (`page_type`), KEY `idx_active` (`is_active`), CONSTRAINT `fk_assignment_template` FOREIGN KEY (`template_id`) REFERENCES `db_templatebuilder_templates` (`template_id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Template to page assignments'; -- Template Builder: Version history for templates CREATE TABLE IF NOT EXISTS `db_templatebuilder_versions` ( `version_id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, `template_id` INT(11) UNSIGNED NOT NULL, `version_number` INT(11) NOT NULL, `template_structure` LONGTEXT NOT NULL, `template_settings` TEXT, `custom_css` LONGTEXT, `custom_js` TEXT, `change_note` VARCHAR(500) DEFAULT NULL, `created_at` DATETIME DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`version_id`), KEY `idx_template` (`template_id`), KEY `idx_version` (`version_number`), CONSTRAINT `fk_version_template` FOREIGN KEY (`template_id`) REFERENCES `db_templatebuilder_templates` (`template_id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Template version history'; -- Template Builder: User preferences and settings CREATE TABLE IF NOT EXISTS `db_templatebuilder_user_prefs` ( `pref_id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, `user_id` INT(11) UNSIGNED NOT NULL, `active_template_homepage` INT(11) UNSIGNED DEFAULT NULL, `active_template_channel` INT(11) UNSIGNED DEFAULT NULL, `active_template_browse` INT(11) UNSIGNED DEFAULT NULL, `builder_mode` ENUM('simple', 'advanced') DEFAULT 'simple', `auto_save` TINYINT(1) DEFAULT 1, `show_grid` TINYINT(1) DEFAULT 1, `preferences` TEXT COMMENT 'JSON additional preferences', `updated_at` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`pref_id`), UNIQUE KEY `unique_user` (`user_id`), CONSTRAINT `fk_prefs_user` FOREIGN KEY (`user_id`) REFERENCES `db_accountuser` (`usr_id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='User template builder preferences'; -- ============================================================================ -- Insert Default System Components -- ============================================================================ -- Component: Video Grid (4 columns) INSERT INTO `db_templatebuilder_components` (`component_name`, `component_slug`, `component_category`, `component_html`, `component_css`, `component_settings_schema`, `is_system`, `description`) VALUES ('Video Grid - 4 Columns', 'video_grid_4col', 'video_grid', '
{{caption}}
{/if}Your custom HTML here
"}, "padding": {"type": "number", "default": 0}}', 1, 'Custom HTML/Smarty code block'); -- ============================================================================ -- Add permissions for template builder (optional - if using permissions system) -- ============================================================================ -- Note: Adjust table name if your permissions table is different -- INSERT INTO `db_permissions` (`permission_name`, `permission_slug`, `description`) -- VALUES -- ('Template Builder Access', 'template_builder_access', 'Can access template builder'), -- ('Template Builder Advanced', 'template_builder_advanced', 'Can use advanced features like custom CSS/JS'), -- ('Template Builder Admin', 'template_builder_admin', 'Can manage system components and global templates'); -- ============================================================================ -- Indexes for performance -- ============================================================================ -- Additional indexes are already included in table definitions above -- ============================================================================ -- End of Template Builder Schema -- ============================================================================