CREATE TABLE courses (
course_id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
creator_user_id BIGINT UNSIGNED NOT NULL,
tenant_id BIGINT UNSIGNED DEFAULT NULL,
title VARCHAR(255) NOT NULL,
slug VARCHAR(150) UNIQUE NOT NULL,
description TEXT,
cover_image_url VARCHAR(500),
estimated_duration_minutes INT UNSIGNED,
difficulty ENUM('beginner', 'intermediate', 'advanced') DEFAULT 'intermediate',
language CHAR(2) DEFAULT 'tr',
learning_objectives JSON,
prerequisites JSON,
status ENUM('draft', 'published', 'archived') DEFAULT 'draft',
version INT UNSIGNED DEFAULT 1,
ai_generated TINYINT(1) DEFAULT 0,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
INDEX idx_slug (slug),
INDEX idx_creator (creator_user_id),
INDEX idx_tenant (tenant_id)
);
CREATE TABLE academy_course_links (
link_id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
academy_id BIGINT UNSIGNED NOT NULL,
course_id BIGINT UNSIGNED NOT NULL,
display_title VARCHAR(255) DEFAULT NULL,
display_description TEXT DEFAULT NULL,
display_order INT UNSIGNED DEFAULT 0,
access_level ENUM('open', 'invite_only', 'group_restricted', 'paid') DEFAULT 'invite_only',
start_date DATETIME DEFAULT NULL,
end_date DATETIME DEFAULT NULL,
group_ids JSON DEFAULT NULL,
completion_criteria JSON DEFAULT NULL,
custom_price DECIMAL(10,2) DEFAULT NULL,
status ENUM('active', 'hidden', 'scheduled') DEFAULT 'active',
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
UNIQUE KEY uk_academy_course (academy_id, course_id),
FOREIGN KEY (academy_id) REFERENCES academies(academy_id) ON DELETE CASCADE,
FOREIGN KEY (course_id) REFERENCES courses(course_id) ON DELETE RESTRICT
);
CREATE TABLE course_modules (
module_id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
course_id BIGINT UNSIGNED NOT NULL,
title VARCHAR(255) NOT NULL,
slug VARCHAR(150) NOT NULL,
module_type ENUM('detailed_content', 'quiz', 'flashcards', 'audio_script', 'case_study', 'discussion_topics', 'faq', 'roleplay', 'project', 'other') NOT NULL,
display_order INT UNSIGNED NOT NULL,
is_required TINYINT(1) DEFAULT 1,
estimated_duration_minutes SMALLINT UNSIGNED,
prerequisites JSON,
content JSON,
ai_prompt_used TEXT,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
UNIQUE KEY uk_course_module (course_id, slug),
FOREIGN KEY (course_id) REFERENCES courses(course_id) ON DELETE CASCADE,
INDEX idx_course_order (course_id, display_order)
);
CREATE TABLE module_sections (
section_id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
module_id BIGINT UNSIGNED NOT NULL,
title VARCHAR(255),
content_type ENUM('text', 'video_script', 'infographic_desc', 'quiz_embed', 'discussion_prompt'),
content JSON,
display_order INT UNSIGNED,
FOREIGN KEY (module_id) REFERENCES course_modules(module_id) ON DELETE CASCADE
);
CREATE TABLE user_course_progress (
progress_id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
user_id BIGINT UNSIGNED NOT NULL,
academy_id BIGINT UNSIGNED NOT NULL,
course_id BIGINT UNSIGNED NOT NULL,
completion_percentage DECIMAL(5,2) DEFAULT 0.00,
started_at DATETIME,
completed_at DATETIME,
last_activity DATETIME,
FOREIGN KEY (academy_id) REFERENCES academies(academy_id) ON DELETE CASCADE,
FOREIGN KEY (course_id) REFERENCES courses(course_id) ON DELETE RESTRICT,
UNIQUE KEY uk_user_academy_course (user_id, academy_id, course_id)
);