Skip to Content
DatabaseEntity Relations — PostgreSQL

Entity Relations — PostgreSQL

Visual reference for all PostgreSQL tables and their relationships.

Full schema details (column definitions, indexes, queries): postgres.md


Core Hierarchy

The primary data hierarchy flows from a tenant down through strategy, goals, deliverables, activities, and execution records.

Rendering diagram…

Tenants & Users

Rendering diagram…

Strategy → Goals → Deliverables

Rendering diagram…

Activities & Execution

Rendering diagram…

Agent Configuration

Rendering diagram…

Channels & Content

Rendering diagram…

Rendering diagram…

Rendering diagram…

Billing

Rendering diagram…

Full Relationship Summary

TableKey Foreign Keys
userstenant_id → tenants
contractstenant_id → tenants, accepted_by → users
onboarding_runstenant_id → tenants, reviewed_by → users
strategiestenant_id → tenants, approved_by → users
goalstenant_id → tenants, strategy_id → strategies
deliverablestenant_id → tenants, goal_id → goals, strategy_id → strategies
deliverable_periodstenant_id → tenants, deliverable_id → deliverables
activitiestenant_id → tenants, deliverable_period_id → deliverable_periods, goal_id → goals, parent_activity_id → activities, assignee_user_id → users
activity_runstenant_id → tenants, activity_id → activities, session_id → sessions
sessionstenant_id → tenants, goal_id → goals
llm_callstenant_id → tenants, activity_run_id → activity_runs
tool_callstenant_id → tenants, activity_run_id → activity_runs
agent_configstenant_id → tenants
activity_templatestenant_id → tenants, source_template_id → activity_templates (self-ref)
recurring_task_templatestenant_id → tenants, source_template_id → recurring_task_templates (self-ref)
channelstenant_id → tenants
channel_scorestenant_id → tenants, channel_id → channels
blog_requeststenant_id → tenants, deliverable_id → deliverables, activity_id → activities, target_channel_id → channels
blog_poststenant_id → tenants, blog_request_id → blog_requests, channel_id → channels
social_media_requeststenant_id → tenants, deliverable_id → deliverables, activity_id → activities
social_poststenant_id → tenants, social_media_request_id → social_media_requests, channel_id → channels
backlinkstenant_id → tenants, activity_id → activities, deliverable_id → deliverables
leadstenant_id → tenants, source_channel_id → channels, source_campaign_id → ad_campaigns, assigned_to → users
lead_activitiestenant_id → tenants, lead_id → leads
ad_campaignstenant_id → tenants, channel_id → channels
ad_keywordstenant_id → tenants, channel_id → channels, ad_campaign_id → ad_campaigns
search_term_reportstenant_id → tenants, channel_id → channels, ad_campaign_id → ad_campaigns
search_term_classificationstenant_id → tenants, search_term_report_id → search_term_reports, activity_id → activities, reviewed_by → users
ad_optimization_recommendationstenant_id → tenants, channel_id → channels, ad_campaign_id → ad_campaigns, activity_id → activities, reviewed_by → users
billing_eventstenant_id → tenants

Cross-Database References

PostgreSQL columns reference MongoDB or S3 via stored identifiers. These are application-level references — not DB-enforced constraints.

PostgreSQL → MongoDB

PostgreSQL columnReferences MongoDBCollection
activities.output_refObjectIdactivity_outputs (metadata; content is in S3 via activity_outputs.s3Key)
blog_posts.content_refObjectIdactivity_outputs
social_posts.content_refObjectIdactivity_outputs
onboarding_runs.context_file_idObjectIdskills (and onboarding_research)
tool_calls (summary)ObjectIdtool_call_logs (full payloads)

PostgreSQL → S3

PostgreSQL columnS3 key pattern
contracts.pdf_s3_key{tenantId}/contracts/{contractRefId}/v{templateVersion}.pdf

PostgreSQL → MongoDB → S3 (two-hop)

For deliverable content, the path is: PostgreSQL holds a MongoDB ObjectId; the MongoDB document holds the S3 key.

PostgreSQL columnMongoDB collectionS3 content
activities.output_refactivity_outputs.s3KeyFull Markdown or JSON output
blog_posts.content_refactivity_outputs.s3KeyFull article Markdown
social_posts.content_refactivity_outputs.s3KeyPost copy + hashtags

© 2026 Leadmetrics — Internal use only