Giao diện
loyalty / spin
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 đè.
5 bảng. Quay lại loyalty.
spin_sessions
P4-15. One Lucky Draw Session per Order from its confirmed deposit; rule snapshot immutable; SPEC-04 values (spins, window) set-once; best_* = highest draw only, never a sum.
public.spin_sessions · 29 cột · 16 check · 4 unique · 9 index · 1 policy · 3 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
order_id | uuid | NOT NULL | FK → orders | |
owner_account_id | uuid | NOT NULL | FK → accounts | |
campaign_id | uuid | NOT NULL | ||
rule_version_id | uuid | NOT NULL | FK → spin_rule_versions | |
rule_version_no | integer | NOT NULL | ||
order_version | integer | NOT NULL | ||
deposit_confirmed_at | timestamptz | NOT NULL | ||
source_event_id | uuid | NOT NULL | ||
correlation_id | correlation_ref | NOT NULL | ||
spins_allotted | integer | |||
window_starts_at | timestamptz | |||
window_ends_at | timestamptz | |||
state | text | NOT NULL | VQM-P1-06 / P1-07 / P1-08 (S9, DEC-VQM-18). NOT_ENTERED | ACTIVE | COMPLETED | FORFEITED. KEPT / EXPIRED_UNSPUN are deprecated SDL values only (mapped by 080400 / 080500, refused by the CHECK since 080600). | |
spins_used | integer | NOT NULL | ||
best_draw_id | uuid | |||
best_points | integer | |||
ended_at | timestamptz | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
version | integer | NOT NULL | ||
session_duration_seconds | integer | |||
config_snapshot | jsonb | FU-717. Copy of the rule version configuration (prize_tiers, order_time_intervals, version no, duration) taken when the session was created; immutable. | ||
end_reason | text | VQM-P1-06. ALL_SPINS_USED | LEFT | DISCONNECTED | ORDER_CANCELLED | CAMPAIGN_CLOSED (NOT_ENTERED forfeits only) | WINDOW_EXPIRED (legacy windowed sessions); derived by the guard with the state change; NULL while NOT_ENTERED / ACTIVE / KEPT and for sessions ended before SPEC-04. | ||
resume_request_id | text | G1S-P1-06. Request id of the last resumeSpinSession (spin.resume_session): a repeat returns the session unchanged. | ||
entered_at | timestamptz | VQM-P1-06 BR-VQ-08. When the buyer entered the session (NOT_ENTERED -> ACTIVE), set once by the guard; null for a session never entered and for the pre-VQM windowed sessions. | ||
last_seen_at | timestamptz | VQM-P1-06 BR-VQ-08 E. Last signal of the app (enter, heartbeat, draw) on an entered ACTIVE session, DB now() only. | ||
round_no | integer | VQM-P1-06 BR-VQ-06. The round (Đợt) of the deposit that granted the spins (shape 2 rule); null for a legacy rule. | ||
wheel_id | uuid | NOT NULL | FK → wheels | VQM-P1-06. The wheel of the session rule version (spin_rule_versions.wheel_id), set at insert; immutable. |
Khoá chính: id
Trỏ ra (4):
order_id→orders·ON DELETE RESTRICTowner_account_id→accounts·ON DELETE RESTRICTrule_version_id→spin_rule_versions·ON DELETE RESTRICTwheel_id→wheels·ON DELETE RESTRICT
Được trỏ tới (2): spin_draws, spin_results
spin_draws
P4-15. Append-only server draws of a session (configured tier only, inside the window, one per spin).
public.spin_draws · 11 cột · 5 check · 3 unique · 4 index · 1 policy · 5 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
session_id | uuid | NOT NULL | FK → spin_sessions | |
draw_no | integer | NOT NULL | ||
request_id | text | NOT NULL | ||
rule_version_id | uuid | NOT NULL | ||
tier_no | integer | NOT NULL | ||
points | integer | NOT NULL | ||
drawn_at | timestamptz | NOT NULL | ||
correlation_id | correlation_ref | NOT NULL | ||
roll_pct | numeric | P4-16. Server uniform random in [0,100) the tier was derived from (audit); NULL only for pre-P4-16 fixtures. | ||
rng_source | text | P4-16. Generator that produced roll_pct (e.g. WEB_CRYPTO_GETRANDOMVALUES). |
Khoá chính: id
Trỏ ra (1):
session_id→spin_sessions·ON DELETE RESTRICT
Được trỏ tới (1): spin_results
spin_rule_versions
P4-15. Lucky Wheel config per Campaign (A-SPIN-01 intervals, A-SPIN-02 tiers); immutable once PUBLISHED; order-time basis, boundary, per-spin table and SPEC-04 session rule stay UNDECIDED.
public.spin_rule_versions · 24 cột · 12 check · 1 unique · 4 index · 3 policy · 3 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
campaign_id | uuid | FK → campaigns | Legacy (CV3-P1-07): the campaign the version was written for through the campaign path (before CV3, or the deprecated campaignId argument); not a key. Null for a version written for a wheel. | |
version_no | integer | NOT NULL | ||
status | text | NOT NULL | ||
order_time_intervals | jsonb | P4-15 A-SPIN-01. Shape 1 only (null on shape 2, VQM-P1-02): [{starts_at, ends_at, spins}] (spin.intervals_ok). | ||
prize_tiers | jsonb | NOT NULL | P4-15 A-SPIN-02 [{tier_no, points, probability_pct}]: shape 1 spin.prize_tiers_ok; shape 2 the 8 slots (spin.slots_ok, VQM-P1-02). | |
order_time_basis | text | NOT NULL | G2I-P1-02 (D6). DEPOSIT_CONFIRMED for every version saved from 2026-12-25; UNDECIDED rows predate it and are read the same way (the rule is global). | |
interval_boundary | text | NOT NULL | ||
prize_table_scope | text | NOT NULL | ||
session_rule_status | text | NOT NULL | FU-717. INTERIM_SPEC04 = the SPEC-04 interim session rule applies (10 minutes from creation); UNDECIDED = the pre-decision shape (no window). Immutable once PUBLISHED. | |
session_rule_ref | text | NOT NULL | ||
session_duration_seconds | integer | FU-717. Session length in seconds, snapshotted into each session at creation; 600 by SPEC-04 (interim). | ||
published_at | timestamptz | |||
published_by | uuid | FK → accounts | ||
superseded_at | timestamptz | |||
created_by | uuid | NOT NULL | FK → accounts | |
updated_by | uuid | NOT NULL | FK → accounts | |
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
version | integer | NOT NULL | ||
wheel_id | uuid | NOT NULL | FK → wheels | CV3-P1-07 DEC-CV3-05. The wheel this version configures; version_no counts per wheel. |
shape | smallint | NOT NULL | VQM-P1-02. 1 = legacy rule (order_time_intervals + prize_tiers); 2 = Word 12/11 rule (rounds + 8 slots in prize_tiers + tone). Immutable once PUBLISHED like the rest of the configuration. | |
rounds | jsonb | VQM-P1-02 BR-VQ-06. Shape 2 only: [{to_day, spins}] in round order, the last to_day null (spin.rounds_ok); cut to a campaign by spin.resolve_rounds. | ||
tone | text | VQM-P1-02 BR-VQ-07. Shape 2 only: ORANGE | CHERRY_PINK, the tone snapshot of the version (slot colours from spin.tone_palette). |
Khoá chính: id
Trỏ ra (5):
campaign_id→campaigns·ON DELETE RESTRICTcreated_by→accounts·ON DELETE RESTRICTpublished_by→accounts·ON DELETE RESTRICTupdated_by→accounts·ON DELETE RESTRICTwheel_id→wheels·ON DELETE RESTRICT
Được trỏ tới (1): spin_sessions
spin_order_outcomes
G1S-P1-06. Why an order with a confirmed deposit has no Lucky Wheel session, when the App shows it: NO_SPINS (D6, the deposit is in no interval with spins) or NO_WALLET (P3, no linked Ví của tôi). One row per order, written once by spin.open_session_from_deposit, read by spin.order_spin; no other access.
public.spin_order_outcomes · 9 cột · 1 check · 0 unique · 1 index · 0 policy · 2 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
order_id | uuid | NOT NULL | PK FK → orders | |
outcome | text | NOT NULL | ||
owner_account_id | uuid | NOT NULL | FK → accounts | |
campaign_id | uuid | NOT NULL | ||
rule_version_id | uuid | |||
deposit_confirmed_at | timestamptz | NOT NULL | ||
source_event_id | uuid | NOT NULL | ||
correlation_id | correlation_ref | NOT NULL | ||
created_at | timestamptz | NOT NULL |
Khoá chính: order_id
Trỏ ra (2):
order_id→orders·ON DELETE RESTRICTowner_account_id→accounts·ON DELETE RESTRICT
Được trỏ tới: không có
spin_results
P4-15. The one retained outcome per session = its highest draw (base points, no sum); immutable.
public.spin_results · 9 cột · 1 check · 1 unique · 2 index · 1 policy · 3 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
session_id | uuid | NOT NULL | FK → spin_sessions | |
owner_account_id | uuid | NOT NULL | FK → spin_sessions | |
order_id | uuid | NOT NULL | FK → orders | |
rule_version_id | uuid | NOT NULL | ||
draw_id | uuid | NOT NULL | FK → spin_draws | |
base_points | integer | NOT NULL | ||
recorded_at | timestamptz | NOT NULL | ||
correlation_id | correlation_ref | NOT NULL |
Khoá chính: id
Trỏ ra (3):
draw_id, session_id→spin_draws·ON DELETE RESTRICTorder_id→orders·ON DELETE RESTRICTsession_id, owner_account_id→spin_sessions·ON DELETE RESTRICT
Được trỏ tới: không có