This commit is contained in:
2026-04-14 17:42:59 +07:00
parent efd7fac42f
commit 427557ef96
5 changed files with 191 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
CREATE TABLE user_test_attempt (
id SERIAL PRIMARY KEY,
user_id INT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
test_id INT NOT NULL REFERENCES test(id) ON DELETE CASCADE,
-- các part được chọn để luyện tập (có thể chọn 1 hoặc nhiều part)
selected_parts INT[], -- hoặc dùng junction table
-- thời gian
time_limit_minutes INT, -- user chọn từ dropdown (NULL = không giới hạn)
started_at TIMESTAMP,
submitted_at TIMESTAMP,
time_spent_seconds INT, -- thời gian thực tế đã dùng
-- kết quả
total_correct INT DEFAULT 0,
total_questions INT DEFAULT 0,
score DECIMAL(5,2), -- scaled score nếu full test
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE user_answer (
id SERIAL PRIMARY KEY,
attempt_id INT NOT NULL REFERENCES user_test_attempt(id) ON DELETE CASCADE,
question_id INT NOT NULL REFERENCES question(id),
selected_value CHAR(1), -- A / B / C / D (NULL nếu bỏ qua)
is_correct BOOLEAN,
UNIQUE (attempt_id, question_id)
);