Skip to main content
Version: v1.0.0(int)

Customers

Sales-side parties. Carries the rich model: classification (type + segment), default broker, hierarchy (parent customer), country, QBO sync. Auxiliary tables in this cluster (customer_types, customer_segments, brokers) only exist for customers — they're not shared with vendors, which carry a deliberately flatter shape.

ER diagram

org.customers

ColumnTypeNotes
idUUID PK
org_idUUID FKplatform.organizations(id).
nameVARCHAR
customer_type_idUUID FKorg.customer_types(id) ON DELETE RESTRICT. NOT NULL.
customer_segment_idUUID FKorg.customer_segments(id) ON DELETE SET NULL.
broker_idUUID FKorg.brokers(id) ON DELETE SET NULL. Default broker — overridable per SO.
broker_fee_percentNUMERICCHECK 0..100. Default broker fee for this customer.
addressTEXT
cityVARCHAR(150)
stateVARCHAR(100)
countryCHAR(2)ISO 3166-1 alpha-2.
zip_codeVARCHAR(20)
parent_customer_idUUID FKorg.customers(id) ON DELETE SET NULL. Hierarchy — see Hierarchy rules.
qbo_idVARCHAR(100)UNIQUE per (org_id, qbo_id). QBO sync identifier.
notesTEXTFree-form notes (nullable).
is_activeBOOLDefault true. Soft-delete.
created_atTIMESTAMPTZDefault NOW().
updated_atTIMESTAMPTZDefault NOW(). Auto-updated by trigger.

org.customer_types

Required taxonomic classification (e.g., Purchaser, Location, Customer). NOT NULL FK from customers.customer_type_id.

ColumnTypeNotes
idUUID PK
org_idUUID FKplatform.organizations(id).
nameVARCHAR(100)UNIQUE per (org_id, name).
sort_orderSMALLINTCHECK >= 0. UNIQUE per (org_id, sort_order)DEFERRABLE INITIALLY IMMEDIATE for reorders.
is_activeBOOLNOT NULL. Default true.
created_atTIMESTAMPTZNOT NULL. Default NOW().

org.customer_segments

Optional softer classification (e.g., Club, Distributor, Grocery). Nullable FK from customers.customer_segment_id.

ColumnTypeNotes
idUUID PK
org_idUUID FKplatform.organizations(id).
nameVARCHAR(100)UNIQUE per (org_id, name).
sort_orderSMALLINTCHECK >= 0. UNIQUE per (org_id, sort_order)DEFERRABLE INITIALLY IMMEDIATE for reorders.
is_activeBOOLNOT NULL. Default true.
created_atTIMESTAMPTZNOT NULL. Default NOW().

org.brokers

Third-party intermediaries who get a percentage commission on sales. Nullable FK from customers.broker_id. Also referenced from sales_orders.broker_id (per-SO override).

ColumnTypeNotes
idUUID PK
org_idUUID FKplatform.organizations(id).
nameVARCHAR(100)UNIQUE per (org_id, name).
sort_orderSMALLINTCHECK >= 0. UNIQUE per (org_id, sort_order)DEFERRABLE INITIALLY IMMEDIATE for reorders.
is_activeBOOLNOT NULL. Default true.
created_atTIMESTAMPTZNOT NULL. Default NOW().

Hierarchy rules

Application-enforced — not in the schema:

  • Purchaser customers cannot have a parent_customer_id.
  • Location and Customer types must have a parent_customer_id pointing at a Purchaser.

Cross-references

  • Used by sales orders — every SO has a customer_id (RESTRICT) and a broker_id + broker_fee_percent snapshot (overridable from the customer default).
  • Linked to contacts via entity_contacts.entity_type = 'customer'.