Skip to content

Database Schema Extensions

The GamiBot plugin extends the Moodle database with custom tables to track quizzes, chat history, and ingestion logs.


Overview

TablePurpose
local_gamibot_quizzesStore quiz metadata and student performance
local_gamibot_chatStore chat history for continuity
local_gamibot_ingestion_logTrack material ingestion status

Quiz Metadata Table

Stores generated quizzes and student performance:

sql
CREATE TABLE IF NOT EXISTS {local_gamibot_quizzes} (
    id BIGINT PRIMARY KEY AUTO_INCREMENT,
    course_id BIGINT NOT NULL,
    student_id BIGINT NOT NULL,
    quiz_id VARCHAR(36) NOT NULL UNIQUE,
    topic VARCHAR(255),
    num_questions INT,
    score FLOAT,
    created_at TIMESTAMP,
    answered_at TIMESTAMP,
    FOREIGN KEY (course_id) REFERENCES {course}(id),
    FOREIGN KEY (student_id) REFERENCES {user}(id)
);

Fields

FieldTypeDescription
idBIGINTPrimary key
course_idBIGINTReference to Moodle course
student_idBIGINTReference to Moodle user
quiz_idVARCHAR(36)Unique quiz identifier (UUID)
topicVARCHAR(255)Quiz topic
num_questionsINTNumber of questions
scoreFLOATFinal score (0.0 - 1.0)
created_atTIMESTAMPQuiz creation time
answered_atTIMESTAMPQuiz completion time

Chat History Table

Stores conversation history for context continuity:

sql
CREATE TABLE IF NOT EXISTS {local_gamibot_chat} (
    id BIGINT PRIMARY KEY AUTO_INCREMENT,
    course_id BIGINT NOT NULL,
    user_id BIGINT NOT NULL,
    session_id VARCHAR(36),
    message_type ENUM('student_query', 'agent_response', 'system_notification'),
    content LONGTEXT,
    created_at TIMESTAMP,
    FOREIGN KEY (course_id) REFERENCES {course}(id),
    FOREIGN KEY (user_id) REFERENCES {user}(id)
);

Fields

FieldTypeDescription
idBIGINTPrimary key
course_idBIGINTReference to Moodle course
user_idBIGINTReference to Moodle user
session_idVARCHAR(36)Conversation session ID
message_typeENUMType of message
contentLONGTEXTMessage content
created_atTIMESTAMPMessage timestamp

Message Types

TypeDescription
student_queryQuestion from student
agent_responseResponse from AI agent
system_notificationSystem messages (errors, confirmations)

Ingestion Log Table

Tracks the status of material ingestion:

sql
CREATE TABLE IF NOT EXISTS {local_gamibot_ingestion_log} (
    id BIGINT PRIMARY KEY AUTO_INCREMENT,
    course_id BIGINT NOT NULL,
    file_url VARCHAR(500),
    filename VARCHAR(255),
    file_type VARCHAR(10),
    status ENUM('success', 'failed', 'pending'),
    chunks_created INT,
    error_message TEXT,
    created_at TIMESTAMP,
    FOREIGN KEY (course_id) REFERENCES {course}(id)
);

Fields

FieldTypeDescription
idBIGINTPrimary key
course_idBIGINTReference to Moodle course
file_urlVARCHAR(500)Original file URL
filenameVARCHAR(255)Original filename
file_typeVARCHAR(10)File extension
statusENUMIngestion status
chunks_createdINTNumber of chunks created
error_messageTEXTError details (if failed)
created_atTIMESTAMPIngestion timestamp

Status Values

StatusDescription
pendingQueued for processing
successSuccessfully ingested
failedIngestion failed

Indexes

For optimal query performance:

sql
-- Quiz queries by student
CREATE INDEX idx_quizzes_student ON {local_gamibot_quizzes} (student_id, course_id);

-- Chat queries by session
CREATE INDEX idx_chat_session ON {local_gamibot_chat} (session_id, created_at);

-- Ingestion status queries
CREATE INDEX idx_ingestion_status ON {local_gamibot_ingestion_log} (course_id, status);

Moodle XMLDB

For Moodle compatibility, define tables in db/install.xml:

xml
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="local/gamibot_manager/db" VERSION="20251216">
  <TABLES>
    <TABLE NAME="local_gamibot_quizzes">
      <FIELDS>
        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
        <FIELD NAME="course_id" TYPE="int" LENGTH="10" NOTNULL="true"/>
        <FIELD NAME="student_id" TYPE="int" LENGTH="10" NOTNULL="true"/>
        <FIELD NAME="quiz_id" TYPE="char" LENGTH="36" NOTNULL="true"/>
        <FIELD NAME="topic" TYPE="char" LENGTH="255"/>
        <FIELD NAME="num_questions" TYPE="int" LENGTH="5"/>
        <FIELD NAME="score" TYPE="number" LENGTH="5" DECIMALS="2"/>
        <FIELD NAME="created_at" TYPE="int" LENGTH="10"/>
        <FIELD NAME="answered_at" TYPE="int" LENGTH="10"/>
      </FIELDS>
      <KEYS>
        <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
        <KEY NAME="course_fk" TYPE="foreign" FIELDS="course_id" REFTABLE="course" REFFIELDS="id"/>
        <KEY NAME="student_fk" TYPE="foreign" FIELDS="student_id" REFTABLE="user" REFFIELDS="id"/>
      </KEYS>
      <INDEXES>
        <INDEX NAME="quiz_id_unique" UNIQUE="true" FIELDS="quiz_id"/>
      </INDEXES>
    </TABLE>
  </TABLES>
</XMLDB>

Next Steps

Released under the MIT License.