CFA Prep Web — Database Schema

Tổng quan: 12 bảng

subjects ──< modules ──< glossary_terms
                    ├──< formulas
                    ├──< questions ──< question_options
                    │               ├──< explanations
                    │               └──< user_attempts
                    └──< concepts

links (đồ thị liên kết giữa mọi entity)
users
review_schedule (spaced repetition)

1. subjects

Bảng gốc — 10 môn CFA Level 1.

ColumnTypeConstraintMô tả
idTEXTPKquantitative-methods
nameTEXTNOT NULLQuantitative Methods
name_viTEXTCác phương pháp định lượng
order_numINTEGERNOT NULL, UNIQUE1 (thứ tự trong curriculum)
total_modulesINTEGERDEFAULT 011
statusTEXTDEFAULT ‘not_started’not_started, in_progress, completed
iconTEXT📊

Ví dụ dữ liệu:

idnameorder_numtotal_modules
quantitative-methodsQuantitative Methods111
economicsEconomics20
financial-statement-analysisFinancial Statement Analysis30

2. modules

11 modules mỗi subject. Chứa nội dung bài học chính.

ColumnTypeConstraintMô tả
idTEXTPKquant-m01
subject_idTEXTFK → subjects.idquantitative-methods
numberINTEGERNOT NULL1
titleTEXTNOT NULLRates and Returns
slugTEXTUNIQUEm01-rates-and-returns
content_mdTEXTNội dung markdown gốc
content_htmlTEXTHTML đã render (KaTeX, links)
losTEXTJSON: ["1.a","1.b","1.c","1.d","1.e"]
page_startINTEGER3 (trang bắt đầu trong PDF)
page_endINTEGER32

3. glossary_terms ⭐

Từ điển CFA — 254 thuật ngữ. Đây là bảng quan trọng nhất cho hover/click.

ColumnTypeConstraintMô tả
idTEXTPKquant-m01-inflation-premium
module_idTEXTFK → modules.idquant-m01
termTEXTNOT NULLInflation Premium
slugTEXTUNIQUEinflation-premium
definitionTEXTNOT NULLĐịnh nghĩa ngắn (1-3 câu)
definition_htmlTEXTHTML đã render
formula_latexTEXTNULLr_f = r_{real} + IP
formula_variablesTEXTNULLJSON: [{"sym":"r_f","desc":"Nominal risk-free rate"},...]
los_refTEXT1.a
noteTEXTNULLGhi chú thêm
related_term_idsTEXTNULLJSON: ["quant-m01-real-risk-free-rate","quant-m01-nominal-risk-free-rate"]

Ví dụ dữ liệu:

idtermdefinitionformula_latex
quant-m01-inflation-premiumInflation PremiumPhần bù lạm phát — bù đắp cho mất sức mua do lạm phátr_f = r_{real} + IP
quant-m01-hprHolding Period Return (HPR)Lợi suất trong một kỳ nắm giữHPR = \frac{P_1 - P_0 + I_1}{P_0}
quant-m08-type-i-errorType I ErrorBác bỏ giả thuyết null đúng (false positive)NULL

4. formulas

Công thức tách riêng — dễ filter, search, render.

ColumnTypeConstraintMô tả
idTEXTPKquant-m01-hpr
module_idTEXTFK → modules.idquant-m01
nameTEXTNOT NULLHolding Period Return
slugTEXTUNIQUEhpr
latexTEXTNOT NULLHPR = \frac{P_1 - P_0 + I_1}{P_0}
variablesTEXTJSON: [{"sym":"P_0","desc":"Beginning price"},{"sym":"P_1","desc":"Ending price"},{"sym":"I_1","desc":"Income"}]
descriptionTEXTLợi suất nắm giữ trong một kỳ
categoryTEXTreturn-measures
los_refTEXT1.b

5. questions

169 câu hỏi. Tách question text ra khỏi options và explanations.

ColumnTypeConstraintMô tả
idTEXTPKcfai-m01-q03
module_idTEXTFK → modules.idquant-m01
sourceTEXTNOT NULLcfai hoặc sapp
numberINTEGERNOT NULL3
topicTEXTNULLReturn Measures
question_mdTEXTNOT NULLNội dung câu hỏi (markdown)
question_htmlTEXTHTML đã render
exhibit_mdTEXTNULLBảng/exhibit đi kèm (nếu có)
exhibit_htmlTEXTNULL
correct_answerTEXTNOT NULLA, B, hoặc C
difficultyTEXTDEFAULT ‘medium’easy, medium, hard
los_refTEXTNULL1.b
tagsTEXTNULLJSON: ["geometric-mean","return-measures"]

6. question_options

3 đáp án cho mỗi câu hỏi.

ColumnTypeConstraintMô tả
idINTEGERPK, AUTO
question_idTEXTFK → questions.idcfai-m01-q03
labelTEXTNOT NULLA, B, C
text_mdTEXTNOT NULL14.9 percent
text_htmlTEXT
is_correctBOOLEANDEFAULT FALSETRUE cho đáp án đúng

7. explanations

Giải thích song ngữ — mỗi câu có 2 rows (en + vi).

ColumnTypeConstraintMô tả
idINTEGERPK, AUTO
question_idTEXTFK → questions.idcfai-m01-q03
langTEXTNOT NULLen hoặc vi
content_mdTEXTNOT NULLNội dung giải thích
content_htmlTEXTHTML đã render
why_correctTEXTNULLTại sao đáp án đúng (tách riêng)
why_a_wrongTEXTNULLTại sao A sai (nếu A không phải đáp án đúng)
why_b_wrongTEXTNULLTại sao B sai
why_c_wrongTEXTNULLTại sao C sai

8. concepts

11 concept pages — giải thích sâu hơn glossary.

ColumnTypeConstraintMô tả
idTEXTPKprobability
titleTEXTNOT NULLProbability
slugTEXTUNIQUEprobability
content_mdTEXTNội dung đầy đủ
content_htmlTEXT
related_module_idsTEXTJSON: ["quant-m04"]
tagsTEXTJSON: ["probability","bayes","counting"]

Bảng đồ thị — LƯU MỌI LIÊN KẾT giữa mọi entity. Đây là bảng quan trọng nhất cho hover preview và click navigation.

ColumnTypeConstraintMô tả
idINTEGERPK, AUTO
source_typeTEXTNOT NULLquestion, glossary, module, concept, formula, explanation
source_idTEXTNOT NULLcfai-m01-q04
target_typeTEXTNOT NULLglossary, module, concept, formula
target_idTEXTNOT NULLquant-m01-inflation-premium
anchor_textTEXTNULLinflation premium (text hiển thị)
contextTEXTNULLquestion_text, option_a, explanation_vi, definition

Indexes:

CREATE INDEX idx_links_source ON links(source_type, source_id);
CREATE INDEX idx_links_target ON links(target_type, target_id);
CREATE INDEX idx_links_target_id ON links(target_id);

Ví dụ dữ liệu:

source_typesource_idtarget_typetarget_idanchor_textcontext
questionsapp-m01-q04glossaryquant-m01-gross-returngross returnquestion_text
questionsapp-m01-q04glossaryquant-m01-net-returnnet returnquestion_text
glossaryquant-m01-inflation-premiumglossaryquant-m01-nominal-risk-free-ratenominal risk-free ratedefinition
glossaryquant-m01-inflation-premiummodulequant-m01M01definition
modulequant-m01formulaquant-m01-hprHPRcontent
conceptinterest-ratesmodulequant-m01M01content

Cách query:

-- Hover preview: lấy định nghĩa term
SELECT term, definition, formula_latex, los_ref
FROM glossary_terms WHERE id = 'quant-m01-inflation-premium';
 
-- Click: lấy tất cả backlinks (ai nhắc đến term này?)
SELECT source_type, source_id, anchor_text, context
FROM links WHERE target_id = 'quant-m01-inflation-premium';
-- → Trả về: Q1 (SAPP), Q1 (CFAI), Module M01, Concept interest-rates
 
-- Graph view: lấy tất cả connections của 1 entity
SELECT * FROM links 
WHERE source_id = 'quant-m01-inflation-premium' 
   OR target_id = 'quant-m01-inflation-premium';
 
-- Tìm related terms (cùng module, cùng LOS)
SELECT * FROM glossary_terms 
WHERE module_id = 'quant-m01' AND los_ref = '1.a';

10. users

ColumnTypeConstraintMô tả
idTEXTPKUUID hoặc default
nameTEXTSophie
emailTEXTUNIQUE, NULL
created_atDATETIMEDEFAULT NOW
settingsTEXTNULLJSON: {"lang":"vi","theme":"dark"}

11. user_attempts

Lưu lịch sử trả lời.

ColumnTypeConstraintMô tả
idINTEGERPK, AUTO
user_idTEXTFK → users.iddefault
question_idTEXTFK → questions.idcfai-m01-q03
selectedTEXTNOT NULLA, B, hoặc C
is_correctBOOLEANNOT NULLTRUE
time_spentINTEGERNULLGiây (seconds)
attempted_atDATETIMEDEFAULT NOW

12. review_schedule

Spaced Repetition (SM-2 algorithm).

ColumnTypeConstraintMô tả
idINTEGERPK, AUTO
user_idTEXTFK → users.id
question_idTEXTFK → questions.id
next_reviewDATETIMENOT NULLThời điểm ôn lại
interval_daysREALDEFAULT 1.0Khoảng cách giữa các lần ôn (ngày)
ease_factorREALDEFAULT 2.5Hệ số dễ/khó (SM-2)
repetitionsINTEGERDEFAULT 0Số lần đã ôn đúng liên tiếp
last_qualityINTEGERNULL0-5 (chất lượng trả lời lần cuối)

Tổng kết

BảngSố rows ước tínhVai trò
subjects1010 môn CFA L1
modules11+Nội dung bài học
glossary_terms254Từ điển — hover preview
formulas66+Công thức — render KaTeX
questions169Câu hỏi practice
question_options507 (169×3)3 đáp án mỗi câu
explanations338 (169×2)Giải thích EN + VI
concepts11Khái niệm tổng hợp
links~1500+Đồ thị liên kết — core của hover/click
users1+Người dùng
user_attempts0→∞Lịch sử trả lời
review_schedule0→169Lịch ôn spaced repetition