CREATE TABLE IF NOT EXISTS user_practice_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,
    question_set_id BIGINT NOT NULL REFERENCES question_sets(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_practice_progress_unique
ON user_practice_progress(user_id, question_set_id);

CREATE INDEX IF NOT EXISTS idx_user_practice_progress_sub_course
ON user_practice_progress(user_id, sub_course_id);
