Giao diện
loyalty / rank
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 đè.
4 bảng. Quay lại loyalty.
rank_lots
P4-07. NO_HARD_DELETE_FINANCIAL. One rank lot per Available/posted PiPoint command: points, anchor_at (available_at/posted_at) and expires_at fixed at creation from the policy version in force. Not a ledger; no spent column: spending never reduces rank. Only the set-once expired_at marker can change.
public.rank_lots · 17 cột · 9 check · 2 unique · 4 index · 2 policy · 4 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
account_id | uuid | NOT NULL | FK → accounts | |
audience | text | NOT NULL | ||
source_request_id | uuid | FK → point_requests | ||
source_kind | text | NOT NULL | ||
points | integer | NOT NULL | ||
anchor_at | timestamptz | NOT NULL | ||
anchor_basis | text | NOT NULL | ||
expires_at | timestamptz | NOT NULL | ||
policy_version_id | uuid | NOT NULL | FK → rank_policy_versions | |
source_event_id | uuid | NOT NULL | ||
correlation_id | correlation_ref | NOT NULL | ||
expired_at | timestamptz | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
version | integer | NOT NULL | ||
carried_from_lot_id | uuid | FK → rank_lots |
Khoá chính: id
Trỏ ra (4):
account_id→accounts·ON DELETE RESTRICTcarried_from_lot_id→rank_lots·ON DELETE RESTRICTpolicy_version_id→rank_policy_versions·ON DELETE RESTRICTsource_request_id→point_requests·ON DELETE RESTRICT
Được trỏ tới (2): rank_lot_deductions, rank_lots
rank_debits
L9 / A-TIER-03 AC05. NO_HARD_DELETE_FINANCIAL. One row per ACCEPTED ADJUST DEBIT request: points asked, allocated to rank lots (soonest-expiring first) and unallocated. Not a balance: PiPoint owns every balance.
public.rank_debits · 15 cột · 8 check · 2 unique · 4 index · 2 policy · 2 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
account_id | uuid | NOT NULL | FK → accounts | |
audience | text | NOT NULL | ||
source_request_id | uuid | FK → point_requests | ||
points | integer | NOT NULL | ||
allocated_points | integer | NOT NULL | ||
unallocated_points | integer | |||
anchor_at | timestamptz | NOT NULL | ||
anchor_basis | text | NOT NULL | ||
source_event_id | uuid | NOT NULL | ||
correlation_id | correlation_ref | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
ledger_model | text | NOT NULL | U28-P3-04. LOT_FEFO = legacy (and Sale) debit allocated to lots soonest-expiring first, unallocated rest ignored; SIGNED = customer debit counted as one negative entry of the signed rank ledger, never allocated to lots. | |
expires_at | timestamptz | U28-P3-04. End of a SIGNED debit (exclusive). NULL while GAP-HT-V1-04 is open: in force, no expiry invented. | ||
source_rank_adjustment_id | uuid | FK → rank_adjustments | PPI-P5-07 (W-03 b). The approved rank-only adjustment this SIGNED debit comes from (no point request); exactly one of source_request_id / source_rank_adjustment_id is set. anchor_at = the approval instant (anchor_basis APPROVED). |
Khoá chính: id
Trỏ ra (3):
account_id→accounts·ON DELETE RESTRICTsource_rank_adjustment_id→rank_adjustments·ON DELETE RESTRICTsource_request_id→point_requests·ON DELETE RESTRICT
Được trỏ tới (1): rank_lot_deductions
rank_policy_versions
P4-07 / U28-P3-05. Immutable rank-lot expiry policy (N calendar months, VN time). v1 by migration; later versions only through tier.save_rank_policy (tier.write, effective now(), DEC-U28-08). Lots store the version in force at their anchor; a later version never rewrites them.
public.rank_policy_versions · 8 cột · 4 check · 2 unique · 3 index · 2 policy · 2 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
version_no | integer | NOT NULL | ||
expiry_months | integer | NOT NULL | ||
time_zone | text | NOT NULL | ||
effective_from | timestamptz | NOT NULL | ||
source_ref | text | NOT NULL | ||
decision_ref | text | NOT NULL | ||
created_at | timestamptz | NOT NULL |
Khoá chính: id
Trỏ ra: không có
Được trỏ tới (1): rank_lots
rank_lot_deductions
L9. Append-only allocation of a rank debit to lots; rank_lots stay immutable.
public.rank_lot_deductions · 5 cột · 1 check · 1 unique · 3 index · 2 policy · 3 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
debit_id | uuid | NOT NULL | FK → rank_debits | |
lot_id | uuid | NOT NULL | FK → rank_lots | |
points | integer | NOT NULL | ||
created_at | timestamptz | NOT NULL |
Khoá chính: id
Trỏ ra (2):
debit_id→rank_debits·ON DELETE RESTRICTlot_id→rank_lots·ON DELETE RESTRICT
Được trỏ tới: không có