Giao diện
campaign / campaign
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 đè.
10 bảng. Quay lại campaign.
campaigns
P2-06. Group Buy / Recurring campaign aggregate: state machine + version CAS enforced by trigger; every version is one campaign_state_events row. PERM_GATED campaign managers (GAP-26: none yet).
public.campaigns · 34 cột · 26 check · 2 unique · 9 index · 4 policy · 13 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
campaign_type | text | NOT NULL | ||
name | text | |||
description | text | |||
opens_at | timestamptz | |||
closes_at | timestamptz | |||
term_options | integer[] | |||
state | text | NOT NULL | ||
state_changed_at | timestamptz | NOT NULL | ||
created_by | uuid | NOT NULL | FK → accounts | |
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 | ||
publish_at | timestamptz | U19-P1-01. Thời gian công bố (B006.R04): PENDING_PUBLISH -> UPCOMING at this time; immutable once UPCOMING. | ||
published_at | timestamptz | U19-P1-01. When the campaign entered UPCOMING (trigger-written). | ||
opened_at | timestamptz | U19-P1-01. When the campaign entered OPEN (trigger-written). | ||
closed_at | timestamptz | U19-P1-01. When the campaign entered CLOSING (trigger-written). | ||
reward_unit | text | U19-P1-04. Đơn vị Pi-Point thưởng (B058.R09/B214.R08): PERCENT_ORDER (bp of the order value) | POINTS_PER_ORDER. | ||
point_cap_bp | integer | U19-P1-04. Trần thanh toán bằng Pi-Point per campaign (B064.R07), bp 0..10000; replaces the global POINT_CAP. | ||
pay_now_bonus | integer | U19-P1-04 / PAF-P1-08. Mua chung: Thưởng thanh toán online (B064.R08), whole number in reward_unit; NULL = none. | ||
prepay_all_bonus | integer | U19-P1-04. Mua định kỳ: Thưởng khi trả trước toàn bộ các kỳ (B223.R04), whole number in reward_unit; NULL = none. | ||
terms_set_id | uuid | FK → deal_terms_sets | U19-P1-04. Điều khoản tham gia Deal (B058.R10), required outside DRAFT. | |
code | text | NOT NULL | U19-P1-02 B006.R14 + PAF-P1-17 BR-C-13. Mã chiến dịch CD + ddmmyyyy (Vietnam date of the first save) + 4-digit number of that day (from 0001 each day, public.daily_code_counters scope campaign); written by trigger campaigns_code on insert (drafts too), unique, immutable, never reissued. | |
cloned_from_id | uuid | FK → campaigns | U19-P1-02 B006.R13. "Nhân bản từ": the source campaign; set once on insert, null once the source is deleted. | |
cloned_from_code | text | U19-P1-02 B006.R13 / GAP-W-CD-15. Code of the source campaign, copied on insert; kept when the source is deleted. | ||
delivery_start_month | date | U19-P1-05. Mua định kỳ: Kỳ bắt đầu giao (B208.R05), first day of the month; period k = this + (k-1) months. | ||
min_order_value_vnd | bigint | U19-P1-05. Mua định kỳ: Giá trị đơn tối thiểu per period in VND (B208.R09/B223.R05), checked when the buyer orders. | ||
legacy_cancelled | boolean | NOT NULL | U19-P1-06 GAP-W-CD-11. A campaign CANCELLED under the old machine: kept as DRAFT, hidden from the Admin list. | |
legacy_unvalidated | boolean | NOT NULL | U19-P1-06 GAP-W-CD-11. A pre-U19 row that cannot satisfy the U19 CHECKs (fields not derivable); exempted from them. | |
spin_wheel_id | uuid | FK → wheels | CV3-P1-07 BR-C-09. The lucky wheel the campaign chose; null = Không áp dụng (default). Configuration: locked from OPEN onwards by campaigns_guard (BR-C-11). Backfill DEC-CV3-06 (a). |
Khoá chính: id
Trỏ ra (5):
cloned_from_id→campaigns·ON DELETE SET NULLcreated_by→accounts·ON DELETE RESTRICTspin_wheel_id→wheels·ON DELETE RESTRICTterms_set_id→deal_terms_sets·ON DELETE RESTRICTupdated_by→accounts·ON DELETE RESTRICT
Được trỏ tới (23): affiliate_links, attribution_assignments, campaign_delivery_windows, campaign_outcomes, campaign_policy_versions, campaign_products, campaign_state_events, campaign_term_packages, campaigns, cancellation_decisions, content_versions, delivery_milestones, in_app_events, order_quotes, order_return_cases, orders, recurring_baskets, recurring_cycles, recurring_forfeit_reviews, shipments, spin_rule_versions, stock_shortage_cases, wheels
campaign_policy_versions
P2-06. Immutable-once-frozen policy/snapshot versions per campaign: deposit/cap/rate snapshots and close/skip/shortage rule status (UNDECIDED / INTERIM / APPROVED). OI-CP-09 and skip stay UNDECIDED.
public.campaign_policy_versions · 22 cột · 11 check · 2 unique · 3 index · 3 policy · 3 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 | |
version_no | integer | NOT NULL | ||
deposit_rate_bp | integer | |||
point_cap_bp | integer | |||
point_cap_policy_version | text | |||
point_rate_snapshot_vnd | numeric | |||
point_rate_policy_version | text | |||
close_rule_status | text | NOT NULL | ||
close_rule_code | text | |||
close_rule_ref | text | NOT NULL | ||
skip_rule_status | text | |||
skip_rule_ref | text | |||
skip_max_count | integer | |||
shortage_rule_status | text | NOT NULL | ||
shortage_rule_versions | text[] | NOT NULL | ||
frozen_at | timestamptz | |||
created_by | uuid | NOT NULL | FK → accounts | |
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
skip_rule_code | text | P2-18. Approved skip method code (evaluator key). NULL until DEC-CP-SKIP is decided; frozen with the version. |
Khoá chính: id
Trỏ ra (2):
campaign_id, campaign_type→campaigns·ON DELETE CASCADEcreated_by→accounts·ON DELETE RESTRICT
Được trỏ tới (13): campaign_outcomes, campaign_state_events, order_close_outcomes, order_cycles, order_periods, order_quotes, order_state_events, orders, price_tiers, recurring_baskets, recurring_skip_requests, refund_cases, stock_shortage_case_orders
campaign_outcomes
P2-15. Immutable Group Buy close outcome (one per campaign): per-product committed quantity, MOQ, tier and final unit price under the frozen policy version; written with CLOSING -> CONFIRMED|FAILED.
public.campaign_outcomes · 17 cột · 5 check · 2 unique · 3 index · 1 policy · 3 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
campaign_id | uuid | NOT NULL | FK → campaign_policy_versions | |
campaign_type | text | NOT NULL | FK → campaigns | |
closing_version | integer | NOT NULL | ||
outcome_version | integer | NOT NULL | ||
outcome | text | NOT NULL | ||
policy_version_id | uuid | NOT NULL | FK → campaign_policy_versions | |
close_rule_code | text | NOT NULL | ||
close_rule_ref | text | NOT NULL | ||
closes_at | timestamptz | NOT NULL | ||
product_results | jsonb | NOT NULL | ||
counted_orders | integer | NOT NULL | ||
excluded_orders | integer | NOT NULL | ||
run_id | uuid | NOT NULL | ||
computed_at | timestamptz | NOT NULL | ||
close_rule_version | text | P2-16. Evaluator version of a Recurring close (NULL for Group Buy). | ||
closes_at_vn | date | P2-16. Vietnam calendar date (UTC+07:00) of closes_at; generated. |
Khoá chính: id
Trỏ ra (2):
campaign_id, campaign_type→campaigns·ON DELETE RESTRICTpolicy_version_id, campaign_id→campaign_policy_versions·ON DELETE RESTRICT
Được trỏ tới (6): campaign_product_outcomes, order_close_outcomes, order_cycle_close_values, order_period_final_prices, order_points_excess_refunds, point_reward_partial_cancels
campaign_products
P2-06. Catalog products of a campaign with their own MOQ; SKU/name snapshot once finished (SP-US-03).
public.campaign_products · 20 cột · 8 check · 3 unique · 5 index · 4 policy · 6 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 | |
product_id | uuid | NOT NULL | FK → products | |
moq_qty | integer | |||
sku_snapshot | text | |||
name_snapshot | text | |||
snapshot_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 | ||
position | integer | NOT NULL | U19-P1-04. Display order 1..n (B006.R15); 1 = featured on the App home (BR-C-14). Unique per campaign, deferred. | |
listed_price_vnd | bigint | U19-P1-04. Giá niêm yết (B061.R03), VND > 0; the App strikes it through and computes the saving. | ||
tag | text | U19-P1-04. Tag sản phẩm (B061.R06, BR-C-16): <= 50 characters (char_length), emoji allowed; NULL = none. | ||
virtual_mode | text | NOT NULL | U19-P1-04. Số lượng ảo (B006.R05, B061.R05): NONE | FIXED | DAILY; read through campaign.virtual_qty(). | |
virtual_fixed_qty | integer | |||
virtual_daily_qty | integer | |||
virtual_max_qty | integer | |||
virtual_qty_at_close | integer | U19-P1-04. Virtual quantity frozen when registration closes (set once while CLOSING, U19-P2-06). |
Khoá chính: id
Trỏ ra (4):
campaign_id, campaign_type→campaigns·ON DELETE CASCADEcreated_by→accounts·ON DELETE RESTRICTproduct_id→products·ON DELETE RESTRICTupdated_by→accounts·ON DELETE RESTRICT
Được trỏ tới (6): affiliate_links, campaign_product_outcomes, order_lines, price_tiers, recurring_basket_lines, stock_shortage_cases
campaign_delivery_windows
U19-P1-05 / CV3-P1-01. Mua định kỳ: Khung ngày giao trong tháng (BR-DK-04): day 1..28 on the row; a DRAFT may hold an empty day, Đến < Từ or overlapping windows (BR-TC-07); outside DRAFT campaign_recurring_children_check and campaign.assert_ready require complete windows, Đến >= Từ, no overlap.
public.campaign_delivery_windows · 9 cột · 3 check · 0 unique · 1 index · 4 policy · 4 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
campaign_id | uuid | NOT NULL | PK FK → campaigns | |
campaign_type | text | NOT NULL | FK → campaigns | |
window_no | integer | NOT NULL | PK | |
from_day | integer | |||
to_day | integer | |||
created_by | uuid | NOT NULL | FK → accounts | |
updated_by | uuid | NOT NULL | FK → accounts | |
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
Khoá chính: campaign_id, window_no
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 (3): order_quotes, orders, recurring_baskets
campaign_term_packages
U19-P1-05 / CV3-P1-01. Mua định kỳ: Gói kỳ cam kết (BR-DK-05): Số kỳ 1..12, Được bỏ qua >= 0, label <= 50 on the row; a DRAFT may hold an empty Số kỳ, a repeated Số kỳ or Được bỏ qua >= Số kỳ (BR-TC-07); outside DRAFT campaign_recurring_children_check and campaign.assert_ready require Số kỳ unique and Được bỏ qua < Số kỳ.
public.campaign_term_packages · 11 cột · 6 check · 1 unique · 2 index · 4 policy · 4 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
campaign_id | uuid | NOT NULL | PK FK → campaigns | |
campaign_type | text | NOT NULL | FK → campaigns | |
package_no | integer | NOT NULL | PK | |
term_cycles | integer | |||
reward_value | integer | |||
skip_max | integer | |||
label | text | |||
created_by | uuid | NOT NULL | FK → accounts | |
updated_by | uuid | NOT NULL | FK → accounts | |
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL |
Khoá chính: campaign_id, package_no
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 (3): order_quotes, orders, recurring_baskets
campaign_point_config_versions
P2-10. Versioned global PiPoint cap (A-CFG-02) / VND-per-point rate (A-CFG-03): maker proposes, a different checker approves; approved rows immutable; campaigns snapshot the effective version.
public.campaign_point_config_versions · 17 cột · 8 check · 1 unique · 4 index · 4 policy · 5 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
config_key | text | NOT NULL | ||
version_no | integer | NOT NULL | ||
cap_bp | integer | |||
rate_vnd | numeric | |||
effective_at | timestamptz | NOT NULL | ||
reason | text | NOT NULL | ||
status | text | NOT NULL | ||
proposed_by | uuid | NOT NULL | FK → accounts | |
decided_by | uuid | FK → accounts | ||
decided_at | timestamptz | |||
effective_from | timestamptz | |||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
version | integer | NOT NULL | ||
decision_ref | text | |||
reward_policy | jsonb |
Khoá chính: id
Trỏ ra (2):
decided_by→accounts·ON DELETE RESTRICTproposed_by→accounts·ON DELETE RESTRICT
Được trỏ tới: không có
campaign_product_outcomes
U19-P2-06. Immutable per-product Group close result (BR-C-04/05/06): real, virtual frozen at close, total, MOQ, met, final tier (Mốc N) and price, orders and the 100% deposit refund of a product that missed its MOQ.
public.campaign_product_outcomes · 14 cột · 3 check · 0 unique · 1 index · 1 policy · 2 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
campaign_id | uuid | NOT NULL | PK FK → campaign_outcomes | |
campaign_product_id | uuid | NOT NULL | PK FK → campaign_products | |
outcome_id | uuid | NOT NULL | FK → campaign_outcomes | |
real_qty | bigint | NOT NULL | ||
virtual_qty | integer | NOT NULL | ||
total_qty | bigint | NOT NULL | ||
moq_qty | integer | NOT NULL | ||
met | boolean | NOT NULL | ||
final_tier_no | integer | |||
final_unit_price_vnd | bigint | |||
order_count | integer | NOT NULL | ||
refund_order_count | integer | NOT NULL | ||
refund_vnd | bigint | NOT NULL | ||
computed_at | timestamptz | NOT NULL |
Khoá chính: campaign_id, campaign_product_id
Trỏ ra (2):
campaign_product_id→campaign_products·ON DELETE RESTRICToutcome_id, campaign_id→campaign_outcomes·ON DELETE RESTRICT
Được trỏ tới: không có
campaign_state_events
P2-06. Append-only campaign history: one row per campaign version (actor/source/reason/policy version).
public.campaign_state_events · 13 cột · 4 check · 2 unique · 5 index · 1 policy · 2 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
campaign_id | uuid | NOT NULL | FK → campaigns | |
campaign_version | integer | NOT NULL | ||
event_type | text | NOT NULL | ||
from_state | text | |||
to_state | text | NOT NULL | ||
policy_version_id | uuid | 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 | ||
changes | jsonb |
Khoá chính: id
Trỏ ra (3):
actor_account_id→accounts·ON DELETE RESTRICTcampaign_id→campaigns·ON DELETE CASCADEpolicy_version_id→campaign_policy_versions·ON DELETE CASCADE
Được trỏ tới: không có
campaign_write_throttles
CV3-P4-01 (DEC-CV3-18). SYSTEM_ONLY call counter of the campaign writes saveCampaignDraft / createCampaign / updateCampaign / saveRecurringCampaignDraft per Web Admin account (fixed window). Written only by campaign.write_throttle_begin (pi_api, definer); rows a day past their window are purged by it. No payload, no PII.
public.campaign_write_throttles · 4 cột · 1 check · 0 unique · 2 index · 0 policy · 0 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
account_id | uuid | NOT NULL | PK | |
call_count | integer | NOT NULL | ||
window_started_at | timestamptz | NOT NULL | ||
last_call_at | timestamptz | NOT NULL |
Khoá chính: account_id
Trỏ ra: không có
Được trỏ tới: không có