--
-- PostgreSQL database dump
--

\restrict My0Vn0kx15H8Ap5LRSMbf3GxixKUDcKlSprve6AUT5VODWnkBgTmsOUfbB4jK7O

-- Dumped from database version 16.12 (9893e46)
-- Dumped by pg_dump version 16.13

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

--
-- Name: public; Type: SCHEMA; Schema: -; Owner: -
--

CREATE SCHEMA public;


--
-- Name: SCHEMA public; Type: COMMENT; Schema: -; Owner: -
--

COMMENT ON SCHEMA public IS 'standard public schema';


SET default_table_access_method = heap;

--
-- Name: account_service_balance; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.account_service_balance (
    user_id character varying NOT NULL,
    service_id character varying NOT NULL,
    creditos_disponiveis integer DEFAULT 0 NOT NULL
);


--
-- Name: activity_logs; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.activity_logs (
    id character varying DEFAULT gen_random_uuid() NOT NULL,
    campaign_id character varying,
    action character varying NOT NULL,
    details text,
    created_at timestamp without time zone DEFAULT now(),
    origin character varying(20) DEFAULT 'sistema'::character varying NOT NULL
);


--
-- Name: api_settings; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.api_settings (
    id character varying DEFAULT gen_random_uuid() NOT NULL,
    key character varying NOT NULL,
    value text,
    description text,
    updated_at timestamp without time zone DEFAULT now()
);


--
-- Name: api_tokens; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.api_tokens (
    id character varying DEFAULT gen_random_uuid() NOT NULL,
    service_id character varying NOT NULL,
    token character varying(64) NOT NULL,
    description character varying(200),
    ativo boolean DEFAULT true NOT NULL,
    last_used_at timestamp without time zone,
    created_at timestamp without time zone DEFAULT now()
);


--
-- Name: branding; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.branding (
    user_id character varying NOT NULL,
    logo_url character varying,
    primary_color character varying(20),
    platform_name character varying,
    favicon_url character varying
);


--
-- Name: campaigns; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.campaigns (
    id character varying DEFAULT gen_random_uuid() NOT NULL,
    external_id character varying NOT NULL,
    name character varying NOT NULL,
    status character varying(50) DEFAULT 'pending'::character varying NOT NULL,
    message_text text,
    has_image integer DEFAULT 0,
    has_video integer DEFAULT 0,
    total_contacts integer DEFAULT 0,
    sent_count integer DEFAULT 0,
    failed_count integer DEFAULT 0,
    zip_file_path character varying,
    report_file_path character varying,
    created_at timestamp without time zone DEFAULT now(),
    updated_at timestamp without time zone DEFAULT now(),
    sent_to_operator_at timestamp without time zone,
    report_received_at timestamp without time zone,
    completed_at timestamp without time zone,
    service_type character varying(20) DEFAULT 'wa_oficial'::character varying NOT NULL,
    image_path character varying,
    video_path character varying,
    title_profile character varying,
    profile_image_path character varying,
    scheduled_at timestamp without time zone,
    preferred_ddd character varying(2),
    owner_id character varying,
    service_id character varying,
    creditos_reservados integer DEFAULT 0,
    wa_filter_status character varying(20),
    wa_filter_task_id character varying,
    wa_filtered_count integer,
    template_id character varying,
    template_params text,
    btn_url_param character varying,
    image_data text,
    profile_image_data text,
    video_data text,
    image_object_path character varying,
    profile_image_object_path character varying,
    video_object_path character varying,
    template_body_snapshot text,
    template_rodape_snapshot text,
    template_buttons_snapshot jsonb
);


--
-- Name: column_keywords; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.column_keywords (
    id character varying DEFAULT gen_random_uuid() NOT NULL,
    column_type character varying NOT NULL,
    keyword character varying NOT NULL
);


--
-- Name: contacts; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.contacts (
    id character varying DEFAULT gen_random_uuid() NOT NULL,
    campaign_id character varying NOT NULL,
    phone_number character varying NOT NULL,
    status character varying(50) DEFAULT 'pending'::character varying NOT NULL,
    original_status character varying,
    observation text,
    processed_at timestamp without time zone,
    data_agendamento character varying,
    data_entrega character varying,
    has_whatsapp boolean,
    params text,
    btn_url_param character varying
);


--
-- Name: credit_transactions; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.credit_transactions (
    id character varying DEFAULT gen_random_uuid() NOT NULL,
    user_id character varying NOT NULL,
    service_id character varying NOT NULL,
    tipo character varying(20) NOT NULL,
    quantidade integer NOT NULL,
    campaign_id character varying,
    created_at timestamp without time zone DEFAULT now(),
    descricao character varying
);


--
-- Name: hubspot_alert_config; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.hubspot_alert_config (
    key character varying(32) DEFAULT 'default'::character varying NOT NULL,
    enabled boolean DEFAULT false NOT NULL,
    threshold_count integer DEFAULT 5 NOT NULL,
    window_minutes integer DEFAULT 30 NOT NULL,
    cooldown_minutes integer DEFAULT 360 NOT NULL,
    recipients_csv text DEFAULT ''::text NOT NULL,
    smtp_host character varying(255),
    smtp_port integer,
    smtp_user character varying(255),
    smtp_password text,
    smtp_from character varying(255),
    smtp_secure boolean DEFAULT false NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: hubspot_alert_state; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.hubspot_alert_state (
    portal_id character varying(64) NOT NULL,
    last_alerted_at timestamp without time zone DEFAULT now() NOT NULL,
    last_failure_count integer DEFAULT 0 NOT NULL
);


--
-- Name: hubspot_connections; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.hubspot_connections (
    id character varying DEFAULT gen_random_uuid() NOT NULL,
    user_id character varying NOT NULL,
    service_id character varying NOT NULL,
    portal_id character varying NOT NULL,
    access_token text NOT NULL,
    ativo boolean DEFAULT true NOT NULL,
    last_sync_at timestamp without time zone,
    created_at timestamp without time zone DEFAULT now(),
    refresh_token text,
    token_expires_at timestamp without time zone,
    connection_type character varying DEFAULT 'manual'::character varying NOT NULL,
    last_sync_status character varying(32),
    last_sync_message text,
    property_scope_skip_notice_at timestamp without time zone,
    timeline_enabled boolean DEFAULT true NOT NULL
);


--
-- Name: hubspot_execute_diagnostics; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.hubspot_execute_diagnostics (
    id character varying DEFAULT gen_random_uuid() NOT NULL,
    received_at timestamp without time zone DEFAULT now() NOT NULL,
    ip character varying(64),
    method character varying(10) NOT NULL,
    url text NOT NULL,
    headers text NOT NULL,
    raw_body text,
    signature_valid boolean,
    http_status integer,
    outcome character varying(20) DEFAULT 'pending'::character varying NOT NULL,
    outcome_detail text,
    portal_id character varying(64),
    object_id character varying(64),
    template_id character varying,
    duration_ms integer
);


--
-- Name: hubspot_pending_dispatch; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.hubspot_pending_dispatch (
    id character varying DEFAULT gen_random_uuid() NOT NULL,
    portal_id character varying(64),
    owner_user_id character varying,
    service_id character varying NOT NULL,
    template_id character varying NOT NULL,
    phone character varying NOT NULL,
    parametros jsonb,
    btn_url_param character varying,
    status character varying(20) DEFAULT 'pending'::character varying NOT NULL,
    attempt_count integer DEFAULT 0 NOT NULL,
    last_attempt_at timestamp without time zone,
    last_error text,
    queued_at timestamp without time zone DEFAULT now() NOT NULL,
    sent_at timestamp without time zone,
    contact_object_id character varying(128)
);


--
-- Name: hubspot_timeline_templates; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.hubspot_timeline_templates (
    id character varying DEFAULT gen_random_uuid() NOT NULL,
    app_id character varying(64) NOT NULL,
    event_template_id character varying(128) NOT NULL,
    object_type character varying(32) DEFAULT 'contacts'::character varying NOT NULL,
    version integer DEFAULT 1 NOT NULL,
    registered_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: infobip_configs; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.infobip_configs (
    id character varying DEFAULT gen_random_uuid() NOT NULL,
    service_id character varying NOT NULL,
    api_key text NOT NULL,
    base_url character varying NOT NULL,
    waba_id character varying,
    ativo boolean DEFAULT true NOT NULL,
    created_at timestamp without time zone DEFAULT now(),
    updated_at timestamp without time zone DEFAULT now(),
    name character varying DEFAULT 'WABA Principal'::character varying NOT NULL,
    application_id character varying,
    entity_id character varying,
    webhook_subscription_id character varying
);


--
-- Name: infobip_senders; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.infobip_senders (
    id character varying DEFAULT gen_random_uuid() NOT NULL,
    service_id character varying NOT NULL,
    number character varying NOT NULL,
    display_name character varying,
    status character varying(20) DEFAULT 'ACTIVE'::character varying NOT NULL,
    quality character varying(20) DEFAULT 'UNKNOWN'::character varying NOT NULL,
    last_used_at timestamp without time zone,
    ativo boolean DEFAULT true NOT NULL,
    created_at timestamp without time zone DEFAULT now(),
    config_id character varying,
    daily_limit integer,
    preferred boolean DEFAULT false NOT NULL
);


--
-- Name: services; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.services (
    id character varying DEFAULT gen_random_uuid() NOT NULL,
    nome character varying NOT NULL,
    descricao text,
    tipo character varying(20) DEFAULT 'manual'::character varying NOT NULL,
    regra_cobranca character varying(20) DEFAULT 'enviados'::character varying NOT NULL,
    api_endpoint character varying,
    api_token character varying,
    ativo boolean DEFAULT true NOT NULL,
    tipo_whatsapp character varying(20) DEFAULT 'wa_off'::character varying NOT NULL,
    modo_teste boolean DEFAULT true NOT NULL,
    permitir_marketing boolean DEFAULT false NOT NULL,
    template_filtro character varying(100)
);


--
-- Name: session; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.session (
    sid character varying NOT NULL,
    sess json NOT NULL,
    expire timestamp without time zone NOT NULL
);


--
-- Name: status_mappings; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.status_mappings (
    id character varying DEFAULT gen_random_uuid() NOT NULL,
    original_status character varying NOT NULL,
    normalized_status character varying(50) NOT NULL
);


--
-- Name: template_presets; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.template_presets (
    id character varying DEFAULT gen_random_uuid() NOT NULL,
    service_id character varying NOT NULL,
    template_id character varying NOT NULL,
    parametros jsonb DEFAULT '[]'::jsonb NOT NULL,
    created_at timestamp without time zone DEFAULT now(),
    updated_at timestamp without time zone DEFAULT now(),
    header_image_url character varying
);


--
-- Name: user_services; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.user_services (
    user_id character varying NOT NULL,
    service_id character varying NOT NULL,
    lote_minimo integer DEFAULT 1 NOT NULL,
    hubspot_enabled boolean DEFAULT false NOT NULL,
    ativo boolean DEFAULT true NOT NULL
);


--
-- Name: users; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.users (
    id character varying DEFAULT gen_random_uuid() NOT NULL,
    username text NOT NULL,
    password text NOT NULL,
    role character varying(20) DEFAULT 'OPERADOR'::character varying NOT NULL,
    ativo boolean DEFAULT true NOT NULL,
    failed_attempts integer DEFAULT 0 NOT NULL,
    lock_until timestamp without time zone,
    criado_em timestamp without time zone DEFAULT now(),
    ultimo_login timestamp without time zone,
    email character varying,
    parent_id character varying,
    tipo_pessoa character varying(2),
    documento character varying(18),
    nome_fantasia character varying(150),
    cidade character varying(100),
    razao_social character varying(200),
    bloqueado_criar_lote boolean DEFAULT false NOT NULL
);


--
-- Name: waba_messages; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.waba_messages (
    id character varying DEFAULT gen_random_uuid() NOT NULL,
    service_id character varying NOT NULL,
    campaign_id character varying,
    infobip_message_id character varying,
    phone character varying NOT NULL,
    template_id character varying,
    template_name character varying,
    status character varying(20) DEFAULT 'PENDING'::character varying NOT NULL,
    error_message text,
    sent_at timestamp without time zone DEFAULT now(),
    updated_at timestamp without time zone DEFAULT now(),
    sender_id character varying,
    owner_user_id character varying,
    portal_id character varying,
    source character varying,
    contact_object_id character varying(128)
);


--
-- Name: waba_templates; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.waba_templates (
    id character varying DEFAULT gen_random_uuid() NOT NULL,
    service_id character varying NOT NULL,
    nome character varying NOT NULL,
    idioma character varying(10) DEFAULT 'pt_BR'::character varying NOT NULL,
    categoria character varying(50) DEFAULT 'UTILITY'::character varying NOT NULL,
    corpo text NOT NULL,
    rodape character varying,
    infobip_template_id character varying,
    status character varying(20) DEFAULT 'PENDING'::character varying NOT NULL,
    rejection_reason text,
    created_at timestamp without time zone DEFAULT now(),
    updated_at timestamp without time zone DEFAULT now(),
    tipo character varying(20) DEFAULT 'interativo'::character varying NOT NULL,
    header_type character varying(20),
    header_content text,
    buttons jsonb,
    carousel_cards jsonb
);


--
-- Name: account_service_balance account_service_balance_user_id_service_id_pk; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.account_service_balance
    ADD CONSTRAINT account_service_balance_user_id_service_id_pk PRIMARY KEY (user_id, service_id);


--
-- Name: activity_logs activity_logs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.activity_logs
    ADD CONSTRAINT activity_logs_pkey PRIMARY KEY (id);


--
-- Name: api_settings api_settings_key_unique; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.api_settings
    ADD CONSTRAINT api_settings_key_unique UNIQUE (key);


--
-- Name: api_settings api_settings_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.api_settings
    ADD CONSTRAINT api_settings_pkey PRIMARY KEY (id);


--
-- Name: api_tokens api_tokens_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.api_tokens
    ADD CONSTRAINT api_tokens_pkey PRIMARY KEY (id);


--
-- Name: api_tokens api_tokens_token_unique; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.api_tokens
    ADD CONSTRAINT api_tokens_token_unique UNIQUE (token);


--
-- Name: branding branding_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.branding
    ADD CONSTRAINT branding_pkey PRIMARY KEY (user_id);


--
-- Name: campaigns campaigns_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.campaigns
    ADD CONSTRAINT campaigns_pkey PRIMARY KEY (id);


--
-- Name: column_keywords column_keywords_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.column_keywords
    ADD CONSTRAINT column_keywords_pkey PRIMARY KEY (id);


--
-- Name: contacts contacts_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.contacts
    ADD CONSTRAINT contacts_pkey PRIMARY KEY (id);


--
-- Name: credit_transactions credit_transactions_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.credit_transactions
    ADD CONSTRAINT credit_transactions_pkey PRIMARY KEY (id);


--
-- Name: hubspot_alert_config hubspot_alert_config_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.hubspot_alert_config
    ADD CONSTRAINT hubspot_alert_config_pkey PRIMARY KEY (key);


--
-- Name: hubspot_alert_state hubspot_alert_state_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.hubspot_alert_state
    ADD CONSTRAINT hubspot_alert_state_pkey PRIMARY KEY (portal_id);


--
-- Name: hubspot_connections hubspot_connections_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.hubspot_connections
    ADD CONSTRAINT hubspot_connections_pkey PRIMARY KEY (id);


--
-- Name: hubspot_connections hubspot_connections_portal_id_unique; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.hubspot_connections
    ADD CONSTRAINT hubspot_connections_portal_id_unique UNIQUE (portal_id);


--
-- Name: hubspot_execute_diagnostics hubspot_execute_diagnostics_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.hubspot_execute_diagnostics
    ADD CONSTRAINT hubspot_execute_diagnostics_pkey PRIMARY KEY (id);


--
-- Name: hubspot_pending_dispatch hubspot_pending_dispatch_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.hubspot_pending_dispatch
    ADD CONSTRAINT hubspot_pending_dispatch_pkey PRIMARY KEY (id);


--
-- Name: hubspot_timeline_templates hubspot_timeline_templates_app_id_unique; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.hubspot_timeline_templates
    ADD CONSTRAINT hubspot_timeline_templates_app_id_unique UNIQUE (app_id);


--
-- Name: hubspot_timeline_templates hubspot_timeline_templates_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.hubspot_timeline_templates
    ADD CONSTRAINT hubspot_timeline_templates_pkey PRIMARY KEY (id);


--
-- Name: infobip_configs infobip_configs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.infobip_configs
    ADD CONSTRAINT infobip_configs_pkey PRIMARY KEY (id);


--
-- Name: infobip_senders infobip_senders_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.infobip_senders
    ADD CONSTRAINT infobip_senders_pkey PRIMARY KEY (id);


--
-- Name: services services_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.services
    ADD CONSTRAINT services_pkey PRIMARY KEY (id);


--
-- Name: session session_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.session
    ADD CONSTRAINT session_pkey PRIMARY KEY (sid);


--
-- Name: status_mappings status_mappings_original_status_unique; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.status_mappings
    ADD CONSTRAINT status_mappings_original_status_unique UNIQUE (original_status);


--
-- Name: status_mappings status_mappings_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.status_mappings
    ADD CONSTRAINT status_mappings_pkey PRIMARY KEY (id);


--
-- Name: template_presets template_presets_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.template_presets
    ADD CONSTRAINT template_presets_pkey PRIMARY KEY (id);


--
-- Name: template_presets template_presets_svc_tmpl_uniq; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.template_presets
    ADD CONSTRAINT template_presets_svc_tmpl_uniq UNIQUE (service_id, template_id);


--
-- Name: users users_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.users
    ADD CONSTRAINT users_pkey PRIMARY KEY (id);


--
-- Name: users users_username_unique; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.users
    ADD CONSTRAINT users_username_unique UNIQUE (username);


--
-- Name: waba_messages waba_messages_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.waba_messages
    ADD CONSTRAINT waba_messages_pkey PRIMARY KEY (id);


--
-- Name: waba_templates waba_templates_nome_unique; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.waba_templates
    ADD CONSTRAINT waba_templates_nome_unique UNIQUE (nome);


--
-- Name: waba_templates waba_templates_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.waba_templates
    ADD CONSTRAINT waba_templates_pkey PRIMARY KEY (id);


--
-- Name: IDX_session_expire; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX "IDX_session_expire" ON public.session USING btree (expire);


--
-- Name: hubspot_pending_dispatch_service_status_idx; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX hubspot_pending_dispatch_service_status_idx ON public.hubspot_pending_dispatch USING btree (service_id, status);


--
-- Name: hubspot_pending_dispatch_status_queued_at_idx; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX hubspot_pending_dispatch_status_queued_at_idx ON public.hubspot_pending_dispatch USING btree (status, queued_at);


--
-- Name: waba_messages_portal_contact_sent_at_idx; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX waba_messages_portal_contact_sent_at_idx ON public.waba_messages USING btree (portal_id, contact_object_id, sent_at);


--
-- Name: account_service_balance account_service_balance_service_id_services_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.account_service_balance
    ADD CONSTRAINT account_service_balance_service_id_services_id_fk FOREIGN KEY (service_id) REFERENCES public.services(id) ON DELETE CASCADE;


--
-- Name: account_service_balance account_service_balance_user_id_users_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.account_service_balance
    ADD CONSTRAINT account_service_balance_user_id_users_id_fk FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;


--
-- Name: activity_logs activity_logs_campaign_id_campaigns_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.activity_logs
    ADD CONSTRAINT activity_logs_campaign_id_campaigns_id_fk FOREIGN KEY (campaign_id) REFERENCES public.campaigns(id);


--
-- Name: api_tokens api_tokens_service_id_services_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.api_tokens
    ADD CONSTRAINT api_tokens_service_id_services_id_fk FOREIGN KEY (service_id) REFERENCES public.services(id) ON DELETE CASCADE;


--
-- Name: branding branding_user_id_users_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.branding
    ADD CONSTRAINT branding_user_id_users_id_fk FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;


--
-- Name: contacts contacts_campaign_id_campaigns_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.contacts
    ADD CONSTRAINT contacts_campaign_id_campaigns_id_fk FOREIGN KEY (campaign_id) REFERENCES public.campaigns(id);


--
-- Name: credit_transactions credit_transactions_campaign_id_campaigns_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.credit_transactions
    ADD CONSTRAINT credit_transactions_campaign_id_campaigns_id_fk FOREIGN KEY (campaign_id) REFERENCES public.campaigns(id);


--
-- Name: credit_transactions credit_transactions_service_id_services_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.credit_transactions
    ADD CONSTRAINT credit_transactions_service_id_services_id_fk FOREIGN KEY (service_id) REFERENCES public.services(id);


--
-- Name: credit_transactions credit_transactions_user_id_users_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.credit_transactions
    ADD CONSTRAINT credit_transactions_user_id_users_id_fk FOREIGN KEY (user_id) REFERENCES public.users(id);


--
-- Name: hubspot_connections hubspot_connections_service_id_services_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.hubspot_connections
    ADD CONSTRAINT hubspot_connections_service_id_services_id_fk FOREIGN KEY (service_id) REFERENCES public.services(id) ON DELETE CASCADE;


--
-- Name: hubspot_connections hubspot_connections_user_id_users_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.hubspot_connections
    ADD CONSTRAINT hubspot_connections_user_id_users_id_fk FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;


--
-- Name: hubspot_pending_dispatch hubspot_pending_dispatch_owner_user_id_users_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.hubspot_pending_dispatch
    ADD CONSTRAINT hubspot_pending_dispatch_owner_user_id_users_id_fk FOREIGN KEY (owner_user_id) REFERENCES public.users(id) ON DELETE SET NULL;


--
-- Name: hubspot_pending_dispatch hubspot_pending_dispatch_service_id_services_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.hubspot_pending_dispatch
    ADD CONSTRAINT hubspot_pending_dispatch_service_id_services_id_fk FOREIGN KEY (service_id) REFERENCES public.services(id) ON DELETE CASCADE;


--
-- Name: infobip_configs infobip_configs_service_id_services_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.infobip_configs
    ADD CONSTRAINT infobip_configs_service_id_services_id_fk FOREIGN KEY (service_id) REFERENCES public.services(id) ON DELETE CASCADE;


--
-- Name: infobip_senders infobip_senders_config_id_infobip_configs_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.infobip_senders
    ADD CONSTRAINT infobip_senders_config_id_infobip_configs_id_fk FOREIGN KEY (config_id) REFERENCES public.infobip_configs(id) ON DELETE CASCADE;


--
-- Name: infobip_senders infobip_senders_service_id_services_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.infobip_senders
    ADD CONSTRAINT infobip_senders_service_id_services_id_fk FOREIGN KEY (service_id) REFERENCES public.services(id) ON DELETE CASCADE;


--
-- Name: template_presets template_presets_service_id_services_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.template_presets
    ADD CONSTRAINT template_presets_service_id_services_id_fk FOREIGN KEY (service_id) REFERENCES public.services(id) ON DELETE CASCADE;


--
-- Name: template_presets template_presets_template_id_waba_templates_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.template_presets
    ADD CONSTRAINT template_presets_template_id_waba_templates_id_fk FOREIGN KEY (template_id) REFERENCES public.waba_templates(id) ON DELETE CASCADE;


--
-- Name: user_services user_services_service_id_services_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.user_services
    ADD CONSTRAINT user_services_service_id_services_id_fk FOREIGN KEY (service_id) REFERENCES public.services(id) ON DELETE CASCADE;


--
-- Name: user_services user_services_user_id_users_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.user_services
    ADD CONSTRAINT user_services_user_id_users_id_fk FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;


--
-- Name: waba_messages waba_messages_campaign_id_campaigns_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.waba_messages
    ADD CONSTRAINT waba_messages_campaign_id_campaigns_id_fk FOREIGN KEY (campaign_id) REFERENCES public.campaigns(id);


--
-- Name: waba_messages waba_messages_sender_id_infobip_senders_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.waba_messages
    ADD CONSTRAINT waba_messages_sender_id_infobip_senders_id_fk FOREIGN KEY (sender_id) REFERENCES public.infobip_senders(id) ON DELETE SET NULL;


--
-- Name: waba_messages waba_messages_service_id_services_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.waba_messages
    ADD CONSTRAINT waba_messages_service_id_services_id_fk FOREIGN KEY (service_id) REFERENCES public.services(id) ON DELETE CASCADE;


--
-- Name: waba_messages waba_messages_template_id_waba_templates_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.waba_messages
    ADD CONSTRAINT waba_messages_template_id_waba_templates_id_fk FOREIGN KEY (template_id) REFERENCES public.waba_templates(id);


--
-- Name: waba_templates waba_templates_service_id_services_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.waba_templates
    ADD CONSTRAINT waba_templates_service_id_services_id_fk FOREIGN KEY (service_id) REFERENCES public.services(id) ON DELETE CASCADE;


--
-- PostgreSQL database dump complete
--

\unrestrict My0Vn0kx15H8Ap5LRSMbf3GxixKUDcKlSprve6AUT5VODWnkBgTmsOUfbB4jK7O

