Skip to content

Data Dictionary · Danh tính & gia đình ​

⚙️ Trang này sinh tự động từ source code bằng scripts/gen-reference.mjs — đừng sửa tay, sửa code rồi chạy npm run gen:reference.

Thuộc Data Dictionary. 10 bảng, audit_log tới users.

audit_log ​

migration: 0001_identity.sql

CộtKiểuRàng buộc / ghi chú
idTEXTPRIMARY KEY
actor_user_idTEXT—
actionTEXTNOT NULL
target_typeTEXTNOT NULL
target_idTEXTNOT NULL
detail_jsonTEXT—
occurred_atTEXTNOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now'))
actor_roleTEXT— thêm ở 0033_audit_privacy.sql
ipTEXT— thêm ở 0033_audit_privacy.sql
user_agentTEXT— thêm ở 0033_audit_privacy.sql
request_idTEXT— thêm ở 0033_audit_privacy.sql

Index: idx_audit_target(target_type, target_id) · idx_audit_actor(actor_user_id, occurred_at DESC)

auth_identities ​

migration: 0001_identity.sql

CộtKiểuRàng buộc / ghi chú
providerTEXTNOT NULL
subjectTEXTNOT NULL
user_idTEXTNOT NULL REFERENCES users(id)
emailTEXTNOT NULL
created_atTEXTNOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now'))
—table constraintPRIMARY KEY (provider, subject)

Khóa ngoại: user_id → users

families ​

migration: 0001_identity.sql

CộtKiểuRàng buộc / ghi chú
idTEXTPRIMARY KEY
nameTEXT—
created_byTEXTNOT NULL REFERENCES users(id)
created_atTEXTNOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now'))
sourceTEXTNOT NULL DEFAULT 'self' — thêm ở 0078_family_workspace.sql
statusTEXTNOT NULL DEFAULT 'active' — thêm ở 0078_family_workspace.sql
updated_atTEXT— thêm ở 0078_family_workspace.sql

Khóa ngoại: created_by → users

Index: idx_families_status(status, source)

family_members ​

migration: 0001_identity.sql

CộtKiểuRàng buộc / ghi chú
family_idTEXTNOT NULL REFERENCES families(id)
user_idTEXTNOT NULL REFERENCES users(id)
roleTEXTNOT NULL CHECK (role IN ('owner','guardian','supporter','learner'))
created_atTEXTNOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now'))
—table constraintPRIMARY KEY (family_id, user_id)

Khóa ngoại: family_id → families · user_id → users

guardians ​

migration: 0001_identity.sql

CộtKiểuRàng buộc / ghi chú
learner_idTEXTNOT NULL REFERENCES learners(id)
user_idTEXTNOT NULL REFERENCES users(id)
relationshipTEXTNOT NULL DEFAULT 'parent' CHECK (relationship IN ('parent','grandparent','guardian','other'))
created_atTEXTNOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now'))
—table constraintPRIMARY KEY (learner_id, user_id)

Khóa ngoại: learner_id → learners · user_id → users

invitations ​

migration: 0001_identity.sql

CộtKiểuRàng buộc / ghi chú
idTEXTPRIMARY KEY
family_idTEXTNOT NULL REFERENCES families(id)
learner_idTEXTREFERENCES learners(id)
invited_byTEXTNOT NULL REFERENCES users(id)
emailTEXT—
codeTEXTNOT NULL UNIQUE
roleTEXTNOT NULL DEFAULT 'learner' CHECK (role IN ('learner','guardian','supporter'))
statusTEXTNOT NULL DEFAULT 'pending' CHECK (status IN ('pending','accepted','expired','revoked'))
expires_atTEXTNOT NULL
accepted_byTEXTREFERENCES users(id)
accepted_atTEXT—
created_atTEXTNOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now'))

Khóa ngoại: family_id → families · learner_id → learners · invited_by → users · accepted_by → users

Index: idx_invitations_family(family_id)

learners ​

migration: 0001_identity.sql

CộtKiểuRàng buộc / ghi chú
idTEXTPRIMARY KEY
user_idTEXTUNIQUE REFERENCES users(id)
family_idTEXTNOT NULL REFERENCES families(id)
display_nameTEXTNOT NULL
birth_yearINTEGER—
gradeINTEGER—
statusTEXTNOT NULL DEFAULT 'invited' CHECK (status IN ('invited','active','paused','archived'))
created_atTEXTNOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now'))
updated_atTEXTNOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now'))
birth_dateTEXT— thêm ở 0003_onboarding_models.sql
current_schoolTEXT— thêm ở 0003_onboarding_models.sql
provinceTEXT— thêm ở 0003_onboarding_models.sql
profile_completed_atTEXT— thêm ở 0003_onboarding_models.sql
learning_priorityTEXT— thêm ở 0045_parent_declared_profile.sql
profile_sourceTEXT— thêm ở 0045_parent_declared_profile.sql
daily_intensityTEXTNOT NULL DEFAULT 'light'
CHECK (daily_intensity IN ('light','medium','high')) — thêm ở 0061_daily_intensity.sql
photo_media_idTEXT— thêm ở 0083_family_member_photos_nickname.sql
nicknameTEXT— thêm ở 0083_family_member_photos_nickname.sql
facebook_urlTEXT— thêm ở 0161_person_profile_fields.sql
links_jsonTEXT— thêm ở 0161_person_profile_fields.sql
interestsTEXT— thêm ở 0161_person_profile_fields.sql
expertiseTEXT— thêm ở 0161_person_profile_fields.sql
province_codeTEXTREFERENCES provinces(code) — thêm ở 0279_learner_geography_country_and_province_codes.sql

Khóa ngoại: user_id → users · family_id → families

Index: idx_learners_family(family_id) · idx_learners_province_code(province_code)

role_assignments ​

migration: 0001_identity.sql

CộtKiểuRàng buộc / ghi chú
user_idTEXTNOT NULL REFERENCES users(id)
roleTEXTNOT NULL CHECK (role IN ('learner','guardian','mentor','staff','admin'))
scope_typeTEXTNOT NULL DEFAULT 'global' CHECK (scope_type IN ('global','school','family','learner'))
scope_idTEXTNOT NULL DEFAULT '*'
granted_byTEXTREFERENCES users(id)
created_atTEXTNOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now'))
—table constraintPRIMARY KEY (user_id, role, scope_type, scope_id)

Khóa ngoại: user_id → users · granted_by → users

sessions ​

migration: 0001_identity.sql

CộtKiểuRàng buộc / ghi chú
idTEXTPRIMARY KEY
user_idTEXTNOT NULL REFERENCES users(id)
token_hashTEXTNOT NULL UNIQUE
expires_atTEXTNOT NULL
rotated_fromTEXT—
revoked_atTEXT—
last_seen_atTEXT—
clientTEXTNOT NULL DEFAULT 'web' CHECK (client IN ('web','mobile'))
created_atTEXTNOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now'))

Khóa ngoại: user_id → users

Index: idx_sessions_user(user_id)

users ​

Migration 0001 — Identity, Family, RBAC core (SDD-001 §6–7). Quy tắc QG-004: một sequence duy nhất, idempotent, email KHÔNG là khóa dữ liệu (RISK-001).

migration: 0001_identity.sql

CộtKiểuRàng buộc / ghi chú
idTEXTPRIMARY KEY
emailTEXTNOT NULL UNIQUE
display_nameTEXT—
avatar_media_idTEXT—
statusTEXTNOT NULL DEFAULT 'active' CHECK (status IN ('active','suspended','deleted'))
created_atTEXTNOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now'))
updated_atTEXTNOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now'))
avatar_urlTEXT— thêm ở 0022_user_avatar.sql
birth_yearINTEGERCHECK (birth_year IS NULL OR (birth_year >= 1940 AND birth_year <= 2020)) — thêm ở 0221_parent_profile.sql
provinceTEXTCHECK (province IS NULL OR length(province) <= 100) — thêm ở 0221_parent_profile.sql
profile_completed_atTEXT— thêm ở 0221_parent_profile.sql
country_codeTEXTCHECK (country_code IS NULL OR (length(country_code) = 2 AND country_code = upper(country_code))) — thêm ở 0279_learner_geography_country_and_province_codes.sql
country_sourceTEXTCHECK (country_source IS NULL OR country_source IN ('geo', 'declared')) — thêm ở 0279_learner_geography_country_and_province_codes.sql
country_seen_atTEXT— thêm ở 0279_learner_geography_country_and_province_codes.sql
province_codeTEXTREFERENCES provinces(code) — thêm ở 0279_learner_geography_country_and_province_codes.sql