-- WARNING: This schema is for context only and is not meant to be run.
CREATE TABLE public.chat_messages (
id uuid NOT NULL DEFAULT gen_random_uuid(),
session_id text NOT NULL,
sender_identity text NOT NULL,
message text NOT NULL,
created_at timestamp with time zone DEFAULT now(),
metadata jsonb DEFAULT '{}'::jsonb,
CONSTRAINT chat_messages_pkey PRIMARY KEY (id)
);
CREATE TABLE public.contacts (
id uuid NOT NULL DEFAULT gen_random_uuid(),
name text NOT NULL,
phone text NOT NULL,
email text,
company text,
notes text,
created_at timestamp with time zone DEFAULT now(),
updated_at timestamp with time zone DEFAULT now(),
sms_opt_out boolean DEFAULT false,
tags ARRAY DEFAULT '{}'::text[],
source text,
metadata jsonb DEFAULT '{}'::jsonb,
CONSTRAINT contacts_pkey PRIMARY KEY (id)
);
CREATE TABLE public.follow_ups (
id uuid NOT NULL DEFAULT gen_random_uuid(),
interaction_id uuid,
contact_id uuid,
type text NOT NULL CHECK (type = ANY (ARRAY['auto_sms'::text, 'manual'::text, 'callback'::text, 'email'::text])),
status text NOT NULL DEFAULT 'pending'::text CHECK (status = ANY (ARRAY['pending'::text, 'completed'::text, 'failed'::text])),
message text,
scheduled_for timestamp with time zone,
completed_at timestamp with time zone,
created_at timestamp with time zone DEFAULT now(),
priority text DEFAULT 'medium'::text,
metadata jsonb DEFAULT '{}'::jsonb,
due_date timestamp with time zone,
CONSTRAINT follow_ups_pkey PRIMARY KEY (id),
CONSTRAINT follow_ups_interaction_id_fkey FOREIGN KEY (interaction_id) REFERENCES public.interactions(id),
CONSTRAINT follow_ups_contact_id_fkey FOREIGN KEY (contact_id) REFERENCES public.contacts(id)
);
CREATE TABLE public.interactions (
id uuid NOT NULL DEFAULT gen_random_uuid(),
type text NOT NULL CHECK (type = ANY (ARRAY['call'::text, 'sms'::text])),
direction text NOT NULL CHECK (direction = ANY (ARRAY['inbound'::text, 'outbound'::text])),
from_number text NOT NULL,
to_number text NOT NULL,
status text NOT NULL,
duration integer,
body text,
twilio_sid text,
contact_id uuid,
created_at timestamp with time zone DEFAULT now(),
num_media integer DEFAULT 0,
metadata jsonb DEFAULT '{}'::jsonb,
CONSTRAINT interactions_pkey PRIMARY KEY (id),
CONSTRAINT interactions_contact_id_fkey FOREIGN KEY (contact_id) REFERENCES public.contacts(id)
);
CREATE TABLE public.leads (
id uuid NOT NULL DEFAULT gen_random_uuid(),
contact_id uuid,
title text NOT NULL,
description text,
status text NOT NULL DEFAULT 'new'::text CHECK (status = ANY (ARRAY['new'::text, 'contacted'::text, 'qualified'::text, 'converted'::text, 'lost'::text])),
priority text DEFAULT 'medium'::text CHECK (priority = ANY (ARRAY['low'::text, 'medium'::text, 'high'::text])),
source text,
value numeric,
created_at timestamp with time zone DEFAULT now(),
updated_at timestamp with time zone DEFAULT now(),
CONSTRAINT leads_pkey PRIMARY KEY (id),
CONSTRAINT leads_contact_id_fkey FOREIGN KEY (contact_id) REFERENCES public.contacts(id)
);
CREATE TABLE public.notifications (
id uuid NOT NULL DEFAULT uuid_generate_v4(),
type text NOT NULL,
severity text DEFAULT 'info'::text,
title text NOT NULL,
message text,
metadata jsonb DEFAULT '{}'::jsonb,
read boolean DEFAULT false,
created_at timestamp with time zone DEFAULT now(),
CONSTRAINT notifications_pkey PRIMARY KEY (id)
);
CREATE TABLE public.sms_metrics (
id uuid NOT NULL DEFAULT uuid_generate_v4(),
message_sid text NOT NULL UNIQUE,
status text NOT NULL,
is_delivered boolean DEFAULT false,
is_failed boolean DEFAULT false,
error_code text,
num_segments integer DEFAULT 1,
price numeric,
price_unit text,
delivery_time_ms integer,
created_at timestamp with time zone DEFAULT now(),
CONSTRAINT sms_metrics_pkey PRIMARY KEY (id)
);