Skip to content

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ộtKiểuKhoáMô tả
iduuidNOT NULLPK
account_iduuidNOT NULLFK → accounts
sourcetextNOT NULLSELF_REGISTERED (Sale App), USER_REQUEST (User to Sale), ADMIN_CREATED (created in Admin, SL-US-03; U6-P2-22).
statetextNOT NULL
attempt_nointegerNOT NULL
submitted_attimestamptzNOT NULL
reviewed_byuuidFK → accounts
reviewed_attimestamptz
rejection_reasontext
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
versionintegerNOT NULL
created_byuuidFK → accountsU6-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 RESTRICT
  • created_by → accounts · ON DELETE RESTRICT
  • reviewed_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ộtKiểuKhoáMô tả
iduuidNOT NULLPK
codetextNOT NULL
nametextNOT NULL
descriptiontext
manager_account_iduuidFK → app_memberships
manager_appapp_codeNOT NULLFK → app_memberships
statustextNOT NULL
status_reasontext
created_byuuidNOT NULLFK → accounts
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
versionintegerNOT NULL

Khoá chính: id

Trỏ ra (2):

  • created_by → accounts · ON DELETE RESTRICT
  • manager_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ộtKiểuKhoáMô tả
iduuidNOT NULLPK
codetextNOT NULL
labeltextNOT NULL
sort_orderintegerNOT NULL
is_activebooleanNOT NULL
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
versionintegerNOT NULL
requires_notebooleanNOT NULLU6-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ộtKiểuKhoáMô tả
account_iduuidNOT NULLPK FK → accounts
avatar_media_iduuidFK → media
contact_emailtext
contact_addresstext
id_numbertext
bank_accounttext
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
versionintegerNOT NULL
usernametextU6-P2-22. Ten tai khoan (PRD:657): unique case-insensitive, <= 100 (INT-SL-10).
date_of_birthdateU6-P2-22. Ngay sinh (PRD:660): calendar date, not after today (Asia/Ho_Chi_Minh).
referral_codetextU6-P2-22. Ma gioi thieu (PRD:664): unique case-insensitive, also against referral_links.code; <= 64 (NEW-SL-07).
notetextU6-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 RESTRICT
  • avatar_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ộtKiểuKhoáMô tả
iduuidNOT NULLPK
application_iduuidNOT NULLFK → sale_applications
application_versionintegerNOT NULL
event_typetextNOT NULL
from_statetext
to_statetextNOT NULL
attempt_nointegerNOT NULL
actor_account_iduuidNOT NULLFK → accounts
reasontext
recorded_attimestamptzNOT NULL

Khoá chính: id

Trỏ ra (2):

  • actor_account_id → accounts · ON DELETE RESTRICT
  • application_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ộtKiểuKhoáMô tả
iduuidNOT NULLPK
application_iduuidNOT NULLFK → sale_applications
application_versionintegerNOT NULL
account_iduuidNOT NULLFK → accounts
kindtextNOT NULL
decisiontext
statustextNOT NULL
fingerprinttextNOT NULL
active_rankbigintNOT NULL
evidencejsonbNOT NULL
evaluated_attimestamptzNOT NULL
actor_account_iduuidNOT NULLFK → accounts
created_attimestamptzNOT NULL

Khoá chính: id

Trỏ ra (3):

  • account_id → accounts · ON DELETE RESTRICT
  • actor_account_id → accounts · ON DELETE RESTRICT
  • application_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ộtKiểuKhoáMô tả
account_iduuidNOT NULLPK FK → accounts
codetextNOT NULL
issued_attimestamptzNOT 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ộtKiểuKhoáMô tả
iduuidNOT NULLPK
account_iduuidNOT NULLFK → accounts
seqintegerNOT NULL
statetextNOT NULL
new_full_nametext
new_id_numbertext
new_bank_accounttext
old_full_nametext
old_id_numbertext
old_bank_accounttext
submitted_attimestamptzNOT NULL
reviewed_byuuidFK → accounts
reviewed_attimestamptz
rejection_reasontext
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
versionintegerNOT NULL

Khoá chính: id

Trỏ ra (2):

  • account_id → accounts · ON DELETE RESTRICT
  • reviewed_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ộtKiểuKhoáMô tả
iduuidNOT NULLPK
sale_account_iduuidNOT NULLFK → app_memberships
appapp_codeNOT NULLFK → app_memberships
team_iduuidFK → sale_teams
effective_fromtimestamptzNOT NULL
reasontextNOT NULL
recorded_byuuidNOT NULLFK → accounts
recorded_attimestamptzNOT NULL
correlation_idcorrelation_refNOT NULL

Khoá chính: id

Trỏ ra (3):

  • sale_account_id, app → app_memberships · ON DELETE RESTRICT
  • recorded_by → accounts · ON DELETE RESTRICT
  • team_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ộtKiểuKhoáMô tả
iduuidNOT NULLPK
ticket_kindtextNOT NULL
ticket_iduuidNOT NULL
ticket_versionintegerNOT NULL
account_iduuidNOT NULLFK → accounts
reason_iduuidNOT NULLFK → sale_rejection_reasons
reason_labeltextNOT NULL
decided_byuuidNOT NULLFK → accounts
decided_attimestamptzNOT NULL
correlation_idcorrelation_ref
notetextU6-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 RESTRICT
  • decided_by → accounts · ON DELETE RESTRICT
  • reason_id → sale_rejection_reasons · ON DELETE RESTRICT

Được trỏ tới: không có

Sinh từ ad83b0aea · 820 migration · PostgreSQL 17