Giao diện
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ột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
code | text | NOT NULL | ||
code_key | text | |||
name | text | NOT NULL | ||
name_key | text | |||
description | text | |||
is_default | boolean | NOT NULL | ||
created_by | uuid | FK → accounts | Account that created the group; NULL only for the migration seed (U6-P7-67, Q-9 MAC_DINH). | |
updated_by | uuid | FK → accounts | Account of the last write; NULL only for the migration seed row until its first edit (U6-P7-67). | |
deleted_at | timestamptz | |||
deleted_by | uuid | FK → accounts | ||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
version | integer | NOT NULL |
Khoá chính: id
Trỏ ra (3):
created_by→accounts·ON DELETE RESTRICTdeleted_by→accounts·ON DELETE RESTRICTupdated_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ột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
account_id | uuid | NOT NULL | PK FK → app_memberships | |
app | app_code | NOT NULL | FK → app_memberships | |
code | text | NOT NULL | ||
issued_at | timestamptz | NOT 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ột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
account_id | uuid | NOT NULL | PK FK → app_memberships | |
app | app_code | NOT NULL | FK → app_memberships | |
columns | text[] | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
version | integer | NOT 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ột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
account_id | uuid | NOT NULL | FK → app_memberships | |
app | app_code | NOT NULL | FK → app_memberships | |
group_id | uuid | NOT NULL | FK → customer_groups | |
reason | text | NOT NULL | ||
valid_from | timestamptz | NOT NULL | ||
valid_to | timestamptz | |||
opened_by | uuid | NOT NULL | FK → accounts | |
closed_by | uuid | FK → accounts | ||
correlation_id | correlation_ref | NOT NULL |
Khoá chính: id
Trỏ ra (4):
closed_by→accounts·ON DELETE RESTRICTaccount_id, app→app_memberships·ON DELETE RESTRICTgroup_id→customer_groups·ON DELETE RESTRICTopened_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ột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
account_id | uuid | NOT NULL | PK FK → app_memberships | |
app | app_code | NOT NULL | FK → app_memberships | |
description | text | |||
tags | text[] | NOT NULL | ||
updated_by | uuid | NOT NULL | FK → accounts | |
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
version | integer | NOT NULL |
Khoá chính: account_id
Trỏ ra (2):
account_id, app→app_memberships·ON DELETE RESTRICTupdated_by→accounts·ON DELETE RESTRICT
Được trỏ tới: không có