Skip to content

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ộtKiểuKhoáMô tả
iduuidNOT NULLPK
order_iduuidNOT NULLFK → orders
owner_account_iduuidNOT NULLFK → accounts
campaign_iduuidNOT NULL
rule_version_iduuidNOT NULLFK → spin_rule_versions
rule_version_nointegerNOT NULL
order_versionintegerNOT NULL
deposit_confirmed_attimestamptzNOT NULL
source_event_iduuidNOT NULL
correlation_idcorrelation_refNOT NULL
spins_allottedinteger
window_starts_attimestamptz
window_ends_attimestamptz
statetextNOT NULLVQM-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_usedintegerNOT NULL
best_draw_iduuid
best_pointsinteger
ended_attimestamptz
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
versionintegerNOT NULL
session_duration_secondsinteger
config_snapshotjsonbFU-717. Copy of the rule version configuration (prize_tiers, order_time_intervals, version no, duration) taken when the session was created; immutable.
end_reasontextVQM-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_idtextG1S-P1-06. Request id of the last resumeSpinSession (spin.resume_session): a repeat returns the session unchanged.
entered_attimestamptzVQM-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_attimestamptzVQM-P1-06 BR-VQ-08 E. Last signal of the app (enter, heartbeat, draw) on an entered ACTIVE session, DB now() only.
round_nointegerVQM-P1-06 BR-VQ-06. The round (Đợt) of the deposit that granted the spins (shape 2 rule); null for a legacy rule.
wheel_iduuidNOT NULLFK → wheelsVQM-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 RESTRICT
  • owner_account_id → accounts · ON DELETE RESTRICT
  • rule_version_id → spin_rule_versions · ON DELETE RESTRICT
  • wheel_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ộtKiểuKhoáMô tả
iduuidNOT NULLPK
session_iduuidNOT NULLFK → spin_sessions
draw_nointegerNOT NULL
request_idtextNOT NULL
rule_version_iduuidNOT NULL
tier_nointegerNOT NULL
pointsintegerNOT NULL
drawn_attimestamptzNOT NULL
correlation_idcorrelation_refNOT NULL
roll_pctnumericP4-16. Server uniform random in [0,100) the tier was derived from (audit); NULL only for pre-P4-16 fixtures.
rng_sourcetextP4-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ộtKiểuKhoáMô tả
iduuidNOT NULLPK
campaign_iduuidFK → campaignsLegacy (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_nointegerNOT NULL
statustextNOT NULL
order_time_intervalsjsonbP4-15 A-SPIN-01. Shape 1 only (null on shape 2, VQM-P1-02): [{starts_at, ends_at, spins}] (spin.intervals_ok).
prize_tiersjsonbNOT NULLP4-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_basistextNOT NULLG2I-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_boundarytextNOT NULL
prize_table_scopetextNOT NULL
session_rule_statustextNOT NULLFU-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_reftextNOT NULL
session_duration_secondsintegerFU-717. Session length in seconds, snapshotted into each session at creation; 600 by SPEC-04 (interim).
published_attimestamptz
published_byuuidFK → accounts
superseded_attimestamptz
created_byuuidNOT NULLFK → accounts
updated_byuuidNOT NULLFK → accounts
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
versionintegerNOT NULL
wheel_iduuidNOT NULLFK → wheelsCV3-P1-07 DEC-CV3-05. The wheel this version configures; version_no counts per wheel.
shapesmallintNOT NULLVQM-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.
roundsjsonbVQM-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.
tonetextVQM-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 RESTRICT
  • created_by → accounts · ON DELETE RESTRICT
  • published_by → accounts · ON DELETE RESTRICT
  • updated_by → accounts · ON DELETE RESTRICT
  • wheel_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ộtKiểuKhoáMô tả
order_iduuidNOT NULLPK FK → orders
outcometextNOT NULL
owner_account_iduuidNOT NULLFK → accounts
campaign_iduuidNOT NULL
rule_version_iduuid
deposit_confirmed_attimestamptzNOT NULL
source_event_iduuidNOT NULL
correlation_idcorrelation_refNOT NULL
created_attimestamptzNOT NULL

Khoá chính: order_id

Trỏ ra (2):

  • order_id → orders · ON DELETE RESTRICT
  • owner_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ộtKiểuKhoáMô tả
iduuidNOT NULLPK
session_iduuidNOT NULLFK → spin_sessions
owner_account_iduuidNOT NULLFK → spin_sessions
order_iduuidNOT NULLFK → orders
rule_version_iduuidNOT NULL
draw_iduuidNOT NULLFK → spin_draws
base_pointsintegerNOT NULL
recorded_attimestamptzNOT NULL
correlation_idcorrelation_refNOT NULL

Khoá chính: id

Trỏ ra (3):

  • draw_id, session_id → spin_draws · ON DELETE RESTRICT
  • order_id → orders · ON DELETE RESTRICT
  • session_id, owner_account_id → spin_sessions · ON DELETE RESTRICT

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

Sinh từ ad83b0aea · 820 migration · PostgreSQL 17