Giao diện
identity / sale
Trang sinh tự động
Sinh từ ad83b0aea — chạy 820 migration lên PostgreSQL 17 rồi đọc pg_catalog. Mô tả bảng và cột lấy từ COMMENT ON. Không sửa tay: lần chạy docgen sau sẽ ghi đè.
10 bảng. Quay lại identity.
sale_applications
P1-12. One Sale application per account (SA-01, UA-26): PENDING -> APPROVED | REJECTED, REJECTED -> PENDING (resubmission, attempt_no + 1). Approval never grants membership/roles (P1-13/P1-06 activate them).
public.sale_applications · 13 cột · 9 check · 1 unique · 3 index · 5 policy · 8 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
account_id | uuid | NOT NULL | FK → accounts | |
source | text | NOT NULL | SELF_REGISTERED (Sale App), USER_REQUEST (User to Sale), ADMIN_CREATED (created in Admin, SL-US-03; U6-P2-22). | |
state | text | NOT NULL | ||
attempt_no | integer | NOT NULL | ||
submitted_at | timestamptz | NOT NULL | ||
reviewed_by | uuid | FK → accounts | ||
reviewed_at | timestamptz | |||
rejection_reason | text | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
version | integer | NOT NULL | ||
created_by | uuid | FK → accounts | U6-P7-53. The Admin who created the Sale in Admin (ADMIN_CREATED tickets); never the reviewer (K-10). Null otherwise. |
Khoá chính: id
Trỏ ra (3):
account_id→accounts·ON DELETE RESTRICTcreated_by→accounts·ON DELETE RESTRICTreviewed_by→accounts·ON DELETE RESTRICT
Được trỏ tới (3): sale_application_events, sale_application_qualifications, sale_role_transfers
sale_teams
P1-13. Flat Sale teams (A-TEAM-01): one optional WEB_ADMIN manager, ACTIVE|INACTIVE, never deleted. Membership over time is public.sale_team_history.
public.sale_teams · 12 cột · 5 check · 0 unique · 3 index · 1 policy · 4 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
code | text | NOT NULL | ||
name | text | NOT NULL | ||
description | text | |||
manager_account_id | uuid | FK → app_memberships | ||
manager_app | app_code | NOT NULL | FK → app_memberships | |
status | text | NOT NULL | ||
status_reason | text | |||
created_by | uuid | NOT NULL | FK → accounts | |
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
version | integer | NOT NULL |
Khoá chính: id
Trỏ ra (2):
created_by→accounts·ON DELETE RESTRICTmanager_account_id, manager_app→app_memberships·ON DELETE RESTRICT
Được trỏ tới (3): attribution_assignments, referral_milestones, sale_team_history
sale_rejection_reasons
U6-P7-29. Configured Sale ticket rejection reasons (PRD:718), seeded by migration 20261211030800 (Q-2). Retire with is_active = false; never deleted.
public.sale_rejection_reasons · 9 cột · 3 check · 1 unique · 3 index · 0 policy · 4 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
code | text | NOT NULL | ||
label | text | NOT NULL | ||
sort_order | integer | NOT NULL | ||
is_active | boolean | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
version | integer | NOT NULL | ||
requires_note | boolean | NOT NULL | U6-P7-29 (Q-2). true: choosing this reason needs a non-empty free-text note ("Khac"). |
Khoá chính: id
Trỏ ra: không có
Được trỏ tới (1): sale_ticket_rejections
sale_account_profiles
FU-718 (SPEC-06). Sale profile fields beyond the shared profiles row. id_number / bank_account are PII: read only through sale_profile.* definer functions, masked; written only by an approved PROFILE_CHANGE.
public.sale_account_profiles · 13 cột · 8 check · 0 unique · 4 index · 0 policy · 4 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
account_id | uuid | NOT NULL | PK FK → accounts | |
avatar_media_id | uuid | FK → media | ||
contact_email | text | |||
contact_address | text | |||
id_number | text | |||
bank_account | text | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
version | integer | NOT NULL | ||
username | text | U6-P2-22. Ten tai khoan (PRD:657): unique case-insensitive, <= 100 (INT-SL-10). | ||
date_of_birth | date | U6-P2-22. Ngay sinh (PRD:660): calendar date, not after today (Asia/Ho_Chi_Minh). | ||
referral_code | text | U6-P2-22. Ma gioi thieu (PRD:664): unique case-insensitive, also against referral_links.code; <= 64 (NEW-SL-07). | ||
note | text | U6-P2-22. Ghi chu (PRD:669): 1..500 characters, blank stored as null. |
Khoá chính: account_id
Trỏ ra (2):
account_id→accounts·ON DELETE RESTRICTavatar_media_id→media·ON DELETE RESTRICT
Được trỏ tới: không có
sale_application_events
P1-12. Append-only history of sale_applications (one row per version), written by trigger only.
public.sale_application_events · 10 cột · 2 check · 1 unique · 2 index · 2 policy · 2 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
application_id | uuid | NOT NULL | FK → sale_applications | |
application_version | integer | NOT NULL | ||
event_type | text | NOT NULL | ||
from_state | text | |||
to_state | text | NOT NULL | ||
attempt_no | integer | NOT NULL | ||
actor_account_id | uuid | NOT NULL | FK → accounts | |
reason | text | |||
recorded_at | timestamptz | NOT NULL |
Khoá chính: id
Trỏ ra (2):
actor_account_id→accounts·ON DELETE RESTRICTapplication_id→sale_applications·ON DELETE RESTRICT
Được trỏ tới: không có
sale_application_qualifications
P4-10. APPEND_ONLY_RETAIN snapshots of a User-to-Sale applicant's Mission qualification at submission and at the reviewer's decision (rank is evidence only, GAP-238). An APPROVE snapshot is always QUALIFIED. Written by sale_qualification.record() only.
public.sale_application_qualifications · 13 cột · 8 check · 1 unique · 3 index · 0 policy · 2 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
application_id | uuid | NOT NULL | FK → sale_applications | |
application_version | integer | NOT NULL | ||
account_id | uuid | NOT NULL | FK → accounts | |
kind | text | NOT NULL | ||
decision | text | |||
status | text | NOT NULL | ||
fingerprint | text | NOT NULL | ||
active_rank | bigint | NOT NULL | ||
evidence | jsonb | NOT NULL | ||
evaluated_at | timestamptz | NOT NULL | ||
actor_account_id | uuid | NOT NULL | FK → accounts | |
created_at | timestamptz | NOT NULL |
Khoá chính: id
Trỏ ra (3):
account_id→accounts·ON DELETE RESTRICTactor_account_id→accounts·ON DELETE RESTRICTapplication_id→sale_applications·ON DELETE RESTRICT
Được trỏ tới: không có
sale_codes
U6-P2-22. One system-generated, immutable employee code per Sale account (Ma nhan vien, PRD:631,655; format SL-NNNNN is a technical placeholder, INT-SL-08). Issued by backfill and by triggers on app_memberships (APP_SALE) / sale_applications insert; read only through sale_admin definer functions.
public.sale_codes · 3 cột · 1 check · 1 unique · 2 index · 0 policy · 3 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
account_id | uuid | NOT NULL | PK FK → accounts | |
code | text | NOT NULL | ||
issued_at | timestamptz | NOT NULL |
Khoá chính: account_id
Trỏ ra (1):
account_id→accounts·ON DELETE RESTRICT
Được trỏ tới: không có
sale_profile_changes
FU-718 (SPEC-06). One PROFILE_CHANGE request per submission: PENDING -> APPROVED | REJECTED (terminal, the reason of a rejection is kept). A new submission is a new row; at most one PENDING per Sale. Written only by sale_profile.submit_change() and sale_profile.decide_change().
public.sale_profile_changes · 17 cột · 12 check · 1 unique · 4 index · 0 policy · 6 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
account_id | uuid | NOT NULL | FK → accounts | |
seq | integer | NOT NULL | ||
state | text | NOT NULL | ||
new_full_name | text | |||
new_id_number | text | |||
new_bank_account | text | |||
old_full_name | text | |||
old_id_number | text | |||
old_bank_account | text | |||
submitted_at | timestamptz | NOT NULL | ||
reviewed_by | uuid | FK → accounts | ||
reviewed_at | timestamptz | |||
rejection_reason | text | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
version | integer | NOT NULL |
Khoá chính: id
Trỏ ra (2):
account_id→accounts·ON DELETE RESTRICTreviewed_by→accounts·ON DELETE RESTRICT
Được trỏ tới: không có
sale_team_history
P1-01 (owner to be confirmed by integrator). APPEND_ONLY team-change rows for HISTORICAL_TEAM scope.
public.sale_team_history · 9 cột · 2 check · 1 unique · 3 index · 1 policy · 2 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
sale_account_id | uuid | NOT NULL | FK → app_memberships | |
app | app_code | NOT NULL | FK → app_memberships | |
team_id | uuid | FK → sale_teams | ||
effective_from | timestamptz | NOT NULL | ||
reason | text | NOT NULL | ||
recorded_by | uuid | NOT NULL | FK → accounts | |
recorded_at | timestamptz | NOT NULL | ||
correlation_id | correlation_ref | NOT NULL |
Khoá chính: id
Trỏ ra (3):
sale_account_id, app→app_memberships·ON DELETE RESTRICTrecorded_by→accounts·ON DELETE RESTRICTteam_id→sale_teams·ON DELETE RESTRICT
Được trỏ tới: không có
sale_ticket_rejections
U6-P7-02. Append-only ledger of Sale ticket rejections (configured reason + label at the time, optional note, reviewer).
public.sale_ticket_rejections · 11 cột · 5 check · 1 unique · 3 index · 0 policy · 2 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
ticket_kind | text | NOT NULL | ||
ticket_id | uuid | NOT NULL | ||
ticket_version | integer | NOT NULL | ||
account_id | uuid | NOT NULL | FK → accounts | |
reason_id | uuid | NOT NULL | FK → sale_rejection_reasons | |
reason_label | text | NOT NULL | ||
decided_by | uuid | NOT NULL | FK → accounts | |
decided_at | timestamptz | NOT NULL | ||
correlation_id | correlation_ref | |||
note | text | U6-P7-29 (Q-2). Note typed with a reason that requires one; otherwise null. |
Khoá chính: id
Trỏ ra (3):
account_id→accounts·ON DELETE RESTRICTdecided_by→accounts·ON DELETE RESTRICTreason_id→sale_rejection_reasons·ON DELETE RESTRICT
Được trỏ tới: không có