Skip to content

customer / customer ​

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 customer.

customer_groups ​

P2-04. Customer classification labels (not tied to price/deposit/points yet, Rule #3). Exactly one live default; soft delete only after members moved to the default; never hard-deleted. Code/name keys (trim + NFC + lower) unique among live groups only (U6-P2-24, X-02 / Rule #8, #9).

public.customer_groups · 14 cột · 5 check · 0 unique · 4 index · 3 policy · 6 trigger · RLS bật

CộtKiểuKhoáMô tả
iduuidNOT NULLPK
codetextNOT NULL
code_keytext
nametextNOT NULL
name_keytext
descriptiontext
is_defaultbooleanNOT NULL
created_byuuidFK → accountsAccount that created the group; NULL only for the migration seed (U6-P7-67, Q-9 MAC_DINH).
updated_byuuidFK → accountsAccount of the last write; NULL only for the migration seed row until its first edit (U6-P7-67).
deleted_attimestamptz
deleted_byuuidFK → accounts
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
versionintegerNOT NULL

Khoá chính: id

Trỏ ra (3):

  • created_by → accounts · ON DELETE RESTRICT
  • deleted_by → accounts · ON DELETE RESTRICT
  • updated_by → accounts · ON DELETE RESTRICT

Được trỏ tới (1): customer_group_memberships

customer_codes ​

U6-P2-23 / U6-P7-61. One immutable system customer code per customer (Rule #13, Q-3: KH + ddmmyyyy + 6-digit counter). Issued by customer.assign_code(): trigger on app_memberships (APP_USER) for new customers, backfill for existing ones. Read only through customer.directory().

public.customer_codes · 4 cột · 2 check · 1 unique · 2 index · 0 policy · 3 trigger · RLS bật

CộtKiểuKhoáMô tả
account_iduuidNOT NULLPK FK → app_memberships
appapp_codeNOT NULLFK → app_memberships
codetextNOT NULL
issued_attimestamptzNOT NULL

Khoá chính: account_id

Trỏ ra (1):

  • account_id, app → app_memberships · ON DELETE RESTRICT

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

customer_column_preferences ​

U6-P2-23 KH-US-01 AC16-AC20. Customer-list columns of one Admin (canonical CustomerColumn codes, fixed order, CODE/NAME/PHONE always present); own row only, last write wins. No row = customer.default_columns().

public.customer_column_preferences · 6 cột · 3 check · 0 unique · 1 index · 3 policy · 2 trigger · RLS bật

CộtKiểuKhoáMô tả
account_iduuidNOT NULLPK FK → app_memberships
appapp_codeNOT NULLFK → app_memberships
columnstext[]NOT NULL
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
versionintegerNOT NULL

Khoá chính: account_id

Trỏ ra (1):

  • account_id, app → app_memberships · ON DELETE RESTRICT

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

customer_group_memberships ​

P2-04. Customer group history: one open row per customer (none = current default group). Close-once, never deleted. OWN_OR_SCOPE sketch; TEAM has no row source yet, so only customer.* readers see rows.

public.customer_group_memberships · 10 cột · 4 check · 0 unique · 4 index · 3 policy · 6 trigger · RLS bật

CộtKiểuKhoáMô tả
iduuidNOT NULLPK
account_iduuidNOT NULLFK → app_memberships
appapp_codeNOT NULLFK → app_memberships
group_iduuidNOT NULLFK → customer_groups
reasontextNOT NULL
valid_fromtimestamptzNOT NULL
valid_totimestamptz
opened_byuuidNOT NULLFK → accounts
closed_byuuidFK → accounts
correlation_idcorrelation_refNOT NULL

Khoá chính: id

Trỏ ra (4):

  • closed_by → accounts · ON DELETE RESTRICT
  • account_id, app → app_memberships · ON DELETE RESTRICT
  • group_id → customer_groups · ON DELETE RESTRICT
  • opened_by → accounts · ON DELETE RESTRICT

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

customer_profiles ​

P2-04. Admin-managed customer fields (description, tags) and the customer aggregate version. No identity/PII column. Created lazily on the first Admin write.

public.customer_profiles · 8 cột · 4 check · 0 unique · 1 index · 3 policy · 4 trigger · RLS bật

CộtKiểuKhoáMô tả
account_iduuidNOT NULLPK FK → app_memberships
appapp_codeNOT NULLFK → app_memberships
descriptiontext
tagstext[]NOT NULL
updated_byuuidNOT NULLFK → accounts
created_attimestamptzNOT NULL
updated_attimestamptzNOT NULL
versionintegerNOT NULL

Khoá chính: account_id

Trỏ ra (2):

  • account_id, app → app_memberships · ON DELETE RESTRICT
  • updated_by → accounts · ON DELETE RESTRICT

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

Sinh từ ad83b0aea · 820 migration · PostgreSQL 17