Skip to content

public.entitlements

Synced from docs/generated/erd/ — do not hand-edit.
Regenerate with bun run docs:erd (needs staging reader), then this script runs automatically.
Labels: docs/db/erd-table-labels.yml · Runbook: docs/runbooks/erd-schema-docs.md

Legacy / sponsorship-fulfilment entitlement rows (not the platform commerce ledger) — Not: commerce_entitlements (ADR 2581 explicitly distinguishes these) — See: docs/decisions/2581-modules-vs-entitlements-vs-rls.md

Name Type Default Nullable Children Parents Comment
allocated_quantity integer 0 false
benefit_definition_id uuid false public.benefit_definitions
company_id uuid false companies
created_at timestamp with time zone now() false
expires_at date true
id uuid gen_random_uuid() false public.benefit_reservations public.benefit_usage
membership_unit_id uuid true membership_units
org_id text ‘’::text false organizations
reserved_quantity integer 0 false
sponsor_subscription_id uuid false sponsorships
start_date date CURRENT_DATE false
status text ‘active’::text false
updated_at timestamp with time zone now() false
used_quantity integer 0 false
Name Definition
Membership & Billing Members split-payload (members + member_profiles + member_billing + member_metrics),
tiers, commerce/billable offers, billing agreements/subscriptions/transactions.
Catalog §2.1–2.2, 2.4. Strong first-review cluster for Nathan/Craig.
NAMING TRAP — “entitlement” is three different concepts (see docs/db/erd-table-labels.yml):
commerce_entitlements = plan/agreement commercial limits;
member_entitlements = chamber member benefit allocations;
member_product_entitlements = external product provisioning (e.g. Bullseye).
The bare entitlements table is NOT the commerce ledger (ADR #2581).
Name Type Definition
entitlements_benefit_definition_id_fkey FOREIGN KEY FOREIGN KEY (benefit_definition_id) REFERENCES benefit_definitions(id) ON DELETE RESTRICT
entitlements_company_id_fkey FOREIGN KEY FOREIGN KEY (company_id) REFERENCES companies(id) ON DELETE CASCADE
entitlements_membership_unit_id_fkey FOREIGN KEY FOREIGN KEY (membership_unit_id) REFERENCES membership_units(id) ON DELETE SET NULL
entitlements_pkey PRIMARY KEY PRIMARY KEY (id)
entitlements_sponsor_subscription_id_fkey FOREIGN KEY FOREIGN KEY (sponsor_subscription_id) REFERENCES sponsorships(id) ON DELETE CASCADE
fk_entitlements_org FOREIGN KEY FOREIGN KEY (org_id) REFERENCES organizations(id)
Name Definition
entitlements_pkey CREATE UNIQUE INDEX entitlements_pkey ON public.entitlements USING btree (id)
Name Definition
entitlements_updated_at CREATE TRIGGER entitlements_updated_at BEFORE UPDATE ON public.entitlements FOR EACH ROW EXECUTE FUNCTION update_updated_at_column()
erDiagram

"public.entitlements" }o--|| "public.benefit_definitions" : "FOREIGN KEY (benefit_definition_id) REFERENCES benefit_definitions(id) ON DELETE RESTRICT"
"public.entitlements" }o--|| "public.companies" : "FOREIGN KEY (company_id) REFERENCES companies(id) ON DELETE CASCADE"
"public.benefit_reservations" }o--|| "public.entitlements" : "FOREIGN KEY (entitlement_id) REFERENCES entitlements(id) ON DELETE CASCADE"
"public.benefit_usage" }o--|| "public.entitlements" : "FOREIGN KEY (entitlement_id) REFERENCES entitlements(id) ON DELETE CASCADE"
"public.entitlements" }o--o| "public.membership_units" : "FOREIGN KEY (membership_unit_id) REFERENCES membership_units(id) ON DELETE SET NULL"
"public.entitlements" }o--|| "public.organizations" : "FOREIGN KEY (org_id) REFERENCES organizations(id)"
"public.entitlements" }o--|| "public.sponsorships" : "FOREIGN KEY (sponsor_subscription_id) REFERENCES sponsorships(id) ON DELETE CASCADE"

"public.entitlements" {
  uuid benefit_definition_id FK ""
  uuid company_id FK ""
  uuid id ""
  uuid membership_unit_id FK ""
  text org_id FK ""
  uuid sponsor_subscription_id FK ""
}
"public.benefit_definitions" {
  uuid id ""
  text org_id FK ""
}
"public.companies" {
  uuid id ""
  text org_id FK ""
  uuid primary_contact_id FK ""
}
"public.benefit_reservations" {
  uuid entitlement_id FK ""
  uuid id ""
  text org_id FK ""
}
"public.benefit_usage" {
  uuid entitlement_id FK ""
  text org_id FK ""
  uuid reservation_id FK ""
}
"public.membership_units" {
  uuid company_id FK ""
  uuid id ""
  text org_id FK ""
  uuid owner_member_id FK ""
}
"public.organizations" {
  text association_id FK ""
  uuid default_approval_reviewer_contact_id FK "Org-level fallback reviewer for two-step send (#5698). Routing chain: the sender's own reviewer, then this, then all org admins. NULL means fall through to the admins, which is the pre-#5698 behaviour."
  text id ""
  text parent_org_id FK "#671 self-referencing hierarchy pointer. NULL = root org. Direct writes are blocked by trg_block_direct_parent_org_id_writes for every role except service_role/postgres/supabase_admin — the only write path for authenticated/interactive callers is public.reparent_organization(). Cycle-prevented by trg_prevent_org_hierarchy_cycle. #quot;Is association#quot; is derived (EXISTS a child), never stored."
}
"public.sponsorships" {
  uuid company_id FK ""
  uuid event_id FK "#3542: set for an event-scoped sponsorship; NULL for an org-level one."
  uuid id ""
  uuid member_id FK ""
  uuid membership_unit_id FK ""
  uuid offering_id FK "#3542: FK to sponsorship_offerings (renamed from tier_id)."
  text org_id FK ""
  uuid signature_event_id FK ""
  uuid subscription_id FK ""
}

Generated by tbls