Giao diện
campaign / recurring
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 đè.
8 bảng. Quay lại campaign.
recurring_baskets
P2-09. A buyer's draft selection (UA-11 cart + UA-12 term) from one Recurring campaign; not an Order, not a reservation. OWN_ROW for the APP_USER buyer.
public.recurring_baskets · 19 cột · 9 check · 2 unique · 6 index · 3 policy · 7 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
campaign_id | uuid | NOT NULL | FK → campaign_delivery_windows | |
campaign_type | text | NOT NULL | FK → campaigns | |
owner_account_id | uuid | NOT NULL | FK → accounts | |
term_cycles | integer | FK → campaign_term_packages | Số kỳ of the chosen package (FK with package_no). G2S-P0-03: null while no package is chosen (a draft saved from G2-02 / G2-03, BR-MD-05); RecurringBasket.termCycles reads 0 then. | |
policy_version_id | uuid | NOT NULL | FK → campaign_policy_versions | |
status | text | NOT NULL | ||
discarded_at | timestamptz | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
version | integer | NOT NULL | ||
order_id | uuid | FK → orders | P2-13. The Recurring order that committed this basket (status COMMITTED); written by the order insert only. | |
committed_at | timestamptz | |||
package_no | integer | FK → campaign_term_packages | ||
delivery_window_no | integer | FK → campaign_delivery_windows | ||
skip_max | integer | |||
package_reward_value | integer | |||
closed_notice_at | timestamptz | G2S-P0-03 (BR-MD-05, S3). When the campaign close discarded this draft; RecurringBasket.closedNotice is read once from it (G2S-P1-03). DISCARDED rows only. | ||
closed_notice_read_at | timestamptz | G2S-P1-03 (BR-MD-05, S3). When myRecurringBasket returned the close notice of this basket (closedNotice true once). |
Khoá chính: id
Trỏ ra (6):
campaign_id, campaign_type→campaigns·ON DELETE RESTRICTorder_id→orders·ON DELETE RESTRICTowner_account_id→accounts·ON DELETE RESTRICTcampaign_id, package_no, term_cycles→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 (4): order_quotes, recurring_basket_cycle_lines, recurring_basket_lines, recurring_skip_requests
recurring_cycles
P2-06 shape only (P2-09 extends): Recurring delivery schedule, one row per period 1..12; no skip/close state.
public.recurring_cycles · 14 cột · 4 check · 2 unique · 3 index · 4 policy · 4 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
campaign_id | uuid | NOT NULL | FK → campaigns | |
campaign_type | text | NOT NULL | FK → campaigns | |
cycle_no | integer | NOT NULL | ||
delivers_from | timestamptz | NOT NULL | ||
delivers_to | timestamptz | NOT NULL | ||
created_by | uuid | NOT NULL | FK → accounts | |
updated_by | uuid | NOT NULL | FK → accounts | |
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
skip_cutoff_at | timestamptz | P2-09, retired by FU-RECCLOSE: always NULL. The cutoff of a cycle is delivers_from minus the approved version (campaign.skip_cutoff_version()). | ||
delivers_from_vn | date | P2-09. Vietnam calendar date (UTC+07:00) of delivers_from; generated. | ||
delivers_to_vn | date | P2-09. Vietnam calendar date (UTC+07:00) of delivers_to; generated. | ||
delivery_month | date | U19-P1-05. Month of the period (day 1) = campaigns.delivery_start_month + (cycle_no - 1) months; set by rebuild_cycles. |
Khoá chính: id
Trỏ ra (3):
campaign_id, campaign_type→campaigns·ON DELETE CASCADEcreated_by→accounts·ON DELETE RESTRICTupdated_by→accounts·ON DELETE RESTRICT
Được trỏ tới (4): order_cycles, order_periods, recurring_skip_requests, shipments
recurring_forfeit_reviews
FU-RECCLOSE. Maker/checker review of a Recurring cycle forfeit (DEC-CP-SKIP: an Operations approver who is not the maker). Records the decision only: no order, payment or point effect (undecided, GAP-132).
public.recurring_forfeit_reviews · 15 cột · 6 check · 1 unique · 4 index · 0 policy · 3 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
order_id | uuid | NOT NULL | FK → order_periods | |
cycle_no | integer | NOT NULL | FK → order_periods | |
campaign_id | uuid | NOT NULL | FK → campaigns | |
status | text | NOT NULL | ||
version | integer | NOT NULL | ||
reason | text | NOT NULL | ||
payload_hash | bytea | NOT NULL | ||
proposed_by | uuid | NOT NULL | FK → accounts | |
proposed_at | timestamptz | NOT NULL | ||
decided_by | uuid | FK → accounts | ||
decided_at | timestamptz | |||
decision_note | text | |||
source_id | text | NOT NULL | ||
correlation_id | correlation_ref |
Khoá chính: id
Trỏ ra (5):
campaign_id→campaigns·ON DELETE RESTRICTdecided_by→accounts·ON DELETE RESTRICTorder_id→orders·ON DELETE RESTRICTorder_id, cycle_no→order_periods·ON DELETE RESTRICTproposed_by→accounts·ON DELETE RESTRICT
Được trỏ tới (2): recurring_forfeit_effects, refund_cases
recurring_basket_lines
P2-09. Product lines (quantity per cycle) of a DRAFT recurring basket; same campaign, one line per product.
public.recurring_basket_lines · 7 cột · 1 check · 1 unique · 3 index · 4 policy · 3 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
basket_id | uuid | NOT NULL | FK → recurring_baskets | |
campaign_id | uuid | NOT NULL | FK → campaign_products | |
campaign_product_id | uuid | NOT NULL | FK → campaign_products | |
quantity_per_cycle | integer | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
Khoá chính: id
Trỏ ra (2):
basket_id, campaign_id→recurring_baskets·ON DELETE RESTRICTcampaign_product_id, campaign_id→campaign_products·ON DELETE RESTRICT
Được trỏ tới (1): recurring_basket_cycle_lines
recurring_skip_cutoff_versions
FU-RECCLOSE. Approved versions of the Recurring self-skip cutoff (hours before the cycle starts), maker != checker, append-only. Empty until Operations records a value (DEC-CP-SKIP-CUTOFF is open): skip then answers policy_undecided.
public.recurring_skip_cutoff_versions · 9 cột · 4 check · 1 unique · 2 index · 0 policy · 2 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
version_no | integer | NOT NULL | ||
hours_before_cycle | integer | NOT NULL | ||
effective_from | timestamptz | NOT NULL | ||
source_ref | text | NOT NULL | ||
recorded_by | uuid | NOT NULL | FK → accounts | |
approved_by | uuid | NOT NULL | FK → accounts | |
approved_at | timestamptz | NOT NULL | ||
created_at | timestamptz | NOT NULL |
Khoá chính: id
Trỏ ra (2):
approved_by→accounts·ON DELETE RESTRICTrecorded_by→accounts·ON DELETE RESTRICT
Được trỏ tới (1): recurring_skip_requests
recurring_basket_cycle_lines
G2I-P2-01 (G2-06, DEC-OWN22-G2-06). Sparse per-cycle quantity of a DRAFT basket line where it differs from quantity_per_cycle; 0 = not delivered that cycle. Replaced by the save command, never updated.
public.recurring_basket_cycle_lines · 5 cột · 2 check · 0 unique · 1 index · 3 policy · 3 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
basket_id | uuid | NOT NULL | PK FK → recurring_basket_lines | |
campaign_id | uuid | NOT NULL | FK → recurring_baskets | |
cycle_no | integer | NOT NULL | PK | |
campaign_product_id | uuid | NOT NULL | PK FK → recurring_basket_lines | |
quantity | integer | NOT NULL |
Khoá chính: basket_id, cycle_no, campaign_product_id
Trỏ ra (2):
basket_id, campaign_id→recurring_baskets·ON DELETE RESTRICTbasket_id, campaign_product_id→recurring_basket_lines·ON DELETE CASCADE
Được trỏ tới: không có
recurring_forfeit_effects
FU-FORFEIT. One immutable row per APPROVED cycle forfeit review: the cycle that left the delivery plan and the stored cash and points share refunded for it (DEC-CP-FORFEIT-EFFECT, interim). No penalty or fee.
public.recurring_forfeit_effects · 10 cột · 2 check · 2 unique · 3 index · 0 policy · 3 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
review_id | uuid | NOT NULL | FK → recurring_forfeit_reviews | |
order_id | uuid | NOT NULL | FK → orders | |
cycle_no | integer | NOT NULL | ||
order_cycle_id | uuid | NOT NULL | FK → order_cycles | |
cash_vnd | bigint | NOT NULL | ||
points | integer | NOT NULL | ||
refund_outcome | text | NOT NULL | ||
rule_version | text | NOT NULL | ||
created_at | timestamptz | NOT NULL |
Khoá chính: id
Trỏ ra (3):
order_cycle_id→order_cycles·ON DELETE RESTRICTorder_id→orders·ON DELETE RESTRICTreview_id→recurring_forfeit_reviews·ON DELETE RESTRICT
Được trỏ tới: không có
recurring_skip_requests
P2-18 (shape of P2-09). One skip request of one committed period of a Recurring order with the immutable policy/n/cutoff snapshot; REQUESTED -> CANCELLED only. Rows exist only under an APPROVED skip rule. A skip is never a delivery and never cancels the commitment.
public.recurring_skip_requests · 29 cột · 10 check · 1 unique · 4 index · 1 policy · 7 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
basket_id | uuid | NOT NULL | FK → recurring_baskets | |
campaign_id | uuid | NOT NULL | FK → campaign_policy_versions | |
cycle_id | uuid | NOT NULL | FK → recurring_cycles | |
owner_account_id | uuid | NOT NULL | FK → accounts | |
request_id | text | NOT NULL | ||
policy_version_id | uuid | NOT NULL | FK → campaign_policy_versions | |
skip_rule_status | text | NOT NULL | ||
skip_rule_ref | text | NOT NULL | ||
skip_max_count | integer | NOT NULL | ||
skip_cutoff_at | timestamptz | NOT NULL | ||
prior_skip_count | integer | NOT NULL | ||
requested_at | timestamptz | NOT NULL | ||
order_id | uuid | NOT NULL | FK → order_periods | |
cycle_no | integer | NOT NULL | FK → order_periods | |
order_cycle_id | uuid | FK → order_cycles | ||
status | text | NOT NULL | ||
version | integer | NOT NULL | ||
decision_rule_code | text | NOT NULL | ||
decision_rule_version | text | NOT NULL | ||
decided_at | timestamptz | NOT NULL | ||
count_after | integer | NOT NULL | ||
source_id | text | NOT NULL | ||
status_changed_at | timestamptz | NOT NULL | ||
cancelled_at | timestamptz | |||
cancel_source_id | text | |||
skip_cutoff_version_id | uuid | FK → recurring_skip_cutoff_versions | FU-RECCLOSE. The cutoff version the request was decided under (skip_cutoff_at is derived from it). | |
reason_code | text | G2I-P1-01 D12. Why the buyer skips (design O-37B); optional at the API, null on older rows. Insert only. | ||
reason_text | text | G2I-P1-01 D12. The buyer's own words (1..200, trimmed); optional. Insert only; staff read it (cycle schedule). |
Khoá chính: id
Trỏ ra (8):
basket_id, campaign_id→recurring_baskets·ON DELETE RESTRICTcycle_id, campaign_id→recurring_cycles·ON DELETE RESTRICTorder_cycle_id→order_cycles·ON DELETE RESTRICTorder_id→orders·ON DELETE RESTRICTowner_account_id→accounts·ON DELETE RESTRICTorder_id, cycle_no→order_periods·ON DELETE RESTRICTpolicy_version_id, campaign_id→campaign_policy_versions·ON DELETE RESTRICTskip_cutoff_version_id→recurring_skip_cutoff_versions·ON DELETE RESTRICT
Được trỏ tới: không có