Skip to main content

Database Tables

Core Tables

TableDescription
usersApp users with email/password auth (JWT). Each user belongs to an agencies via agency_id FK and has a role
sellersAmazon seller accounts, unique on (seller_id, marketplace). Root entity — referenced by report tables and mappings
brandsCanonical brand definitions with aliases for fuzzy matching. Central entity — referenced by new_asins, and both mapping tables
agenciesAgencies that use the platform, with feature flags (jeff_enabled, lex_enabled). Referenced by users, agency_brand_mapping, and jeff_jobs

Mapping Tables

TableDescription
seller_brand_mappingLinks sellers to brands they sell, unique on (seller_id, brand_id). FKs to sellers, brands, and users (created_by)
lex_agency_brand_mappingLinks agencies to brands they manage for review removal. brand_id is unique — enforces one agency per brand. FKs to agencies, brands, users

Upload Tracking Tables

TableDescription
report_upload_historyAudit trail for report uploads: UUID, report type, file hash (dedup), blob path, uploader. uploaded_by and reversed_by FK to users. Supports upload reversal
report_row_changesRow-level change tracking per upload: change type (CREATED/UPDATED/UNCHANGED), previous and new values. FKs to report_upload_history via upload_id. Enables complete rollback

ASIN Ingestion Tables

These tables power the ASIN ingestion system (ScrapingBee-based), centered around new_asins as the parent table. All history tables use composite primary keys with (new_asin_id, timestamp) for time-series storage.

TableDescription
new_asinsScraped ASIN data, unique on (asin, marketplace). FK to brands. Has parent_asin for variation grouping
new_asin_changelogField-level change log for new_asins. FKs to new_asins. Tracks what changed, old/new values, and when
new_asin_signalsComputed signals per ASIN (title length, bullet quality, keyword density, etc.). Composite PK (new_asin_id, signal_name). FKs to new_asins
new_asin_offersCurrent offers/sellers on an ASIN listing. FKs to new_asins. Each offer has a seller_id
new_asin_offer_historyTime-series of offer snapshots. FKs to new_asin_offers via offer_id. Tracks price/buybox changes per offer over time
new_asin_price_historyPrice over time by price_type. Composite PK (new_asin_id, price_type, timestamp)
new_asin_sales_rank_historyBSR history per category. Composite PK (new_asin_id, category_id, timestamp)
new_asin_rating_historyOverall star rating over time
new_asin_rating_distribution_historyPer-star (1-5) rating counts over time
new_asin_review_count_historyTotal review count over time
new_asin_monthly_sold_historyMonthly sold count over time
new_asin_coupon_historyCoupon availability/details over time
dynamic_attributes_valuesMulti-entity SCD Type 2 attribute tracking with effective_from/effective_to. Sparse FKs to new_asins / brands / sellers (exactly one populated per row, matching entity_type); FK to users (modified_by). CHECK constraint enforces FK ↔ entity_type.
new_asin_variation_familiesVariation family definitions. Composite PK (parent_asin, marketplace)
new_asin_variation_family_changelogChange log for variation families. Composite FK to new_asin_variation_families with CASCADE delete
new_asin_variation_rating_historyRating history at variation level. FKs to new_asins
new_asin_variation_review_historyReview count history at variation level. FKs to new_asins

Review Removal Tables

TableDescription
lex_reviewsAmazon reviews tracked for removal. FKs to asins via asin_id. Tracks removal_state, invoice_state, and has_reappeared
lex_review_lifecycle_eventsLifecycle events per review (appeal submitted, removed, invoiced, etc.). FKs to lex_reviews and users

SP Structure Tables

These model the Amazon Sponsored Products campaign hierarchy. The chain is: sp_portfoliossp_campaignssp_ad_groups → targeting/keyword/product entities. All scoped by (seller_id, marketplace).

TableDescription
sp_portfoliosTop-level portfolio containers. Unique on (seller_id, marketplace, amazon_portfolio_id)
sp_campaignsCampaigns within portfolios. FK to sp_portfolios (nullable). Unique on (seller_id, marketplace, amazon_campaign_id)
sp_ad_groupsAd groups within campaigns. FK to sp_campaigns. Unique on (campaign_id, amazon_ad_group_id)
sp_product_adsIndividual product ads. FK to sp_ad_groups
sp_keywordsKeyword targets within ad groups. FK to sp_ad_groups
sp_negative_keywordsNegative keyword targets at ad group level. FK to sp_ad_groups
sp_product_targetingsProduct/ASIN targets within ad groups. FK to sp_ad_groups
sp_negative_product_targetingsNegative product targets at ad group level. FK to sp_ad_groups
sp_campaign_negative_keywordsNegative keywords at campaign level. FK to sp_campaigns
sp_campaign_negative_product_targetingsNegative product targets at campaign level. FK to sp_campaigns
sp_campaign_bidding_adjustmentsPlacement bid adjustments per campaign. FK to sp_campaigns. Unique on (campaign_id, placement)
sp_name_historyTracks name changes for any SP entity (campaign, ad group, etc.) over time. Indexed on (entity_type, entity_id, effective_from)

Report Tables

All report tables use shared mixins: seller_id/marketplace (ReportMetadata), report_date (ReportDate), uploaded_by/upload_timestamp (UploadTracking).

Business Reports

TableDescription
rpt_br_detail_page_sales_trafficParent ASIN sales/traffic: sessions, page views, buy box %, units, revenue
rpt_br_detail_page_sales_traffic_by_childChild ASIN level sales metrics
rpt_br_all_ordersOrder-level data: order ID, SKU, ASIN, quantity, revenue. Indexed on (seller_id, marketplace, amazon_order_id, sku, asin)
TableDescription
rpt_sponsored_products_campaignCampaign overview with budget/status
rpt_sponsored_products_search_termSearch term performance by match type
rpt_sponsored_products_targetingTargeting clause performance
rpt_sponsored_products_advertised_productProduct-level ASIN/SKU performance
rpt_sponsored_products_budgetBudget optimization and missed opportunities
rpt_sponsored_products_placementPerformance by ad placement
rpt_sponsored_products_purchased_productCross-sell analysis
rpt_sponsored_products_performance_over_timeTime-series minimal metrics
rpt_sponsored_products_search_term_impression_shareCompetitive positioning
rpt_sponsored_products_gross_and_invalid_trafficTraffic quality metrics

Search Query Performance

TableDescription
rpt_search_query_performance_brandBrand-level search analytics
rpt_search_query_performance_asinASIN-level search analytics

Inventory Reports

TableDescription
rpt_restock_inventoryRestock recommendations and inventory levels

Other Reports

TableDescription
rpt_azure_usageMakeshift table for tracking Azure API usage/costs. Not related to seller analytics

Jeff Tables

These power the Jeff AI SDR system. jeff_jobs is the entry point — each job contains rows (jeff_job_rows) that go through seller selection and audit generation.

TableDescription
jeff_jobsBulk processing jobs (CSV upload). FK to agencies. Contains status and config
jeff_job_rowsIndividual rows within a job, one per seller. FKs to jeff_jobs (CASCADE) and jeff_audits (CASCADE, nullable). Unique on (job_id, row_number)
jeff_prospect_selectionsSelected prospect ASINs per seller. Indexed on (seller_id, keepa_domain_id, selected_at)
jeff_competitor_selectionsCompetitor ASINs chosen for each prospect. FK to jeff_prospect_selections (CASCADE)
jeff_selection_xrayDebug/explainability data for selection scoring. FK to jeff_prospect_selections (CASCADE). Unique on (prospect_selection_id, step_type)
jeff_auditsGenerated audit documents per prospect selection. FK to jeff_prospect_selections (CASCADE)
jeff_refresh_dispatch_logsLogs for ASIN data refresh dispatches. No FKs, standalone
jeff_posthog_eventsPostHog analytics events related to Jeff

Smartlead Tables

Integration tables for the Smartlead email outreach platform. Prefixed with jeff_sl_ since they serve the Jeff outreach pipeline. jeff_sl_clients links to agencies for multi-tenant access.

TableDescription
jeff_sl_clientsSmartlead client accounts. FK to agencies (nullable). PK is the Smartlead ID
jeff_sl_campaignsEmail campaigns. Linked to clients via client_id. Has parent_campaign_id for series/sub-series hierarchy
jeff_sl_leadsEmail leads per campaign. Composite PK (id, campaign_id). Tracks status, category, and last activity
jeff_sl_lead_messagesIndividual email messages for leads
jeff_sl_email_accountsSender email accounts. Linked to clients. Indexed on domain and type
jeff_sl_categoriesLead categorization labels
jeff_sl_meetingsMeetings booked from outreach
jeff_sl_meeting_stage_eventsStage transitions for meetings (pipeline tracking)

Deprecated Tables

warning

These tables are from the legacy ASIN system and have been superseded by the ASIN Ingestion Tables (new_asins and family). The new_asins system provides richer data via ScrapingBee-based ingestion — including time-series history, signals, offers, and variation tracking — replacing the flat asins table and its lifecycle events. These tables still exist in the database but should not be used for new development.

TableDescription
asinsLegacy product catalog with parent-child relationships (via parent_asin self-reference). FKs to brands. Replaced by new_asins which has richer scraped data, marketplace scoping, and full history tracking
asin_lifecycle_eventsLegacy lifecycle events for ASINs (launch, discontinue, restock, etc.). FKs to asins and users. Replaced by new_asin_changelog which provides field-level change tracking automatically