Skip to content

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ộtKiểuKhoáMô tả
iduuidNOT NULLPK
campaign_typetextNOT NULL
nametext
descriptiontext
opens_attimestamptz
closes_attimestamptz
term_optionsinteger[]
statetextNOT NULL
state_changed_attimestamptzNOT NULL
created_byuuidNOT NULLFK → accounts
updated_byuuidFK → accounts
change_sourcetextNOT NULL
change_source_idtextNOT NULL
change_reasontext
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
versionintegerNOT NULL
publish_attimestamptzU19-P1-01. Thời gian công bố (B006.R04): PENDING_PUBLISH -> UPCOMING at this time; immutable once UPCOMING.
published_attimestamptzU19-P1-01. When the campaign entered UPCOMING (trigger-written).
opened_attimestamptzU19-P1-01. When the campaign entered OPEN (trigger-written).
closed_attimestamptzU19-P1-01. When the campaign entered CLOSING (trigger-written).
reward_unittextU19-P1-04. Đơn vị Pi-Point thưởng (B058.R09/B214.R08): PERCENT_ORDER (bp of the order value) | POINTS_PER_ORDER.
point_cap_bpintegerU19-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_bonusintegerU19-P1-04 / PAF-P1-08. Mua chung: Thưởng thanh toán online (B064.R08), whole number in reward_unit; NULL = none.
prepay_all_bonusintegerU19-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_iduuidFK → deal_terms_setsU19-P1-04. Điều khoản tham gia Deal (B058.R10), required outside DRAFT.
codetextNOT NULLU19-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_iduuidFK → campaignsU19-P1-02 B006.R13. "Nhân bản từ": the source campaign; set once on insert, null once the source is deleted.
cloned_from_codetextU19-P1-02 B006.R13 / GAP-W-CD-15. Code of the source campaign, copied on insert; kept when the source is deleted.
delivery_start_monthdateU19-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_vndbigintU19-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_cancelledbooleanNOT NULLU19-P1-06 GAP-W-CD-11. A campaign CANCELLED under the old machine: kept as DRAFT, hidden from the Admin list.
legacy_unvalidatedbooleanNOT NULLU19-P1-06 GAP-W-CD-11. A pre-U19 row that cannot satisfy the U19 CHECKs (fields not derivable); exempted from them.
spin_wheel_iduuidFK → wheelsCV3-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 NULL
  • created_by → accounts · ON DELETE RESTRICT
  • spin_wheel_id → wheels · ON DELETE RESTRICT
  • terms_set_id → deal_terms_sets · ON DELETE RESTRICT
  • updated_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ộtKiểuKhoáMô tả
iduuidNOT NULLPK
campaign_iduuidNOT NULLFK → campaigns
campaign_typetextNOT NULLFK → campaigns
version_nointegerNOT NULL
deposit_rate_bpinteger
point_cap_bpinteger
point_cap_policy_versiontext
point_rate_snapshot_vndnumeric
point_rate_policy_versiontext
close_rule_statustextNOT NULL
close_rule_codetext
close_rule_reftextNOT NULL
skip_rule_statustext
skip_rule_reftext
skip_max_countinteger
shortage_rule_statustextNOT NULL
shortage_rule_versionstext[]NOT NULL
frozen_attimestamptz
created_byuuidNOT NULLFK → accounts
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
skip_rule_codetextP2-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 CASCADE
  • created_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ộtKiểuKhoáMô tả
iduuidNOT NULLPK
campaign_iduuidNOT NULLFK → campaign_policy_versions
campaign_typetextNOT NULLFK → campaigns
closing_versionintegerNOT NULL
outcome_versionintegerNOT NULL
outcometextNOT NULL
policy_version_iduuidNOT NULLFK → campaign_policy_versions
close_rule_codetextNOT NULL
close_rule_reftextNOT NULL
closes_attimestamptzNOT NULL
product_resultsjsonbNOT NULL
counted_ordersintegerNOT NULL
excluded_ordersintegerNOT NULL
run_iduuidNOT NULL
computed_attimestamptzNOT NULL
close_rule_versiontextP2-16. Evaluator version of a Recurring close (NULL for Group Buy).
closes_at_vndateP2-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 RESTRICT
  • policy_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ộtKiểuKhoáMô tả
iduuidNOT NULLPK
campaign_iduuidNOT NULLFK → campaigns
campaign_typetextNOT NULLFK → campaigns
product_iduuidNOT NULLFK → products
moq_qtyinteger
sku_snapshottext
name_snapshottext
snapshot_attimestamptz
created_byuuidNOT NULLFK → accounts
updated_byuuidNOT NULLFK → accounts
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
positionintegerNOT NULLU19-P1-04. Display order 1..n (B006.R15); 1 = featured on the App home (BR-C-14). Unique per campaign, deferred.
listed_price_vndbigintU19-P1-04. Giá niêm yết (B061.R03), VND > 0; the App strikes it through and computes the saving.
tagtextU19-P1-04. Tag sản phẩm (B061.R06, BR-C-16): <= 50 characters (char_length), emoji allowed; NULL = none.
virtual_modetextNOT NULLU19-P1-04. Số lượng ảo (B006.R05, B061.R05): NONE | FIXED | DAILY; read through campaign.virtual_qty().
virtual_fixed_qtyinteger
virtual_daily_qtyinteger
virtual_max_qtyinteger
virtual_qty_at_closeintegerU19-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 CASCADE
  • created_by → accounts · ON DELETE RESTRICT
  • product_id → products · ON DELETE RESTRICT
  • updated_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ộtKiểuKhoáMô tả
campaign_iduuidNOT NULLPK FK → campaigns
campaign_typetextNOT NULLFK → campaigns
window_nointegerNOT NULLPK
from_dayinteger
to_dayinteger
created_byuuidNOT NULLFK → accounts
updated_byuuidNOT NULLFK → accounts
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

Khoá chính: campaign_id, window_no

Trỏ ra (3):

  • campaign_id, campaign_type → campaigns · ON DELETE CASCADE
  • created_by → accounts · ON DELETE RESTRICT
  • updated_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ộtKiểuKhoáMô tả
campaign_iduuidNOT NULLPK FK → campaigns
campaign_typetextNOT NULLFK → campaigns
package_nointegerNOT NULLPK
term_cyclesinteger
reward_valueinteger
skip_maxinteger
labeltext
created_byuuidNOT NULLFK → accounts
updated_byuuidNOT NULLFK → accounts
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL

Khoá chính: campaign_id, package_no

Trỏ ra (3):

  • campaign_id, campaign_type → campaigns · ON DELETE CASCADE
  • created_by → accounts · ON DELETE RESTRICT
  • updated_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ộtKiểuKhoáMô tả
iduuidNOT NULLPK
config_keytextNOT NULL
version_nointegerNOT NULL
cap_bpinteger
rate_vndnumeric
effective_attimestamptzNOT NULL
reasontextNOT NULL
statustextNOT NULL
proposed_byuuidNOT NULLFK → accounts
decided_byuuidFK → accounts
decided_attimestamptz
effective_fromtimestamptz
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
versionintegerNOT NULL
decision_reftext
reward_policyjsonb

Khoá chính: id

Trỏ ra (2):

  • decided_by → accounts · ON DELETE RESTRICT
  • proposed_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ộtKiểuKhoáMô tả
campaign_iduuidNOT NULLPK FK → campaign_outcomes
campaign_product_iduuidNOT NULLPK FK → campaign_products
outcome_iduuidNOT NULLFK → campaign_outcomes
real_qtybigintNOT NULL
virtual_qtyintegerNOT NULL
total_qtybigintNOT NULL
moq_qtyintegerNOT NULL
metbooleanNOT NULL
final_tier_nointeger
final_unit_price_vndbigint
order_countintegerNOT NULL
refund_order_countintegerNOT NULL
refund_vndbigintNOT NULL
computed_attimestamptzNOT NULL

Khoá chính: campaign_id, campaign_product_id

Trỏ ra (2):

  • campaign_product_id → campaign_products · ON DELETE RESTRICT
  • outcome_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ộtKiểuKhoáMô tả
iduuidNOT NULLPK
campaign_iduuidNOT NULLFK → campaigns
campaign_versionintegerNOT NULL
event_typetextNOT NULL
from_statetext
to_statetextNOT NULL
policy_version_iduuidFK → campaign_policy_versions
sourcetextNOT NULL
source_event_idtextNOT NULL
actor_account_iduuidFK → accounts
reasontext
recorded_attimestamptzNOT NULL
changesjsonb

Khoá chính: id

Trỏ ra (3):

  • actor_account_id → accounts · ON DELETE RESTRICT
  • campaign_id → campaigns · ON DELETE CASCADE
  • policy_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ộtKiểuKhoáMô tả
account_iduuidNOT NULLPK
call_countintegerNOT NULL
window_started_attimestamptzNOT NULL
last_call_attimestamptzNOT NULL

Khoá chính: account_id

Trỏ ra: không có

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

Sinh từ ad83b0aea · 820 migration · PostgreSQL 17