CREATE TABLE IF NOT EXISTS user_sub_course_video_progress (
    id BIGSERIAL PRIMARY KEY,
    user_id BIGINT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
    sub_course_id BIGINT NOT NULL REFERENCES sub_courses(id) ON DELETE CASCADE,
    video_id BIGINT NOT NULL REFERENCES sub_course_videos(id) ON DELETE CASCADE,
    completed_at TIMESTAMP,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP
);

CREATE UNIQUE INDEX IF NOT EXISTS idx_user_video_progress_unique
ON user_sub_course_video_progress(user_id, video_id);

CREATE INDEX IF NOT EXISTS idx_user_video_progress_sub_course
ON user_sub_course_video_progress(user_id, sub_course_id);
