Skip to main content

Core Tables

agencies

Top-level tenant table. Every resource in the system is scoped to an agency.

ColumnTypeDefaultNullableDescription
iduuiduuid_generate_v4()noPrimary key
namevarchar(255)noAgency display name
slugvarchar(100)noURL-safe identifier (unique)
ultravox_api_key_encryptedbyteayesEncrypted Ultravox API key
ultravox_api_key_added_attimestamptzyesWhen the Ultravox key was stored
ultravox_api_key_validated_attimestamptzyesWhen the Ultravox key was last validated
telnyx_api_key_encryptedbyteayesEncrypted Telnyx API key
telnyx_public_key_encryptedbyteayesEncrypted Telnyx public key
telnyx_account_sid_encryptedbyteayesEncrypted Telnyx account SID
telnyx_api_key_added_attimestamptzyesWhen the Telnyx key was stored
telnyx_api_key_validated_attimestamptzyesWhen the Telnyx key was last validated
telnyx_application_idvarchar(255)yesTelnyx Call Control Application ID
telnyx_outbound_profile_idvarchar(255)yesTelnyx Outbound Voice Profile ID
telephony_configuredbooleanfalsenoWhether Telnyx provisioning is complete
webhook_secretvarchar(64)noAuto-generated secret for webhook URL auth
brandingjsonb'{}'yesCustom branding settings
settingsjsonb'{}'yesAgency-level configuration
created_attimestamptznow()noRecord creation timestamp
updated_attimestamptznow()noLast update timestamp (auto-updated)

Constraints:

ConstraintTypeDetails
agencies_pkeyPrimary keyid
agencies_slug_uniqueUniqueslug
agencies_name_not_emptyChecklength(trim(name)) > 0
agencies_slug_formatCheckslug ~ '^[a-z0-9-]+$' (lowercase alphanumeric and hyphens)

Indexes:

IndexColumnsNotes
idx_agencies_slugslugLookup by URL slug
idx_agencies_created_atcreated_atChronological listing

Triggers:

TriggerEventFunction
agency_set_webhook_secretBEFORE INSERTtrigger_agency_set_webhook_secret() — auto-generates webhook_secret
update_agencies_updated_atBEFORE UPDATEupdate_updated_at_column() — keeps updated_at current

Related edge functions: save-ultravox-integration, store-telnyx-credentials, provision-telephony, get-integration-status


users

Platform users linked to Supabase Auth. Each user has a role determining access level.

ColumnTypeDefaultNullableDescription
iduuidnoPrimary key (matches auth.users.id)
agency_iduuidyesFK → agencies.id (required for agency roles)
client_iduuidyesFK → clients.id (required for client roles)
roleuser_rolenoAccess level enum
emailvarchar(255)noUser email address
full_namevarchar(255)yesDisplay name
avatar_urltextyesProfile image URL
settingsjsonb'{}'yesUser preferences
is_activebooleantruenoSoft-delete flag
created_attimestamptznow()noRecord creation timestamp
updated_attimestamptznow()noLast update timestamp (auto-updated)
last_login_attimestamptzyesMost recent login timestamp

Constraints:

ConstraintTypeDetails
users_pkeyPrimary keyid
users_id_fkeyForeign keyidauth.users(id) ON DELETE CASCADE
users_agency_id_fkeyForeign keyagency_idagencies(id) ON DELETE CASCADE
users_client_id_fkeyForeign keyclient_idclients(id) ON DELETE CASCADE
users_email_not_emptyChecklength(trim(email)) > 0
users_agency_user_has_agencyCheckAgency roles (agency_owner, agency_member) must have agency_id
users_agency_user_no_clientCheckAgency roles must not have client_id
users_client_user_has_clientCheckClient roles (client_admin, client_viewer) must have client_id
users_client_user_no_agencyCheckClient roles must not have agency_id

Indexes:

IndexColumns
idx_users_agency_idagency_id
idx_users_client_idclient_id
idx_users_emailemail
idx_users_rolerole
idx_users_activeis_active

Triggers:

TriggerEventFunction
update_users_updated_atBEFORE UPDATEupdate_updated_at_column()

clients

Client organizations within an agency. Clients can have campaigns and be associated with calls.

ColumnTypeDefaultNullableDescription
iduuiduuid_generate_v4()noPrimary key
agency_iduuidnoFK → agencies.id
namevarchar(255)noClient display name
settingsjsonb'{}'yesClient-level configuration
is_activebooleantruenoSoft-delete flag
created_attimestamptznow()noRecord creation timestamp
updated_attimestamptznow()noLast update timestamp (auto-updated)

Constraints:

ConstraintTypeDetails
clients_pkeyPrimary keyid
clients_agency_id_fkeyForeign keyagency_idagencies(id) ON DELETE CASCADE
clients_name_not_emptyChecklength(trim(name)) > 0

Indexes:

IndexColumnsNotes
idx_clients_agency_idagency_idAgency-scoped queries
idx_clients_agency_active(agency_id, is_active)Active clients per agency
idx_clients_created_atcreated_atChronological listing

Triggers:

TriggerEventFunction
update_clients_updated_atBEFORE UPDATEupdate_updated_at_column()

app_config

Global key-value configuration store. Not agency-scoped.

ColumnTypeDefaultNullableDescription
keytextnoPrimary key — configuration key name
valuetextnoConfiguration value
descriptiontextyesHuman-readable description of the setting
created_attimestamptznow()yesRecord creation timestamp
updated_attimestamptznow()yesLast update timestamp

Constraints:

ConstraintTypeDetails
app_config_pkeyPrimary keykey