is_primary, is_verify, label). It enables a company to hold multiple phone numbers while designating exactly one primary via a partial unique index. The entity is written exclusively by the connector sync pipeline and enrichment flows; there is no user-facing PATCH route, and company_phones does not appear in EDITABLE_FIELDS.
Internal object. Not currently exposed on the public REST API. The operations below describe the intended contract.
API operations
Data model
Attributes
Relationships
System-computed
- pk — auto-increment serial primary key (internal, never exposed via API)
- created_at — set by MikroORM onCreate hook to
new Date()on insert; no onUpdate hook (column does not change after creation) - deleted_at — null at creation; set to current timestamp by soft-delete logic in the pipeline or repository layer; never hard-deleted under normal operation
- No
updated_atcolumn on this entity (audit trail is creation + soft-delete only) - No
*_idUUID public identifier on CompanyPhone itself — the pivot is referenced via its parent Company and Phone IDs in the API; internal pk is used for joins only - Partial unique index
uniq_company_phones_primary_companyis enforced by the database engine on(company_pk) WHERE deleted_at IS NULL AND is_primary IS TRUE— only one active primary phone per company is permitted at the DB level - Composite index
idx_company_phones_company_deleted (company_pk, deleted_at)and reverse indexidx_company_phones_phone (phone_pk)are maintained automatically; added by Migration20260416100000 to cover the forward and reverse array-relationship traversal patterns identified via production Query Insights
Example
apps/api/src/database/entities/CompanyPhone.ts · domain: financial-graph · tier: Supporting