Skip to main content

Sync Tables

historical_sync_jobs

Tracks historical call data import jobs. Each job fetches past calls from Ultravox for a specified date range and imports them into the calls table.

ColumnTypeDefaultNullableDescription
iduuiduuid_generate_v4()noPrimary key
agency_iduuidnoFK → agencies.id
date_fromtimestamptzyesStart of date range (null = beginning of time)
date_totimestamptznoEnd of date range
statussync_job_status'pending'noJob status
total_callsintegeryesTotal calls found in Ultravox
processed_callsinteger0noCalls processed so far
imported_callsinteger0noCalls successfully imported
skipped_callsinteger0noCalls skipped (already exist)
failed_callsinteger0noCalls that failed to import
cursortextyesPagination cursor for resuming
error_messagetextyesLast error message
last_error_attimestamptzyesWhen the last error occurred
max_callsinteger100yesMaximum calls to import per job
created_attimestamptznow()noRecord creation timestamp
started_attimestamptzyesWhen processing began
completed_attimestamptzyesWhen processing finished
last_activity_attimestamptzyesLast processing activity timestamp

Constraints:

ConstraintTypeDetails
historical_sync_jobs_pkeyPrimary keyid
historical_sync_jobs_agency_id_fkeyForeign keyagency_idagencies(id) ON DELETE CASCADE
sync_jobs_counts_positiveCheckprocessed_calls >= 0 AND imported_calls >= 0 AND skipped_calls >= 0 AND failed_calls >= 0
sync_jobs_date_rangeCheckdate_from IS NULL OR date_from < date_to

Indexes:

IndexColumnsNotes
idx_sync_jobs_agencyagency_idAgency-scoped queries
idx_sync_jobs_statusstatusFilter by status
idx_sync_jobs_active(agency_id, status)Filtered: WHERE status IN ('pending', 'in_progress') — active jobs
idx_sync_jobs_createdcreated_at DESCChronological listing

Related edge functions: start-historical-sync, process-historical-sync, cancel-historical-sync, get-sync-status


cron_job_logs

Audit log for cron job executions. Each row represents one execution of a scheduled job.

ColumnTypeDefaultNullableDescription
iduuidgen_random_uuid()noPrimary key
job_nametextnoName of the cron job
started_attimestamptznow()yesWhen execution started
completed_attimestamptzyesWhen execution finished
statustext'running'yesExecution status (e.g., running, completed, failed)
resultjsonbyesExecution result data
error_messagetextyesError message if failed
created_attimestamptznow()yesRecord creation timestamp

Constraints:

ConstraintTypeDetails
cron_job_logs_pkeyPrimary keyid

Indexes:

IndexColumns
idx_cron_job_logs_job_namejob_name
idx_cron_job_logs_started_atstarted_at DESC

Related views: virsyn_cron_jobs shows the currently active cron job definitions.