Giao diện
order_fulfillment / order
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 đè.
14 bảng. Quay lại order_fulfillment.
orders
P2-11. Order commitment with an immutable quote snapshot (V0, deposit, point cap/rate, policy version, tiers, milestone, address). State machine + expectedVersion by trigger; OWN read (U-01).
public.orders · 65 cột · 20 check · 3 unique · 16 index · 2 policy · 17 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
owner_account_id | uuid | NOT NULL | FK → order_quotes | |
request_id | text | NOT NULL | ||
quote_id | uuid | NOT NULL | FK → order_quotes | |
campaign_id | uuid | NOT NULL | FK → campaign_delivery_windows | |
campaign_type | text | NOT NULL | FK → campaigns | |
campaign_version | integer | NOT NULL | ||
policy_version_id | uuid | NOT NULL | FK → campaign_policy_versions | |
committed_cycle_count | integer | NOT NULL | FK → campaign_term_packages | |
v0_vnd | bigint | NOT NULL | ||
deposit_rate_bp | integer | NOT NULL | ||
deposit_vnd | bigint | NOT NULL | ||
point_cap_bp | integer | NOT NULL | ||
point_cap_policy_version | text | NOT NULL | ||
point_rate_snapshot_vnd | numeric | NOT NULL | ||
point_rate_policy_version | text | NOT NULL | ||
max_points | integer | NOT NULL | ||
points_used | integer | NOT NULL | ||
points_value_vnd | bigint | NOT NULL | ||
close_rule_ref | text | NOT NULL | ||
shortage_rule_versions | text[] | NOT NULL | ||
tier_snapshot | jsonb | NOT NULL | ||
quoted_at | timestamptz | NOT NULL | ||
milestone_id | uuid | FK → delivery_milestones | ||
milestone_no | integer | |||
milestone_delivers_from | timestamptz | |||
milestone_delivers_to | timestamptz | |||
milestone_reward_point_bp | integer | |||
address_id | uuid | NOT NULL | FK → addresses | |
ship_recipient_name | text | NOT NULL | ||
ship_recipient_phone | phone_e164 | NOT NULL | ||
ship_province | text | NOT NULL | ||
ship_district | text | NOT NULL | ||
ship_ward | text | NOT NULL | ||
ship_address_line | text | NOT NULL | ||
ship_address_type | text | NOT NULL | ||
state | text | NOT NULL | ||
state_changed_at | timestamptz | NOT NULL | ||
updated_by | uuid | FK → accounts | ||
change_source | text | NOT NULL | ||
change_source_id | text | NOT NULL | ||
change_reason | text | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
version | integer | NOT NULL | ||
code | text | NOT NULL | #298. Business order code, unique (case-insensitive), immutable. TEMPORARY format PO + 8 A-Z0-9 (ordering.new_order_code(); Product format open: NEW-SL-12). No format CHECK on purpose. | |
order_status | ordering.order_axis | NOT NULL | U19-P1-07. Word order axis (B013.R02), stored; moved by the order writers and ordering.set_order_axes only. | |
payment_status | ordering.payment_axis | NOT NULL | U19-P1-07. Word payment axis (B013.R02), stored independently of order_status. | |
cancel_reason | ordering.cancel_reason | U19-P1-07. Why the order is CANCELLED; null for every other status. | ||
confirmed_at | timestamptz | U19-P1-07. Ngay duyet: when the order became CONFIRMED. | ||
status_version | integer | NOT NULL | U19-P1-07. +1 on every write of the axes. | |
shipping_status | ordering.shipping_axis | NOT NULL | U19-P1-08. Word shipping axis (B013.R02) of a Group Buy order; a Recurring order uses order_cycles.shipping_status. | |
package_no | integer | FK → campaign_term_packages | U19-P1-05. Gói kỳ cam kết chosen for the whole basket (B208.R06); belongs to the campaign with this term. | |
delivery_window_no | integer | FK → campaign_delivery_windows | U19-P1-05. Khung ngày giao chosen by the buyer (B208.R05). | |
skip_max | integer | U19-P1-05. Snapshot of the package Được bỏ qua tối đa (App skip button only, owner GAP-W-CD-14). | ||
package_reward_value | integer | U19-P1-05. Snapshot of the package Pi-Point thưởng, in the campaign reward unit (B220.R07). | ||
customer_note | text | U19-P2-11. Ghi chu cua khach (B036.R02): typed by the buyer when ordering, <= 500 characters; read-only for staff. | ||
address_version | integer | NOT NULL | U19-P2-11. Revision of the delivery snapshot (address_id + ship_*). PAF-P1-04 (DEC-PAF-03): the address of an order never changes after creation, so new orders stay at 1; > 1 only on orders changed before PAF-P1-04. | |
address_updated_at | timestamptz | U19-P2-11. When the buyer changed the delivery address on the app (before PAF-P1-04, DEC-PAF-03, no change is possible any more); null = the address given at order time. | ||
deposit_basis | text | NOT NULL | U19-P2-36. Copied from the quote: V0 (rows before U19-P2-36, never recomputed) or PAYABLE (Khách phải trả). | |
terms_accepted | boolean | U19-P2-36. TRUE = the buyer ticked the terms at submit; NULL = not recorded (the App sends no tick yet). | ||
terms_set_id | uuid | FK → deal_terms_sets | U19-P2-36. Điều khoản tham gia Deal set of the campaign the buyer ticked at submit (B006.R15); NULL when not ticked. | |
participant_ordinal | integer | G1S-P0-03 + DEC-OWN30-S1-ORDINAL (BR-MC-02 per owner 30/10, TB-05 / TB-19). Nguoi thu n: the participant count of the Deal (Mua chung) / basket (Mua dinh ky) at the deposit confirmation, buyer included, fixed then; null before. Orders confirmed before 20261229070000 keep the earlier rank rule. | ||
deposit_rounding | text | NOT NULL | G1S-P1-01. Copied from the quote: CEIL (up to whole VND, BR-APP-06) or HALF_UP (orders before 20261227010000, never recomputed). Not read by the V0 basis. | |
repriced_from_quote_id | uuid | FK → order_quotes | G1S-P1-04. The quote the buyer saw when submitGroupOrder wrote the order from a fresh quote at the current price (BR-DC-05/07, owner P4); consumed with the order's quote by orders_guard_insert. NULL = the quoted price. |
Khoá chính: id
Trỏ ra (11):
address_id→addresses·ON DELETE RESTRICTcampaign_id, campaign_type→campaigns·ON DELETE RESTRICTmilestone_id→delivery_milestones·ON DELETE RESTRICTowner_account_id→accounts·ON DELETE RESTRICTcampaign_id, package_no, committed_cycle_count→campaign_term_packages·ON DELETE RESTRICTpolicy_version_id, campaign_id→campaign_policy_versions·ON DELETE RESTRICTquote_id, owner_account_id→order_quotes·ON DELETE RESTRICTrepriced_from_quote_id→order_quotesterms_set_id→deal_terms_sets·ON DELETE RESTRICTupdated_by→accounts·ON DELETE RESTRICTcampaign_id, delivery_window_no→campaign_delivery_windows·ON DELETE RESTRICT
Được trỏ tới (41): attribution_assignments, cancellation_decisions, cashbook_entries, cod_collections, deposit_checkouts, in_app_events, mission_reversal_evidence, order_activity_log, order_close_outcomes, order_cycle_close_values, order_cycle_cod_rebalances, order_cycle_failed_deliveries, order_cycle_skip_values, order_cycles, order_first_paid_cycles, order_lines, order_payment_expiries, order_period_final_prices, order_periods, order_points_excess_refunds, order_remaining_methods, order_return_cases, order_state_events, payment_obligations, payment_overpayment_cases và 16 bảng nữa
order_cycles
P2-11 shape: Recurring cycle commitments (created after the order is LOCKED); skip/forfeit wait for G-CP.
public.order_cycles · 14 cột · 3 check · 2 unique · 5 index · 1 policy · 4 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
order_id | uuid | NOT NULL | FK → orders | |
cycle_no | integer | NOT NULL | ||
recurring_cycle_id | uuid | NOT NULL | FK → recurring_cycles | |
policy_version_id | uuid | NOT NULL | FK → campaign_policy_versions | |
state | text | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
version | integer | NOT NULL | ||
order_status | ordering.order_axis | NOT NULL | U19-P1-08. Word order axis of this cycle (B013.R03). | |
payment_status | ordering.payment_axis | NOT NULL | U19-P1-08. Word payment axis of this cycle (B013.R03). | |
shipping_status | ordering.shipping_axis | NOT NULL | U19-P1-08. Word shipping axis of this cycle (B013.R03). | |
status_version | integer | NOT NULL | U19-P1-08. +1 on every write of the cycle axes. | |
delivered_equivalent | boolean | NOT NULL | U19-P2-24. A cycle paid in full whose last delivery failed counts as delivered (DH-US-14 AC05, GAP-W-DH-08). |
Khoá chính: id
Trỏ ra (3):
order_id→orders·ON DELETE RESTRICTpolicy_version_id→campaign_policy_versions·ON DELETE RESTRICTrecurring_cycle_id→recurring_cycles·ON DELETE RESTRICT
Được trỏ tới (9): cod_collections, order_cycle_close_values, order_cycle_cod_rebalances, order_cycle_failed_deliveries, order_cycle_skip_values, payment_obligations, recurring_forfeit_effects, recurring_skip_requests, shipment_order_links
order_periods
P2-13. Committed periods of a Recurring order with the order-time (V0) allocation of deposit + points from the last period backwards; immutable, written by the order insert only. Not a Cycle Commitment.
public.order_periods · 15 cột · 4 check · 2 unique · 3 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 | |
cycle_no | integer | NOT NULL | ||
recurring_cycle_id | uuid | NOT NULL | FK → recurring_cycles | |
policy_version_id | uuid | NOT NULL | FK → campaign_policy_versions | |
delivers_from | timestamptz | NOT NULL | ||
delivers_to | timestamptz | NOT NULL | ||
value_vnd | bigint | NOT NULL | ||
prepaid_vnd | bigint | NOT NULL | ||
due_vnd | bigint | |||
allocation_basis | text | NOT NULL | ||
allocation_rule | text | NOT NULL | PAY-BRULE-26 (equal periods), BR-DK-08 (U19-P2-37: Pi-Point evenly over the periods with goods) or ACTUAL_PRICE (U28-P2-01 DEC-U28-01: Pi-Point by the line values, actual unit price ceil on the first units, deposit last -> first on V_c, COD ⌈due⌉ to 1,000đ balanced on the last period still to collect, so rounding_vnd may be negative there). | |
created_at | timestamptz | NOT NULL | ||
points_value_vnd | bigint | U19-P2-37. Pi-Point value of the period (even split, GAP-W-CD-17); prepaid_vnd - points_value_vnd = its deposit share. | ||
rounding_vnd | bigint | NOT NULL | U19-P2-37. What rounding the COD of the period up to 1,000đ adds: COD = due_vnd + rounding_vnd (B208.R09). |
Khoá chính: id
Trỏ ra (3):
order_id→orders·ON DELETE RESTRICTpolicy_version_id→campaign_policy_versions·ON DELETE RESTRICTrecurring_cycle_id→recurring_cycles·ON DELETE RESTRICT
Được trỏ tới (4): order_cycle_lines, order_period_final_prices, recurring_forfeit_reviews, recurring_skip_requests
order_close_outcomes
P2-15. Immutable per-Order Group close result: LOCK with final price / remaining / offline excess, or CANCEL with the full refund intent (cash deposit + original points) for P3. OWN read (U-01).
public.order_close_outcomes · 26 cột · 4 check · 1 unique · 4 index · 1 policy · 5 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
outcome_id | uuid | NOT NULL | FK → campaign_outcomes | |
campaign_id | uuid | NOT NULL | FK → campaign_policy_versions | |
order_id | uuid | NOT NULL | FK → orders | |
owner_account_id | uuid | NOT NULL | FK → accounts | |
policy_version_id | uuid | NOT NULL | FK → campaign_policy_versions | |
decision | text | NOT NULL | ||
from_version | integer | NOT NULL | ||
to_version | integer | NOT NULL | ||
units | bigint | NOT NULL | ||
deposit_vnd | bigint | NOT NULL | ||
points_used | integer | NOT NULL | ||
points_value_vnd | bigint | NOT NULL | ||
final_unit_price_vnd | bigint | |||
final_total_vnd | bigint | |||
remaining_vnd | bigint | |||
excess_vnd | bigint | |||
refund_cash_vnd | bigint | |||
refund_points | integer | |||
refund_rule_ref | text | |||
recorded_at | timestamptz | NOT NULL | ||
actual_total_vnd | bigint | G1S-P1-02 (BR-APP-08). Tổng giá thực tế = final total - min(Pi-Point value, final total), not rounded. Null on rows closed before 20261227010100. | ||
actual_unit_price_vnd | bigint | G1S-P1-02 (GAP-G1S-06). Giá thực tế = ceil(actual total / units), rounded UP to 1đ; never shown to the buyer. | ||
actual_ceil_units | bigint | G1S-P1-02 (GAP-G1S-06). Units carrying actual_unit_price_vnd; the others carry it - 1, so they sum to actual total. | ||
rounding_vnd | bigint | G1S-P1-02 (BR-APP-08, BR-MC-05). What rounding the remaining UP to 1,000đ adds: remaining = max(actual total - deposit, 0) + rounding_vnd (0 <= r < 1,000). | ||
excess_points | integer | G1S-P1-02 (BR-APP-08, TB-12). Pi-Point above the final order value, returned to the wallet (order_points_excess_refunds). |
Khoá chính: id
Trỏ ra (4):
order_id→orders·ON DELETE RESTRICToutcome_id, campaign_id→campaign_outcomes·ON DELETE RESTRICTowner_account_id→accounts·ON DELETE RESTRICTpolicy_version_id, campaign_id→campaign_policy_versions·ON DELETE RESTRICT
Được trỏ tới (2): order_points_excess_refunds, payment_overpayment_cases
order_lines
P2-11. Immutable order lines (Campaign Product, quantity, order-time tier price, line V0), copied from the quote.
public.order_lines · 18 cột · 5 check · 2 unique · 4 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 | |
line_no | integer | NOT NULL | ||
campaign_id | uuid | NOT NULL | FK → campaign_products | |
campaign_product_id | uuid | NOT NULL | FK → campaign_products | |
product_id | uuid | NOT NULL | FK → products | |
sku_snapshot | text | NOT NULL | ||
name_snapshot | text | |||
quantity | integer | NOT NULL | ||
cycle_count | integer | NOT NULL | ||
committed_units | bigint | NOT NULL | ||
basis_units | bigint | NOT NULL | ||
tier_min_qty | integer | NOT NULL | ||
tier_max_qty | integer | |||
unit_price_vnd | bigint | NOT NULL | ||
line_v0_vnd | bigint | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
units | bigint | NOT NULL | G2I-P2-01 (G2-06). Quantity over every cycle of the order (Σ ordering.cycle_lines); quantity stays the default per cycle. Mua chung: units = quantity. Basis, V0 and the committed quantity (MOQ, Tổng) read it. |
Khoá chính: id
Trỏ ra (3):
campaign_product_id, campaign_id→campaign_products·ON DELETE RESTRICTorder_id→orders·ON DELETE RESTRICTproduct_id→products·ON DELETE RESTRICT
Được trỏ tới (2): order_cycle_lines, order_period_final_prices
order_quotes
P2-11. Immutable server quote bound to a campaign/policy snapshot (OWN_ROW). Only OPEN -> USED by the order insert; expiry is expires_at (required TTL config). Deposit = d x V0 exactly; points separate.
public.order_quotes · 32 cột · 13 check · 1 unique · 5 index · 2 policy · 5 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
owner_account_id | uuid | NOT NULL | FK → accounts | |
campaign_id | uuid | NOT NULL | FK → campaign_delivery_windows | |
campaign_type | text | NOT NULL | FK → campaigns | |
campaign_version | integer | NOT NULL | ||
policy_version_id | uuid | NOT NULL | FK → campaign_policy_versions | |
cycle_count | integer | NOT NULL | FK → campaign_term_packages | |
lines | jsonb | NOT NULL | ||
tier_snapshot | jsonb | |||
v0_vnd | bigint | NOT NULL | ||
deposit_rate_bp | integer | NOT NULL | ||
deposit_vnd | bigint | NOT NULL | ||
point_cap_bp | integer | NOT NULL | ||
point_cap_policy_version | text | NOT NULL | ||
point_rate_snapshot_vnd | numeric | NOT NULL | ||
point_rate_policy_version | text | NOT NULL | ||
max_points | integer | NOT NULL | ||
points_used | integer | NOT NULL | ||
points_value_vnd | bigint | NOT NULL | ||
close_rule_ref | text | NOT NULL | ||
shortage_rule_versions | text[] | NOT NULL | ||
status | text | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
expires_at | timestamptz | NOT NULL | ||
version | integer | NOT NULL | ||
basket_id | uuid | FK → recurring_baskets | ||
basket_version | integer | |||
deposit_basis | text | NOT NULL | U19-P2-36. V0: deposit = V0 x rate exactly (legacy, Mua định kỳ until U19-P2-37); PAYABLE: deposit = round((V0 - points value) x rate) (Word DH B013.R04 Quy tắc 3, CD B006.R08/R09). | |
package_no | integer | FK → campaign_term_packages | U19-P2-37. Gói kỳ cam kết of a Mua định kỳ quote (B208.R06); the order copies it. | |
delivery_window_no | integer | FK → campaign_delivery_windows | U19-P2-37. Khung ngày giao chosen at the quote (B208.R05); the order copies it. | |
cycle_lines | jsonb | NOT NULL | G2I-P2-01 (G2-06). Sparse per-cycle quantities [{cycleNo, campaignProductId, quantity}] that differ from the line quantity; the order copies them into order_cycle_lines. '[]' = every cycle at the default. | |
deposit_rounding | text | NOT NULL | G1S-P1-01. PAYABLE deposit rounding: CEIL = up to whole VND (FuncSpec 27/10 BR-APP-06, DEC-OWN27-DEPOSIT-CEIL, every new quote); HALF_UP = quotes written before 20261227010000 (never recomputed). Not read by the V0 basis. |
Khoá chính: id
Trỏ ra (6):
basket_id, campaign_id→recurring_baskets·ON DELETE RESTRICTcampaign_id, campaign_type→campaigns·ON DELETE RESTRICTowner_account_id→accounts·ON DELETE RESTRICTcampaign_id, package_no, cycle_count→campaign_term_packages·ON DELETE RESTRICTpolicy_version_id, campaign_id→campaign_policy_versions·ON DELETE RESTRICTcampaign_id, delivery_window_no→campaign_delivery_windows·ON DELETE RESTRICT
Được trỏ tới (2): orders, orders
order_activity_cutover
U19-P1-09. When each legacy history branch moved to public.order_activity_log (legacy rows before it stay read).
public.order_activity_cutover · 3 cột · 1 check · 0 unique · 1 index · 0 policy · 0 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
branch | text | NOT NULL | PK | |
cutover_at | timestamptz | NOT NULL | ||
task | text | NOT NULL |
Khoá chính: branch
Trỏ ra: không có
Được trỏ tới: không có
order_activity_log
U19-P1-09. Append-only log of every action on an order (B013.R10, NFR #8); written by ordering.log_activity only.
public.order_activity_log · 13 cột · 4 check · 0 unique · 2 index · 0 policy · 2 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | bigint | NOT NULL | PK | |
order_id | uuid | NOT NULL | FK → orders | |
cycle_no | integer | |||
category | text | NOT NULL | ||
action | text | NOT NULL | ||
actor_kind | text | NOT NULL | ||
actor_account_id | uuid | FK → accounts | ||
actor_label_snapshot | text | |||
actor_roles_snapshot | text[] | |||
from_value | text | |||
to_value | text | |||
note | text | |||
occurred_at | timestamptz | NOT NULL |
Khoá chính: id
Trỏ ra (2):
actor_account_id→accounts·ON DELETE RESTRICTorder_id→orders·ON DELETE RESTRICT
Được trỏ tới: không có
order_cycle_lines
G2I-P2-01 (G2-06, DEC-OWN22-G2-06). Sparse per-cycle quantity of a Recurring order line where it differs from order_lines.quantity, copied from the quote by the order insert; immutable (no edit after ordering, E5).
public.order_cycle_lines · 5 cột · 1 check · 0 unique · 1 index · 1 policy · 3 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
order_id | uuid | NOT NULL | PK FK → order_periods | |
cycle_no | integer | NOT NULL | PK FK → order_periods | |
order_line_id | uuid | NOT NULL | PK FK → order_lines | |
quantity | integer | NOT NULL | ||
created_at | timestamptz | NOT NULL |
Khoá chính: order_id, cycle_no, order_line_id
Trỏ ra (2):
order_line_id→order_lines·ON DELETE RESTRICTorder_id, cycle_no→order_periods·ON DELETE RESTRICT
Được trỏ tới: không có
order_first_paid_cycles
FU-AC-TRIAGE L7 PAY-R1-05 HC02 / A-LOY-04 AC07. Immutable: the first actually paid cycle of a Recurring order (COD delivered AND collected, or the one online remaining), the milestone the order reward is released on once. Closed to every login.
public.order_first_paid_cycles · 6 cột · 3 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 | |
cycle_no | integer | |||
source | text | NOT NULL | ||
source_event_id | uuid | NOT NULL | ||
paid_at | timestamptz | NOT NULL | ||
recorded_at | timestamptz | NOT NULL |
Khoá chính: order_id
Trỏ ra (1):
order_id→orders·ON DELETE RESTRICT
Được trỏ tới: không có
order_period_final_prices
FU-AC-TRIAGE L7 UA-14 AC01. Immutable: the one final unit price of each product applied to every committed period of every counted order of a CONFIRMED Recurring close. Orders, deposits and obligations are untouched (AC02).
public.order_period_final_prices · 12 cột · 1 check · 1 unique · 3 index · 0 policy · 2 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
outcome_id | uuid | NOT NULL | FK → campaign_outcomes | |
campaign_id | uuid | NOT NULL | FK → campaign_outcomes | |
order_id | uuid | NOT NULL | FK → order_periods | |
cycle_no | integer | NOT NULL | FK → order_periods | |
order_line_id | uuid | NOT NULL | FK → order_lines | |
campaign_product_id | uuid | NOT NULL | ||
quantity | integer | NOT NULL | ||
order_unit_price_vnd | bigint | NOT NULL | ||
final_unit_price_vnd | bigint | NOT NULL | ||
final_value_vnd | bigint | NOT NULL | ||
recorded_at | timestamptz | NOT NULL |
Khoá chính: id
Trỏ ra (4):
order_id→orders·ON DELETE RESTRICTorder_line_id→order_lines·ON DELETE RESTRICToutcome_id, campaign_id→campaign_outcomes·ON DELETE RESTRICTorder_id, cycle_no→order_periods·ON DELETE RESTRICT
Được trỏ tới: không có
order_remaining_methods
U19-P2-21 (B013.R11). The buyer's remaining payment method (ONLINE | COD) of an order after the close; no row after the close = COD. Written only by payment.buyer_select_remaining_method (and the FU-F3 pre-close Recurring fact).
public.order_remaining_methods · 8 cột · 3 check · 0 unique · 1 index · 0 policy · 3 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
order_id | uuid | NOT NULL | PK FK → orders | |
method | text | NOT NULL | ||
source_id | text | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
chosen_at | timestamptz | |||
chosen_by | uuid | FK → accounts | U19-P2-21. The buyer who chose; null for a backfilled row. | |
version | integer | NOT NULL | U19-P2-21. +1 on every change of the choice. | |
updated_at | timestamptz | NOT NULL |
Khoá chính: order_id
Trỏ ra (2):
chosen_by→accounts·ON DELETE RESTRICTorder_id→orders·ON DELETE RESTRICT
Được trỏ tới: không có
order_return_cases
FU-OIFF01. RETURN case of one Order whose COD was refused (OI-FF-01 decided 2026-10-05): shipment RETURNED, stored refusal fact, COD never collected. Order LOCKED -> CANCELLED, COD obligation cancelled, Pending reward cancelled; deposit and points disposition UNDECIDED (GAP-1321). Immutable; moves no money and no points.
public.order_return_cases · 30 cột · 11 check · 2 unique · 6 index · 2 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 | |
shipment_id | uuid | NOT NULL | FK → shipments | |
cod_collection_id | uuid | NOT NULL | FK → cod_collections | |
owner_account_id | uuid | NOT NULL | FK → accounts | |
campaign_id | uuid | NOT NULL | FK → campaigns | |
campaign_type | text | NOT NULL | ||
case_type | text | NOT NULL | ||
cause | text | NOT NULL | ||
reason | text | NOT NULL | ||
evidence_media_ids | uuid[] | NOT NULL | ||
refusal_source | text | NOT NULL | ||
refusal_ref | uuid | NOT NULL | ||
returned_at | timestamptz | NOT NULL | ||
cod_status | text | NOT NULL | ||
cod_amount_due_vnd | bigint | NOT NULL | ||
deposit_vnd | bigint | NOT NULL | ||
points_used | integer | NOT NULL | ||
points_value_vnd | bigint | NOT NULL | ||
from_version | integer | NOT NULL | ||
to_version | integer | NOT NULL | ||
policy_ref | text | NOT NULL | ||
deposit_disposition | text | NOT NULL | ||
points_disposition | text | NOT NULL | ||
reward_disposition | text | NOT NULL | ||
undecided_ref | text | |||
recorded_by | uuid | NOT NULL | FK → accounts | |
source_event_id | text | NOT NULL | ||
recorded_at | timestamptz | NOT NULL | ||
version | integer | NOT NULL |
Khoá chính: id
Trỏ ra (6):
campaign_id→campaigns·ON DELETE RESTRICTcod_collection_id→cod_collections·ON DELETE RESTRICTorder_id→orders·ON DELETE RESTRICTowner_account_id→accounts·ON DELETE RESTRICTrecorded_by→accounts·ON DELETE RESTRICTshipment_id→shipments·ON DELETE RESTRICT
Được trỏ tới: không có
order_state_events
P2-11. Append-only order history: one row per order version (CREATED / TRANSITIONED, source, actor, reason).
public.order_state_events · 14 cột · 4 check · 2 unique · 5 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 | |
order_version | integer | NOT NULL | ||
event_type | text | NOT NULL | ||
from_state | text | |||
to_state | text | NOT NULL | ||
policy_version_id | uuid | NOT NULL | FK → campaign_policy_versions | |
source | text | NOT NULL | ||
source_event_id | text | NOT NULL | ||
actor_account_id | uuid | FK → accounts | ||
reason | text | |||
recorded_at | timestamptz | NOT NULL | ||
actor_label | text | U13-FU-06. Actor profile full name at insert time (null: no actor, no profile, or a row older than the snapshot). | ||
actor_roles | text[] | U13-FU-06. Actor ACTIVE WEB_ADMIN role codes at insert time (null: no actor, or a row older than the snapshot). |
Khoá chính: id
Trỏ ra (3):
actor_account_id→accounts·ON DELETE RESTRICTorder_id→orders·ON DELETE RESTRICTpolicy_version_id→campaign_policy_versions·ON DELETE RESTRICT
Được trỏ tới: không có