0% found this document useful (0 votes)
3 views9 pages

SQL

This document details the SQL database schema for the Trustt AI Management Portal, focusing on user management, campaign orchestration, and customer engagement. It includes tables for users, templates, campaigns, customer data, call tracking, and integrations, among others, with specifications for fields and relationships. Additional notes highlight the use of JSONB fields, indexing strategies, and referential integrity across the database structure.

Uploaded by

bonida2658
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views9 pages

SQL

This document details the SQL database schema for the Trustt AI Management Portal, focusing on user management, campaign orchestration, and customer engagement. It includes tables for users, templates, campaigns, customer data, call tracking, and integrations, among others, with specifications for fields and relationships. Additional notes highlight the use of JSONB fields, indexing strategies, and referential integrity across the database structure.

Uploaded by

bonida2658
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

SQL Database Structure for Trustt AI

Management Portal
This document outlines the comprehensive SQL database schema for the Trustt AI
Management Portal, designed to support user management, campaign orchestration, customer
engagement, analytics, and third-party integrations.

1. Users Table ( Admin )


Stores user credentials and profile details.

CREATE TABLE users (


id SERIAL PRIMARY KEY,
username VARCHAR(255) NOT NULL UNIQUE,
email VARCHAR(255) NOT NULL UNIQUE,
password_hash VARCHAR(255) NOT NULL,
first_name VARCHAR(255),
last_name VARCHAR(255),
role VARCHAR(50) NOT NULL DEFAULT 'user',
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
last_login TIMESTAMP,
is_active BOOLEAN DEFAULT TRUE
);

2. Templates Table
Holds pre-defined campaign templates.

CREATE TABLE templates (


id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
description TEXT,
category VARCHAR(100),
config JSONB NOT NULL,
created_by INTEGER REFERENCES users(id),
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP,
usage_count INTEGER DEFAULT 0
);

3. Campaigns Table
Manages marketing/outreach campaigns.

CREATE TABLE campaigns (


id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
description TEXT,
status VARCHAR(50) NOT NULL DEFAULT 'draft', -- draft, active, paused, completed, failed
template_id INTEGER REFERENCES templates(id),
created_by INTEGER REFERENCES users(id),
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP,
start_date TIMESTAMP,
end_date TIMESTAMP,
is_deleted BOOLEAN DEFAULT FALSE,
tags TEXT[]
);

4. Campaign Configurations
Normalized table for detailed campaign settings.

CREATE TABLE campaign_configs (


id SERIAL PRIMARY KEY,
campaign_id INTEGER REFERENCES campaigns(id) ON DELETE CASCADE,
outcome_type VARCHAR(100),
voice_persona VARCHAR(100),
language VARCHAR(100),
call_script TEXT,
time_zone VARCHAR(100),
business_hours_start TIME,
business_hours_end TIME,
business_days TEXT[],
max_calls_per_day INTEGER,
max_calls_per_customer INTEGER,
retry_strategy VARCHAR(100),
retry_attempts INTEGER,
retry_interval INTEGER,
enable_escalation BOOLEAN DEFAULT TRUE,
sentiment_threshold INTEGER,
confidence_threshold INTEGER,
escalation_level VARCHAR(100),
handoff_behavior VARCHAR(100),
allocation_strategy VARCHAR(100)
);

5. Campaign Customer Table


Stores customer/contact information for a campaign. - Campaign Specific ( Gets Archived once
Campaign is completed/deleted)

CREATE TABLE customers (


id SERIAL PRIMARY KEY,
external_id VARCHAR(255),
first_name VARCHAR(255),
last_name VARCHAR(255),
email VARCHAR(255),
phone VARCHAR(50),
company VARCHAR(255),
job_title VARCHAR(255),
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP,
is_priority BOOLEAN DEFAULT FALSE,
tags TEXT[],
attributes JSONB,
is_deleted BOOLEAN DEFAULT FALSE
);

6. Segments & Membership - Not Required


Customer segmentation for targeting.

CREATE TABLE segments (


id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
description TEXT,
criteria JSONB,
created_by INTEGER REFERENCES users(id),
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP
);

CREATE TABLE customer_segments (


customer_id INTEGER REFERENCES customers(id) ON DELETE CASCADE,
segment_id INTEGER REFERENCES segments(id) ON DELETE CASCADE,
PRIMARY KEY (customer_id, segment_id)
);

7. Campaign Audiences - Future roadmap​


( Target Campaigns for list of Cust. )
Links campaigns to specific segments or customers.

CREATE TABLE campaign_audiences (


campaign_id INTEGER REFERENCES campaigns(id) ON DELETE CASCADE,
segment_id INTEGER REFERENCES segments(id),
customer_id INTEGER REFERENCES customers(id),
PRIMARY KEY (campaign_id, COALESCE(segment_id, 0), COALESCE(customer_id, 0))
);

8. Calls Table
Tracks call history, status, and escalations.

CREATE TABLE calls (


id SERIAL PRIMARY KEY,
campaign_id INTEGER REFERENCES campaigns(id),
customer_id INTEGER REFERENCES customers(id),
status VARCHAR(50) NOT NULL,
start_time TIMESTAMP,
end_time TIMESTAMP,
duration INTEGER,
transcript TEXT,
transcript_segments JSONB,
summary TEXT,
sentiment_score INTEGER,
confidence_score INTEGER,
escalated BOOLEAN DEFAULT FALSE,
escalation_reason TEXT,
escalation_time TIMESTAMP,
escalated_to INTEGER REFERENCES users(id),
call_recording_url VARCHAR(255),
scheduled_time TIMESTAMP,
priority VARCHAR(50) DEFAULT 'medium',
attempt_count INTEGER DEFAULT 1,
next_attempt_time TIMESTAMP,
metadata JSONB
);

9. Documents Table
Stores reference materials linked to campaigns.

CREATE TABLE documents (


id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
type VARCHAR(100) NOT NULL,
file_path VARCHAR(255) NOT NULL,
file_type VARCHAR(50),
content TEXT,
campaign_id INTEGER REFERENCES campaigns(id),
created_by INTEGER REFERENCES users(id),
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
last_updated_by INTEGER REFERENCES users(id),
last_updated_at TIMESTAMP,
is_deleted BOOLEAN DEFAULT FALSE
);

10. Voice Personas & Languages


Support multilingual and multi-voice campaigns.
CREATE TABLE voice_personas (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
description TEXT,
voice_sample_url VARCHAR(255)
);

CREATE TABLE languages (


code VARCHAR(10) PRIMARY KEY,
name VARCHAR(100) NOT NULL,
is_active BOOLEAN DEFAULT TRUE
);

11. Escalation Rules - Not MVP

Defines triggers for call escalations.


CREATE TABLE escalation_rules (
id SERIAL PRIMARY KEY,
campaign_id INTEGER REFERENCES campaigns(id) ON DELETE CASCADE,
keyword_triggers TEXT[],
sentiment_threshold INTEGER,
confidence_threshold INTEGER,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP
);

12. Metrics Table


Aggregated analytics for campaign performance.

CREATE TABLE metrics (


id SERIAL PRIMARY KEY,
campaign_id INTEGER REFERENCES campaigns(id),
date DATE NOT NULL,
total_calls INTEGER DEFAULT 0,
completed_calls INTEGER DEFAULT 0,
active_calls INTEGER DEFAULT 0,
queued_calls INTEGER DEFAULT 0,
failed_calls INTEGER DEFAULT 0,
escalated_calls INTEGER DEFAULT 0,
avg_call_duration INTEGER,
avg_sentiment_score INTEGER,
avg_confidence_score INTEGER,
total_customers_reached INTEGER DEFAULT 0
);

13. Alerts Table


Real-time system notifications.

CREATE TABLE alerts (


id SERIAL PRIMARY KEY,
campaign_id INTEGER REFERENCES campaigns(id),
type VARCHAR(50) NOT NULL,
title VARCHAR(255) NOT NULL,
description TEXT,
is_read BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
severity VARCHAR(20) DEFAULT 'medium'
);

14. CRM Integrations


User-specific CRM connection data.

CREATE TABLE crm_integrations (


id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(id),
crm_type VARCHAR(100) NOT NULL,
credentials JSONB,
is_active BOOLEAN DEFAULT TRUE,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP
);
15. Webhooks Table
Manages outbound event-based integrations.

CREATE TABLE webhooks (


id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(id),
url VARCHAR(255) NOT NULL,
event_types TEXT[] NOT NULL,
secret_key VARCHAR(255),
is_active BOOLEAN DEFAULT TRUE,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
last_triggered_at TIMESTAMP
);

16. Indexes
Improves query performance across key tables.

CREATE INDEX idx_calls_campaign_id ON calls(campaign_id);


CREATE INDEX idx_calls_customer_id ON calls(customer_id);
CREATE INDEX idx_calls_status ON calls(status);
CREATE INDEX idx_customers_email ON customers(email);
CREATE INDEX idx_customers_phone ON customers(phone);
CREATE INDEX idx_campaigns_status ON campaigns(status);
CREATE INDEX idx_campaigns_created_at ON campaigns(created_at);
CREATE INDEX idx_metrics_campaign_date ON metrics(campaign_id, date);
CREATE INDEX idx_templates_category ON templates(category);
CREATE INDEX idx_alerts_campaign_read ON alerts(campaign_id, is_read);

Additional Notes
●​ JSONB Fields: Ideal for flexible, schema-less data like configs, transcripts, and
credentials.​

●​ Indexing Strategy: Focused on columns used in filters, joins, and sorting.​

●​ Audit Fields: Most tables track creation and update timestamps for traceability.​
●​ Soft Deletion: is_deleted used for retaining data without actual removal.​

●​ Referential Integrity: Enforced using foreign keys with cascade rules where needed.​

●​ Cross-DB Compatibility:​

○​ Use AUTO_INCREMENT in MySQL​

○​ Use DATETIME in SQLite​

○​ Use IDENTITY in SQL Server​

You might also like