Skip to content

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ộtKiểuKhoáMô tả
iduuidNOT NULLPK
account_iduuidNOT NULLFK → accounts
audiencetextNOT NULL
source_request_iduuidFK → point_requests
source_kindtextNOT NULL
pointsintegerNOT NULL
anchor_attimestamptzNOT NULL
anchor_basistextNOT NULL
expires_attimestamptzNOT NULL
policy_version_iduuidNOT NULLFK → rank_policy_versions
source_event_iduuidNOT NULL
correlation_idcorrelation_refNOT NULL
expired_attimestamptz
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
versionintegerNOT NULL
carried_from_lot_iduuidFK → rank_lots

Khoá chính: id

Trỏ ra (4):

  • account_id → accounts · ON DELETE RESTRICT
  • carried_from_lot_id → rank_lots · ON DELETE RESTRICT
  • policy_version_id → rank_policy_versions · ON DELETE RESTRICT
  • source_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ộtKiểuKhoáMô tả
iduuidNOT NULLPK
account_iduuidNOT NULLFK → accounts
audiencetextNOT NULL
source_request_iduuidFK → point_requests
pointsintegerNOT NULL
allocated_pointsintegerNOT NULL
unallocated_pointsinteger
anchor_attimestamptzNOT NULL
anchor_basistextNOT NULL
source_event_iduuidNOT NULL
correlation_idcorrelation_refNOT NULL
created_attimestamptzNOT NULL
ledger_modeltextNOT NULLU28-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_attimestamptzU28-P3-04. End of a SIGNED debit (exclusive). NULL while GAP-HT-V1-04 is open: in force, no expiry invented.
source_rank_adjustment_iduuidFK → rank_adjustmentsPPI-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 RESTRICT
  • source_rank_adjustment_id → rank_adjustments · ON DELETE RESTRICT
  • source_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ộtKiểuKhoáMô tả
iduuidNOT NULLPK
version_nointegerNOT NULL
expiry_monthsintegerNOT NULL
time_zonetextNOT NULL
effective_fromtimestamptzNOT NULL
source_reftextNOT NULL
decision_reftextNOT NULL
created_attimestamptzNOT 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ộtKiểuKhoáMô tả
iduuidNOT NULLPK
debit_iduuidNOT NULLFK → rank_debits
lot_iduuidNOT NULLFK → rank_lots
pointsintegerNOT NULL
created_attimestamptzNOT NULL

Khoá chính: id

Trỏ ra (2):

  • debit_id → rank_debits · ON DELETE RESTRICT
  • lot_id → rank_lots · ON DELETE RESTRICT

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

Sinh từ ad83b0aea · 820 migration · PostgreSQL 17