National Commerce Docs
Database

Shipping Audit Tool

Database tables for the standalone Shipping Audit Tool that compares a lead's shipments against provider rate cards and returns savings deliverables.

The audit_* tables power the Shipping Audit Tool. A lead submits an audit job, uploads a shipment file, the tool scores each row against provider shipping-cost rate cards, and it produces downloadable deliverables. This page documents every table and how they connect.

Separate product

These audit_* tables belong to the standalone Shipping Audit Tool, which runs at audit.nationalcommerce.com. It is a separate product from the main portal, so these tables do not reference Brands or accounts. All foreign keys stay within this page. See /docs/data-flows for where the audit tool fits in the wider system, and /docs/database for the full schema index.

audit_leads

A person who used the audit tool, identified by a unique validated email. total_audits_count starts at 1 and is bumped by a trigger each time the lead submits a job.

ColumnTypeNotes
iduuidPK, default gen_random_uuid()
emailtextNOT NULL, UNIQUE. CHECK: must match an email regex
referral_sourcetextWhere the lead came from
total_audits_countintegerNOT NULL, default 1. Incremented by trigger
last_tool_usetimestamptzNOT NULL, default now(). Updated by trigger
created_attimestamptzNOT NULL, default now()

A lead has many audit_jobs. When a job is inserted, trigger_update_lead_audit_count runs update_lead_audit_count(), which increments total_audits_count and refreshes last_tool_use. See /docs/database/automation.

audit_jobs

One audit run for a lead. It tracks processing state, row counts, and the computed savings summary. job_status is the enum audit_job_status and defaults to 'pending'. view_token is a token used to build a shareable results link.

ColumnTypeNotes
iduuidPK, default gen_random_uuid()
lead_iduuidNOT NULL. → references audit_leads
job_statusenum audit_job_statusUSER-DEFINED. NOT NULL, default 'pending'
view_tokenuuidNOT NULL, default gen_random_uuid(). Shareable-link token
workflow_iduuidExternal workflow run identifier
total_rowsintegerRows in the uploaded file
processed_rowsintegerNOT NULL, default 0
excluded_rowsintegerNOT NULL, default 0
column_mappingsjsonbHow upload columns map to expected fields
results_summaryjsonbSummarized audit results
ups_total_savingsnumericTotal UPS savings found
usps_total_savingsnumericTotal USPS savings found
ups_processed_shipmentsintegerDefault 0
usps_processed_shipmentsintegerDefault 0
error_messagetextSet when a run fails
submitted_at_formattedtextDisplay-formatted submit time
started_processing_attimestamptzWhen processing began
completed_attimestamptzWhen the run finished
email_sent_attimestamptzWhen the results email was sent
created_attimestamptzNOT NULL, default now()

A job belongs to one audit_leads (lead_id). It has many audit_uploads and many audit_deliverables. Its rows are scored against audit_provider_shipping_costs.

audit_uploads

Files uploaded for a job, stored in object storage at storage_path. upload_type is the enum upload_type and defaults to 'user_csv'.

ColumnTypeNotes
iduuidPK, default gen_random_uuid()
job_iduuidNOT NULL. → references audit_jobs
upload_typeenum upload_typeUSER-DEFINED. NOT NULL, default 'user_csv'
original_filenametextNOT NULL
storage_pathtextNOT NULL. Object storage location
file_size_bytesintegerNOT NULL
created_attimestamptzNOT NULL, default now()

An upload belongs to one audit_jobs (job_id).

audit_shipping_providers

A shipping carrier the tool compares against, such as UPS or USPS. Both name and short_code are unique and must be non-empty.

ColumnTypeNotes
iduuidPK, default gen_random_uuid()
nametextNOT NULL, UNIQUE. CHECK: trimmed length > 0
short_codetextNOT NULL, UNIQUE. CHECK: trimmed length > 0
descriptiontextProvider description
logo_urltextProvider logo
brand_colortextDefault '#2CA01C'
display_orderintegerDefault 0. Sort order in the UI
is_activebooleanNOT NULL, default true
is_defaultbooleanNOT NULL, default false
created_attimestamptzNOT NULL, default now()

A provider has many audit_provider_shipping_costs and may be referenced by many audit_deliverables.

audit_provider_shipping_costs

The rate card: the cost for a given (provider, weight, zone) as of effective_date. Audit jobs use these rows to price each shipment.

ColumnTypeNotes
iduuidPK, default gen_random_uuid()
provider_iduuidNOT NULL. → references audit_shipping_providers
weight_lbsnumericNOT NULL. CHECK: weight_lbs > 0
zoneintegerNOT NULL. CHECK: zone >= 1 AND zone <= 9
costnumericNOT NULL. CHECK: cost >= 0
effective_datedateNOT NULL. Date this rate applies from
created_attimestamptzNOT NULL, default now()

A cost row belongs to one audit_shipping_providers (provider_id).

audit_deliverables

Output files produced by a job, such as a report CSV or PDF, stored at storage_path. deliverable_type and file_type are Postgres enums. Downloads are tracked via download_count and the first/last download timestamps, bumped by increment_deliverable_download_count().

ColumnTypeNotes
iduuidPK, default gen_random_uuid()
job_iduuidNOT NULL. → references audit_jobs
provider_iduuidNullable. → references audit_shipping_providers
deliverable_typeenum deliverable_typeUSER-DEFINED. NOT NULL
file_typeenum file_typeUSER-DEFINED. Nullable
storage_pathtextNOT NULL. Object storage location
file_size_bytesintegerNOT NULL
download_countintegerNOT NULL, default 0
first_downloaded_attimestamptzSet on first download
last_downloaded_attimestamptzUpdated on each download
created_attimestamptzNOT NULL, default now()

A deliverable belongs to one audit_jobs (job_id) and may optionally reference one audit_shipping_providers (provider_id).

Enums and constraints

The USER-DEFINED columns above are Postgres enums (audit_job_status, upload_type, deliverable_type, file_type). Insert only valid enum values. CHECK constraints also enforce a valid email on audit_leads, weight_lbs > 0, zone between 1 and 9, cost >= 0, and non-empty provider name and short_code.

On this page