Seed the vendor catalogue into SQL and add an optional AI course advisor
Course metadata: a scan now gives every course a course_meta row from the downloader's sidecar JSON when the folder has one, else from catalog_courses matched by the folder name the downloader would create (folderKeyFor, a port of ine.py's sanitize_name). tools/build-catalog-seed.php turns the INE export into seeds/ine_catalog.sql, an idempotent patch that creates its own table and upserts by id, so it can be applied to the live server before or after the code and re-run freely. Course pages show the blurb, difficulty, vendor and tags; search matches tags and blurbs; Settings reports how each course got its details. Against the live library 163 of 179 courses match. Course advisor, off by default: api/advisor.php answers "which course should I take to learn X / what comes before Y" with courses from the library, in order, plus vendor courses not yet downloaded. includes/ai_client.php is a small curl wrapper for any OpenAI-format chat endpoint (DeepSeek V4 Flash by default, no composer); the prompt is a byte-stable catalogue of the library so the provider's prefix cache covers it. Every course id the model returns is validated server-side, a bad JSON reply gets one retry then a plain-text fallback, and a per-user daily cap with token counts lives in advisor_requests. With AI_ENABLED false the app makes no outbound requests and the box does not appear; users can also hide it per browser. Claude-Session: https://claude.ai/code/session_012enquL2RZdjy3D5AcKP5yx
This commit is contained in:
+60
@@ -96,6 +96,66 @@ CREATE TABLE IF NOT EXISTS quizzes (
|
||||
INDEX idx_quizzes_folder (folder_id)
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
-- The vendor's course catalogue (an INE export), applied by seeds/ine_catalog.sql
|
||||
-- (built with tools/build-catalog-seed.php) — never written by a scan.
|
||||
-- `folder_key` is the folder name the downloader creates for a course (see
|
||||
-- folderKeyFor() in includes/functions.php), which is how a library folder is
|
||||
-- matched to its catalogue entry.
|
||||
CREATE TABLE IF NOT EXISTS catalog_courses (
|
||||
id VARCHAR(64) PRIMARY KEY, -- vendor uuid
|
||||
name VARCHAR(255) NOT NULL,
|
||||
slug VARCHAR(255) NOT NULL,
|
||||
folder_key VARCHAR(255) NOT NULL,
|
||||
vendor VARCHAR(100) NULL,
|
||||
difficulty VARCHAR(32) NULL,
|
||||
tags TEXT NULL, -- JSON array of strings
|
||||
short_description TEXT NULL,
|
||||
description TEXT NULL,
|
||||
learning_paths TEXT NULL, -- JSON array of names
|
||||
categories TEXT NULL, -- JSON array of names
|
||||
duration_seconds INT UNSIGNED NULL,
|
||||
url VARCHAR(500) NULL,
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
ON UPDATE CURRENT_TIMESTAMP,
|
||||
INDEX idx_cc_folder_key (folder_key)
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
-- What is known about one library course beyond its folder name: taken from
|
||||
-- the sidecar JSON the downloader leaves in a fully downloaded course, else
|
||||
-- from catalog_courses by folder name. Rewritten by every scan.
|
||||
CREATE TABLE IF NOT EXISTS course_meta (
|
||||
folder_id INT UNSIGNED PRIMARY KEY,
|
||||
source ENUM('sidecar', 'catalog') NOT NULL,
|
||||
catalog_id VARCHAR(64) NULL,
|
||||
title VARCHAR(255) NULL,
|
||||
vendor VARCHAR(100) NULL,
|
||||
difficulty VARCHAR(32) NULL,
|
||||
tags TEXT NULL,
|
||||
short_description TEXT NULL,
|
||||
description TEXT NULL,
|
||||
learning_paths TEXT NULL,
|
||||
categories TEXT NULL,
|
||||
duration_seconds INT UNSIGNED NULL,
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT fk_cm_folder FOREIGN KEY (folder_id) REFERENCES folders(id) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
-- One row per question put to the AI course advisor: the per-user daily cap
|
||||
-- and a record of what it cost. Created lazily on first use, like login_attempts.
|
||||
CREATE TABLE IF NOT EXISTS advisor_requests (
|
||||
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||
user_id INT UNSIGNED NOT NULL,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
ok TINYINT(1) NOT NULL DEFAULT 0,
|
||||
model VARCHAR(64) NULL,
|
||||
prompt_tokens INT UNSIGNED NULL,
|
||||
cache_hit_tokens INT UNSIGNED NULL,
|
||||
completion_tokens INT UNSIGNED NULL,
|
||||
INDEX idx_ar_user_time (user_id, created_at),
|
||||
CONSTRAINT fk_ar_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
-- Per-user quiz results. completed = every question answered correctly
|
||||
-- in a single attempt (sticky).
|
||||
CREATE TABLE IF NOT EXISTS quiz_progress (
|
||||
|
||||
Reference in New Issue
Block a user