--
-- PostgreSQL database dump
--

-- Dumped from database version 16.2
-- Dumped by pg_dump version 16.2

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;

SET default_tablespace = '';

SET default_table_access_method = heap;

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

CREATE TABLE public.accounts (
    id bigint NOT NULL,
    phone text NOT NULL,
    username text,
    display_name text,
    session_file text NOT NULL,
    device_json text,
    proxy_id bigint,
    status text DEFAULT 'offline'::text,
    pool_status text DEFAULT 'offline'::text,
    daily_limit bigint DEFAULT 40,
    daily_sent bigint DEFAULT 0,
    daily_reset_date text,
    resting_until text,
    last_error text,
    project text,
    country text,
    enabled bigint DEFAULT 1,
    created_at text,
    updated_at text,
    spam_status text DEFAULT 'ok'::text,
    spam_until text,
    spam_checked_at text,
    project_id bigint,
    avatar_path text,
    session_auth_total bigint DEFAULT 0,
    session_other_count bigint DEFAULT 0,
    session_has_2fa bigint DEFAULT 0,
    session_2fa_hint text DEFAULT ''::text,
    session_audit_at text,
    session_audit_json text DEFAULT ''::text,
    session_rotate_status text DEFAULT ''::text,
    session_rotate_at text,
    session_rotate_meta text DEFAULT ''::text,
    session_2fa_password text DEFAULT ''::text,
    session_2fa_recovery_email text DEFAULT ''::text,
    sender_persona text DEFAULT 'auto'::text,
    is_premium bigint DEFAULT 0,
    premium_checked_at text,
    tg_id bigint
);


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

CREATE TABLE public.accounts_full (
    id integer NOT NULL,
    phone text NOT NULL,
    username text,
    display_name text,
    session_file text DEFAULT ''::text NOT NULL,
    device_json text,
    proxy_id integer,
    status text DEFAULT 'offline'::text,
    pool_status text DEFAULT 'offline'::text,
    daily_limit integer DEFAULT 40,
    daily_sent integer DEFAULT 0,
    daily_reset_date text,
    resting_until text,
    last_error text,
    project text,
    country text,
    enabled integer DEFAULT 1,
    created_at text,
    updated_at text,
    spam_status text DEFAULT 'ok'::text,
    spam_until text,
    spam_checked_at text,
    project_id integer,
    avatar_path text,
    session_auth_total integer DEFAULT 0,
    session_other_count integer DEFAULT 0,
    session_has_2fa integer DEFAULT 0,
    session_2fa_hint text DEFAULT ''::text,
    session_audit_at text,
    session_audit_json text DEFAULT ''::text,
    session_rotate_status text DEFAULT ''::text,
    session_rotate_at text,
    session_rotate_meta text DEFAULT ''::text,
    session_2fa_password text DEFAULT ''::text,
    session_2fa_recovery_email text DEFAULT ''::text,
    sender_persona text DEFAULT 'auto'::text,
    is_premium integer DEFAULT 0,
    premium_checked_at text,
    tg_id bigint
);


--
-- Name: accounts_full_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE public.accounts_full_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: accounts_full_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE public.accounts_full_id_seq OWNED BY public.accounts_full.id;


--
-- Name: accounts_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

ALTER TABLE public.accounts ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
    SEQUENCE NAME public.accounts_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


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

CREATE TABLE public.agent_training_log (
    id integer NOT NULL,
    session_id text,
    template_id integer,
    template_title text,
    status_before text,
    status_after text,
    technique text,
    client_message text,
    agent_reply text,
    rating text DEFAULT ''::text,
    note text DEFAULT ''::text,
    created_at text NOT NULL,
    job_id integer
);


--
-- Name: agent_training_log_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE public.agent_training_log_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: agent_training_log_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE public.agent_training_log_id_seq OWNED BY public.agent_training_log.id;


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

CREATE TABLE public.ai_agent_claims (
    account_phone text NOT NULL,
    peer_id bigint NOT NULL,
    expires_at text NOT NULL,
    created_at text NOT NULL
);


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

CREATE TABLE public.ai_agent_log (
    account_phone text NOT NULL,
    peer_id bigint NOT NULL,
    last_reply_at text NOT NULL
);


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

CREATE TABLE public.autoresponder_log (
    account_phone text NOT NULL,
    peer_id bigint NOT NULL,
    scope_key text DEFAULT 'global'::text NOT NULL,
    incoming_tg_id bigint NOT NULL,
    trigger_status text DEFAULT 'new'::text NOT NULL,
    template_id bigint,
    sent_at text NOT NULL,
    status text DEFAULT 'sent'::text NOT NULL,
    error_text text
);


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

CREATE TABLE public.broadcast_jobs (
    id bigint NOT NULL,
    name text,
    text text NOT NULL,
    status text DEFAULT 'draft'::text,
    delay_min bigint DEFAULT 35,
    delay_max bigint DEFAULT 55,
    sent_count bigint DEFAULT 0,
    failed_count bigint DEFAULT 0,
    total_count bigint DEFAULT 0,
    created_at text,
    started_at text,
    finished_at text,
    last_error text,
    randomize_text bigint DEFAULT 1,
    parallel_workers bigint DEFAULT 5,
    messages_per_account bigint DEFAULT 0,
    project_ids text DEFAULT ''::text,
    max_accounts bigint DEFAULT 0,
    account_phones text DEFAULT ''::text,
    content_type text DEFAULT 'text'::text,
    recipient_source text DEFAULT 'manual'::text,
    parsed_base_id bigint,
    delete_after_send bigint DEFAULT 0,
    silent_send bigint DEFAULT 0,
    hide_author bigint DEFAULT 0,
    daily_limit bigint DEFAULT 0,
    auto_stop_percent bigint DEFAULT 0,
    batch_size bigint DEFAULT 3,
    post_links text DEFAULT ''::text,
    autoreply_enabled bigint DEFAULT 0,
    autoreply_template_id bigint,
    use_sales_playbook bigint,
    sales_learning_auto_apply_safe bigint DEFAULT 0,
    funnel_start_status text DEFAULT 'new'::text
);


--
-- Name: broadcast_jobs_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

ALTER TABLE public.broadcast_jobs ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
    SEQUENCE NAME public.broadcast_jobs_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


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

CREATE TABLE public.broadcast_logs (
    id bigint NOT NULL,
    job_id bigint NOT NULL,
    log_level text DEFAULT 'info'::text,
    message text NOT NULL,
    created_at text
);


--
-- Name: broadcast_logs_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

ALTER TABLE public.broadcast_logs ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
    SEQUENCE NAME public.broadcast_logs_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


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

CREATE TABLE public.broadcast_recipients (
    id bigint NOT NULL,
    job_id bigint NOT NULL,
    target text NOT NULL,
    account_phone text,
    status text DEFAULT 'pending'::text,
    error text,
    sent_at text,
    peer_id bigint,
    sent_text text,
    phone_number text,
    recipient_kind text DEFAULT 'username'::text,
    parser_job_id bigint,
    parser_user_id bigint,
    ai_reason text,
    claimed_at text
);


--
-- Name: broadcast_recipients_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

ALTER TABLE public.broadcast_recipients ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
    SEQUENCE NAME public.broadcast_recipients_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


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

CREATE TABLE public.chat_leads (
    account_phone text NOT NULL,
    peer_id bigint NOT NULL,
    status text DEFAULT 'new'::text,
    note text,
    updated_at text,
    autoreply_enabled bigint,
    autoreply_template_id bigint,
    status_updated_at text,
    ai_context text,
    ai_context_source text,
    ai_context_updated_at text,
    lead_starred bigint DEFAULT 0,
    last_autoreply_error text,
    last_autoreply_error_at text,
    is_blocked integer DEFAULT 0,
    is_contact integer DEFAULT 0
);


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

CREATE TABLE public.chat_outbox_read (
    account_phone text NOT NULL,
    peer_id bigint NOT NULL,
    read_outbox_max_id bigint DEFAULT 0 NOT NULL,
    updated_at text
);


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

CREATE TABLE public.chat_read_state (
    account_phone text NOT NULL,
    peer_id bigint NOT NULL,
    last_read_iso text NOT NULL,
    last_read_msg_id bigint DEFAULT 0 NOT NULL
);


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

CREATE TABLE public.deleted_chats (
    account_phone text NOT NULL,
    peer_id bigint NOT NULL,
    deleted_at text NOT NULL
);


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

CREATE TABLE public.job_account_stats (
    job_id bigint NOT NULL,
    account_phone text NOT NULL,
    sent_count bigint DEFAULT 0
);


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

CREATE TABLE public.job_autoreply_rules (
    id bigint NOT NULL,
    job_id bigint NOT NULL,
    template_id bigint NOT NULL,
    trigger_status text DEFAULT 'new'::text NOT NULL,
    enabled bigint DEFAULT 1,
    created_at text,
    updated_at text
);


--
-- Name: job_autoreply_rules_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

ALTER TABLE public.job_autoreply_rules ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
    SEQUENCE NAME public.job_autoreply_rules_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


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

CREATE TABLE public.job_lead_statuses (
    id bigint NOT NULL,
    job_id bigint NOT NULL,
    status_key text NOT NULL,
    title text DEFAULT ''::text NOT NULL,
    color text DEFAULT '#b8a8ff'::text,
    type text DEFAULT ''::text,
    description text DEFAULT ''::text
);


--
-- Name: job_lead_statuses_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

ALTER TABLE public.job_lead_statuses ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
    SEQUENCE NAME public.job_lead_statuses_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


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

CREATE TABLE public.job_transition_rules (
    id bigint NOT NULL,
    job_id bigint NOT NULL,
    from_status text NOT NULL,
    condition_text text DEFAULT ''::text NOT NULL,
    to_status text NOT NULL,
    sort_order bigint DEFAULT 0,
    created_at text,
    updated_at text
);


--
-- Name: job_transition_rules_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

ALTER TABLE public.job_transition_rules ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
    SEQUENCE NAME public.job_transition_rules_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


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

CREATE TABLE public.leads (
    account_id bigint NOT NULL,
    peer_id bigint NOT NULL,
    status text DEFAULT 'new'::text NOT NULL,
    starred boolean DEFAULT false NOT NULL,
    notes text,
    ai_context text,
    ai_context_source text,
    updated_at timestamp with time zone DEFAULT now() NOT NULL
);


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

CREATE TABLE public.messages (
    id bigint NOT NULL,
    account_phone text NOT NULL,
    tg_message_id bigint NOT NULL,
    peer_id bigint NOT NULL,
    peer_username text,
    peer_name text,
    text text,
    is_outgoing bigint DEFAULT 0,
    broadcast_job_id bigint,
    date_iso text NOT NULL,
    media_type text,
    media_duration bigint DEFAULT 0,
    media_mime text,
    reply_markup_json text
);


--
-- Name: messages_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

ALTER TABLE public.messages ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
    SEQUENCE NAME public.messages_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


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

CREATE TABLE public.parsed_messages (
    id bigint NOT NULL,
    job_id bigint NOT NULL,
    tg_message_id bigint NOT NULL,
    tg_user_id bigint,
    username text,
    first_name text,
    last_name text,
    message_text text,
    reply_to_message_id bigint,
    message_date text,
    message_order bigint DEFAULT 0,
    is_forwarded bigint DEFAULT 0,
    media_type text,
    media_file_id text,
    media_local_path text
);


--
-- Name: parsed_messages_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

ALTER TABLE public.parsed_messages ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
    SEQUENCE NAME public.parsed_messages_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


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

CREATE TABLE public.parser_jobs (
    id bigint NOT NULL,
    account_id bigint NOT NULL,
    status text DEFAULT 'pending'::text,
    group_link text NOT NULL,
    group_title text,
    group_id text,
    already_member bigint DEFAULT 1,
    limit_messages bigint DEFAULT 0,
    delay_seconds double precision DEFAULT 0.5,
    no_delay bigint DEFAULT 0,
    use_proxy bigint DEFAULT 1,
    auto_proxy_switch bigint DEFAULT 1,
    source_type text DEFAULT 'group'::text,
    parse_mode text DEFAULT 'members'::text,
    date_from text,
    date_to text,
    exclude_bots bigint DEFAULT 1,
    exclude_admins bigint DEFAULT 0,
    activity_filter text DEFAULT 'all'::text,
    topic_link text,
    total_messages bigint DEFAULT 0,
    total_users bigint DEFAULT 0,
    users_with_username bigint DEFAULT 0,
    no_author_count bigint DEFAULT 0,
    progress_percent bigint DEFAULT 0,
    current_status text,
    error_message text,
    recipient_base_id bigint,
    created_at text,
    started_at text,
    completed_at text,
    ai_prompt text,
    ai_parse_batch_done bigint DEFAULT 0,
    ai_collect_done bigint DEFAULT 0
);


--
-- Name: parser_jobs_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

ALTER TABLE public.parser_jobs ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
    SEQUENCE NAME public.parser_jobs_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


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

CREATE TABLE public.parser_results (
    id bigint NOT NULL,
    job_id bigint NOT NULL,
    tg_user_id bigint NOT NULL,
    username text,
    first_name text DEFAULT ''::text,
    last_name text DEFAULT ''::text,
    msg_count bigint DEFAULT 0,
    is_bot bigint DEFAULT 0,
    is_admin bigint DEFAULT 0,
    ai_reason text,
    profile_bio text,
    ai_messages text
);


--
-- Name: parser_results_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

ALTER TABLE public.parser_results ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
    SEQUENCE NAME public.parser_results_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


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

CREATE TABLE public.peer_access (
    account_phone text NOT NULL,
    peer_id bigint NOT NULL,
    access_hash bigint NOT NULL,
    username text,
    updated_at text NOT NULL
);


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

CREATE TABLE public.profile_templates (
    id bigint NOT NULL,
    first_name text NOT NULL,
    last_name text DEFAULT ''::text,
    status_text text DEFAULT ''::text,
    avatar_path text,
    source text DEFAULT 'manual'::text,
    notes text DEFAULT ''::text,
    used_count bigint DEFAULT 0,
    last_used_at text,
    created_at text,
    updated_at text
);


--
-- Name: profile_templates_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

ALTER TABLE public.profile_templates ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
    SEQUENCE NAME public.profile_templates_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


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

CREATE TABLE public.projects (
    id bigint NOT NULL,
    name text NOT NULL,
    country text,
    description text,
    created_at text
);


--
-- Name: projects_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

ALTER TABLE public.projects ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
    SEQUENCE NAME public.projects_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


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

CREATE TABLE public.proxies (
    id bigint NOT NULL,
    host text NOT NULL,
    port bigint NOT NULL,
    proxy_type text DEFAULT 'socks5'::text,
    username text,
    password text,
    country text,
    is_active bigint DEFAULT 1,
    fail_count bigint DEFAULT 0,
    group_id bigint DEFAULT 0 NOT NULL,
    last_error text,
    last_fail_at text
);


--
-- Name: proxies_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

ALTER TABLE public.proxies ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
    SEQUENCE NAME public.proxies_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


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

CREATE TABLE public.proxy_groups (
    id bigint NOT NULL,
    name text NOT NULL,
    country text,
    description text,
    created_at text
);


--
-- Name: proxy_groups_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

ALTER TABLE public.proxy_groups ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
    SEQUENCE NAME public.proxy_groups_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


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

CREATE TABLE public.recipient_base_items (
    id bigint NOT NULL,
    base_id bigint NOT NULL,
    target text NOT NULL,
    phone_number text,
    recipient_kind text DEFAULT 'username'::text,
    parser_job_id bigint,
    parser_user_id bigint,
    ai_reason text
);


--
-- Name: recipient_base_items_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

ALTER TABLE public.recipient_base_items ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
    SEQUENCE NAME public.recipient_base_items_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


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

CREATE TABLE public.recipient_bases (
    id bigint NOT NULL,
    name text NOT NULL,
    source text DEFAULT 'manual'::text,
    item_count bigint DEFAULT 0,
    created_at text
);


--
-- Name: recipient_bases_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

ALTER TABLE public.recipient_bases ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
    SEQUENCE NAME public.recipient_bases_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


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

CREATE TABLE public.reply_templates (
    id bigint NOT NULL,
    title text NOT NULL,
    text text NOT NULL,
    ai_prompt text DEFAULT ''::text,
    ar_trigger_status text DEFAULT 'new'::text,
    ar_after_status text DEFAULT ''::text,
    ar_enabled bigint DEFAULT 0,
    ar_scope text DEFAULT 'none'::text,
    ar_mode text DEFAULT 'text'::text,
    use_sales_playbook bigint DEFAULT 0,
    job_id bigint
);


--
-- Name: reply_templates_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

ALTER TABLE public.reply_templates ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
    SEQUENCE NAME public.reply_templates_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


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

CREATE TABLE public.sales_classifier_markers (
    id bigint NOT NULL,
    phrase text NOT NULL,
    normalized_phrase text NOT NULL,
    objection_type text DEFAULT 'other'::text NOT NULL,
    intent text DEFAULT 'other'::text NOT NULL,
    recommended_action text DEFAULT 'continue'::text NOT NULL,
    scope text DEFAULT 'global'::text NOT NULL,
    category text,
    job_id bigint,
    source text DEFAULT 'manual'::text NOT NULL,
    confidence_score double precision DEFAULT 0.8,
    is_active bigint DEFAULT 1,
    created_at text,
    updated_at text
);


--
-- Name: sales_classifier_markers_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

ALTER TABLE public.sales_classifier_markers ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
    SEQUENCE NAME public.sales_classifier_markers_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


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

CREATE TABLE public.sales_learning_recommendations (
    id bigint NOT NULL,
    source text DEFAULT 'dialogues_analysis'::text NOT NULL,
    scope text DEFAULT 'global'::text NOT NULL,
    job_id bigint,
    category text,
    type text NOT NULL,
    payload_json text DEFAULT '{}'::text NOT NULL,
    status text DEFAULT 'pending'::text NOT NULL,
    created_at text,
    reviewed_at text
);


--
-- Name: sales_learning_recommendations_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

ALTER TABLE public.sales_learning_recommendations ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
    SEQUENCE NAME public.sales_learning_recommendations_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


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

CREATE TABLE public.sales_learning_runs (
    id bigint NOT NULL,
    source text DEFAULT 'dialogues_analysis'::text NOT NULL,
    scope text DEFAULT 'global'::text NOT NULL,
    job_id bigint,
    category text,
    total_dialogues bigint DEFAULT 0,
    total_messages bigint DEFAULT 0,
    status text DEFAULT 'done'::text NOT NULL,
    summary_json text DEFAULT '{}'::text NOT NULL,
    warning text DEFAULT ''::text,
    created_at text,
    raw_result_json text DEFAULT '{}'::text
);


--
-- Name: sales_learning_runs_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

ALTER TABLE public.sales_learning_runs ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
    SEQUENCE NAME public.sales_learning_runs_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


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

CREATE TABLE public.sales_playbook_items (
    id bigint NOT NULL,
    scope text DEFAULT 'global'::text NOT NULL,
    category text,
    title text NOT NULL,
    situation text DEFAULT ''::text NOT NULL,
    objection_type text DEFAULT ''::text NOT NULL,
    funnel_stage text DEFAULT ''::text NOT NULL,
    recommended_strategy text DEFAULT ''::text NOT NULL,
    response_formula text DEFAULT ''::text NOT NULL,
    response_template text DEFAULT ''::text NOT NULL,
    do_say text DEFAULT '[]'::text NOT NULL,
    dont_say text DEFAULT '[]'::text NOT NULL,
    examples_good text DEFAULT '[]'::text NOT NULL,
    examples_bad text DEFAULT '[]'::text NOT NULL,
    psychological_principles text DEFAULT '[]'::text NOT NULL,
    ethical_boundaries text DEFAULT '[]'::text NOT NULL,
    confidence_score double precision DEFAULT 0.8,
    review_status text DEFAULT 'pending'::text NOT NULL,
    is_active bigint DEFAULT 1,
    created_at text,
    updated_at text
);


--
-- Name: sales_playbook_items_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

ALTER TABLE public.sales_playbook_items ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
    SEQUENCE NAME public.sales_playbook_items_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


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

CREATE TABLE public.settings (
    key text NOT NULL,
    value text NOT NULL
);


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

CREATE TABLE public.settings_kv (
    key text NOT NULL,
    value text NOT NULL
);


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

CREATE TABLE public.threads (
    account_id bigint NOT NULL,
    peer_id bigint NOT NULL,
    title text,
    peer_username text,
    last_message_at timestamp with time zone,
    updated_at timestamp with time zone DEFAULT now() NOT NULL
);


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

CREATE TABLE public.warmup_dialogue_messages (
    id bigint NOT NULL,
    dialogue_id bigint NOT NULL,
    seq bigint NOT NULL,
    author_key text NOT NULL,
    text text NOT NULL,
    src_delay_after bigint DEFAULT 0
);


--
-- Name: warmup_dialogue_messages_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

ALTER TABLE public.warmup_dialogue_messages ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
    SEQUENCE NAME public.warmup_dialogue_messages_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


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

CREATE TABLE public.warmup_dialogues (
    id bigint NOT NULL,
    title text NOT NULL,
    source_filename text,
    author_a text NOT NULL,
    author_b text NOT NULL,
    msg_count bigint DEFAULT 0,
    span_seconds bigint DEFAULT 0,
    created_at text NOT NULL
);


--
-- Name: warmup_dialogues_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

ALTER TABLE public.warmup_dialogues ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
    SEQUENCE NAME public.warmup_dialogues_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


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

CREATE TABLE public.warmup_job_log (
    id bigint NOT NULL,
    job_id bigint NOT NULL,
    pair_index bigint NOT NULL,
    phone_from text,
    phone_to text,
    seq bigint,
    text_preview text,
    delay_used double precision,
    ok bigint DEFAULT 1,
    error text,
    created_at text NOT NULL
);


--
-- Name: warmup_job_log_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

ALTER TABLE public.warmup_job_log ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
    SEQUENCE NAME public.warmup_job_log_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


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

CREATE TABLE public.warmup_job_pairs (
    id bigint NOT NULL,
    job_id bigint NOT NULL,
    pair_index bigint NOT NULL,
    phone_a text NOT NULL,
    phone_b text NOT NULL,
    role_swap bigint DEFAULT 0,
    status text DEFAULT 'pending'::text,
    sent_count bigint DEFAULT 0,
    next_seq bigint DEFAULT 1,
    last_error text,
    sent_per_a bigint DEFAULT 0,
    sent_per_b bigint DEFAULT 0
);


--
-- Name: warmup_job_pairs_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

ALTER TABLE public.warmup_job_pairs ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
    SEQUENCE NAME public.warmup_job_pairs_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


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

CREATE TABLE public.warmup_jobs (
    id bigint NOT NULL,
    name text,
    dialogue_id bigint NOT NULL,
    status text DEFAULT 'draft'::text,
    timing_mode text DEFAULT 'delay_range'::text,
    delay_min bigint DEFAULT 35,
    delay_max bigint DEFAULT 180,
    target_duration_sec bigint DEFAULT 0,
    max_messages_per_account bigint DEFAULT 8,
    parallel_pairs bigint DEFAULT 1,
    account_phones text DEFAULT '[]'::text,
    sent_total bigint DEFAULT 0,
    error_total bigint DEFAULT 0,
    started_at text,
    finished_at text,
    last_error text,
    created_at text NOT NULL
);


--
-- Name: warmup_jobs_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

ALTER TABLE public.warmup_jobs ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
    SEQUENCE NAME public.warmup_jobs_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


--
-- Name: accounts_full id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.accounts_full ALTER COLUMN id SET DEFAULT nextval('public.accounts_full_id_seq'::regclass);


--
-- Name: agent_training_log id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.agent_training_log ALTER COLUMN id SET DEFAULT nextval('public.agent_training_log_id_seq'::regclass);


--
-- Name: accounts_full accounts_full_phone_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.accounts_full
    ADD CONSTRAINT accounts_full_phone_key UNIQUE (phone);


--
-- Name: accounts_full accounts_full_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.accounts_full
    ADD CONSTRAINT accounts_full_pkey PRIMARY KEY (id);


--
-- Name: accounts accounts_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.accounts
    ADD CONSTRAINT accounts_pkey PRIMARY KEY (id);


--
-- Name: agent_training_log agent_training_log_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.agent_training_log
    ADD CONSTRAINT agent_training_log_pkey PRIMARY KEY (id);


--
-- Name: ai_agent_claims ai_agent_claims_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.ai_agent_claims
    ADD CONSTRAINT ai_agent_claims_pkey PRIMARY KEY (account_phone, peer_id);


--
-- Name: ai_agent_log ai_agent_log_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.ai_agent_log
    ADD CONSTRAINT ai_agent_log_pkey PRIMARY KEY (account_phone, peer_id);


--
-- Name: autoresponder_log autoresponder_log_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.autoresponder_log
    ADD CONSTRAINT autoresponder_log_pkey PRIMARY KEY (account_phone, peer_id, scope_key, incoming_tg_id);


--
-- Name: broadcast_jobs broadcast_jobs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.broadcast_jobs
    ADD CONSTRAINT broadcast_jobs_pkey PRIMARY KEY (id);


--
-- Name: broadcast_logs broadcast_logs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.broadcast_logs
    ADD CONSTRAINT broadcast_logs_pkey PRIMARY KEY (id);


--
-- Name: broadcast_recipients broadcast_recipients_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.broadcast_recipients
    ADD CONSTRAINT broadcast_recipients_pkey PRIMARY KEY (id);


--
-- Name: chat_leads chat_leads_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.chat_leads
    ADD CONSTRAINT chat_leads_pkey PRIMARY KEY (account_phone, peer_id);


--
-- Name: chat_outbox_read chat_outbox_read_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.chat_outbox_read
    ADD CONSTRAINT chat_outbox_read_pkey PRIMARY KEY (account_phone, peer_id);


--
-- Name: chat_read_state chat_read_state_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.chat_read_state
    ADD CONSTRAINT chat_read_state_pkey PRIMARY KEY (account_phone, peer_id);


--
-- Name: deleted_chats deleted_chats_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.deleted_chats
    ADD CONSTRAINT deleted_chats_pkey PRIMARY KEY (account_phone, peer_id);


--
-- Name: job_account_stats job_account_stats_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.job_account_stats
    ADD CONSTRAINT job_account_stats_pkey PRIMARY KEY (job_id, account_phone);


--
-- Name: job_autoreply_rules job_autoreply_rules_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.job_autoreply_rules
    ADD CONSTRAINT job_autoreply_rules_pkey PRIMARY KEY (id);


--
-- Name: job_lead_statuses job_lead_statuses_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.job_lead_statuses
    ADD CONSTRAINT job_lead_statuses_pkey PRIMARY KEY (id);


--
-- Name: job_transition_rules job_transition_rules_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.job_transition_rules
    ADD CONSTRAINT job_transition_rules_pkey PRIMARY KEY (id);


--
-- Name: leads leads_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.leads
    ADD CONSTRAINT leads_pkey PRIMARY KEY (account_id, peer_id);


--
-- Name: messages messages_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.messages
    ADD CONSTRAINT messages_pkey PRIMARY KEY (id);


--
-- Name: parsed_messages parsed_messages_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.parsed_messages
    ADD CONSTRAINT parsed_messages_pkey PRIMARY KEY (id);


--
-- Name: parser_jobs parser_jobs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.parser_jobs
    ADD CONSTRAINT parser_jobs_pkey PRIMARY KEY (id);


--
-- Name: parser_results parser_results_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.parser_results
    ADD CONSTRAINT parser_results_pkey PRIMARY KEY (id);


--
-- Name: peer_access peer_access_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.peer_access
    ADD CONSTRAINT peer_access_pkey PRIMARY KEY (account_phone, peer_id);


--
-- Name: profile_templates profile_templates_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.profile_templates
    ADD CONSTRAINT profile_templates_pkey PRIMARY KEY (id);


--
-- Name: projects projects_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.projects
    ADD CONSTRAINT projects_pkey PRIMARY KEY (id);


--
-- Name: proxies proxies_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.proxies
    ADD CONSTRAINT proxies_pkey PRIMARY KEY (id);


--
-- Name: proxy_groups proxy_groups_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.proxy_groups
    ADD CONSTRAINT proxy_groups_pkey PRIMARY KEY (id);


--
-- Name: recipient_base_items recipient_base_items_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.recipient_base_items
    ADD CONSTRAINT recipient_base_items_pkey PRIMARY KEY (id);


--
-- Name: recipient_bases recipient_bases_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.recipient_bases
    ADD CONSTRAINT recipient_bases_pkey PRIMARY KEY (id);


--
-- Name: reply_templates reply_templates_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.reply_templates
    ADD CONSTRAINT reply_templates_pkey PRIMARY KEY (id);


--
-- Name: sales_classifier_markers sales_classifier_markers_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.sales_classifier_markers
    ADD CONSTRAINT sales_classifier_markers_pkey PRIMARY KEY (id);


--
-- Name: sales_learning_recommendations sales_learning_recommendations_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.sales_learning_recommendations
    ADD CONSTRAINT sales_learning_recommendations_pkey PRIMARY KEY (id);


--
-- Name: sales_learning_runs sales_learning_runs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.sales_learning_runs
    ADD CONSTRAINT sales_learning_runs_pkey PRIMARY KEY (id);


--
-- Name: sales_playbook_items sales_playbook_items_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.sales_playbook_items
    ADD CONSTRAINT sales_playbook_items_pkey PRIMARY KEY (id);


--
-- Name: settings_kv settings_kv_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.settings_kv
    ADD CONSTRAINT settings_kv_pkey PRIMARY KEY (key);


--
-- Name: settings settings_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.settings
    ADD CONSTRAINT settings_pkey PRIMARY KEY (key);


--
-- Name: threads threads_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.threads
    ADD CONSTRAINT threads_pkey PRIMARY KEY (account_id, peer_id);


--
-- Name: warmup_dialogue_messages warmup_dialogue_messages_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.warmup_dialogue_messages
    ADD CONSTRAINT warmup_dialogue_messages_pkey PRIMARY KEY (id);


--
-- Name: warmup_dialogues warmup_dialogues_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.warmup_dialogues
    ADD CONSTRAINT warmup_dialogues_pkey PRIMARY KEY (id);


--
-- Name: warmup_job_log warmup_job_log_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.warmup_job_log
    ADD CONSTRAINT warmup_job_log_pkey PRIMARY KEY (id);


--
-- Name: warmup_job_pairs warmup_job_pairs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.warmup_job_pairs
    ADD CONSTRAINT warmup_job_pairs_pkey PRIMARY KEY (id);


--
-- Name: warmup_jobs warmup_jobs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.warmup_jobs
    ADD CONSTRAINT warmup_jobs_pkey PRIMARY KEY (id);


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

CREATE INDEX idx_accounts_enabled ON public.accounts USING btree (enabled);


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

CREATE INDEX idx_accounts_full_phone ON public.accounts_full USING btree (phone);


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

CREATE INDEX idx_accounts_full_status ON public.accounts_full USING btree (pool_status);


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

CREATE INDEX idx_accounts_phone ON public.accounts USING btree (phone);


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

CREATE INDEX idx_accounts_pool_status ON public.accounts USING btree (pool_status);


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

CREATE INDEX idx_ai_claims_expires ON public.ai_agent_claims USING btree (expires_at);


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

CREATE INDEX idx_bj_status ON public.broadcast_jobs USING btree (status);


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

CREATE INDEX idx_broadcast_recipients_job_peer ON public.broadcast_recipients USING btree (job_id, account_phone, peer_id, status);


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

CREATE INDEX idx_chat_leads_acc_peer ON public.chat_leads USING btree (account_phone, peer_id);


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

CREATE INDEX idx_chat_outbox_read_acc_peer ON public.chat_outbox_read USING btree (account_phone, peer_id);


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

CREATE INDEX idx_chat_read_state_acc_peer ON public.chat_read_state USING btree (account_phone, peer_id, last_read_msg_id);


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

CREATE INDEX idx_deleted_chats_acc_peer ON public.deleted_chats USING btree (account_phone, peer_id);


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

CREATE INDEX idx_leads_acc_peer ON public.leads USING btree (account_id, peer_id);


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

CREATE INDEX idx_leads_acc_status ON public.leads USING btree (account_id, status);


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

CREATE INDEX idx_leads_status ON public.leads USING btree (status);


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

CREATE INDEX idx_messages_acc_peer_date ON public.messages USING btree (account_phone, peer_id, date_iso DESC);


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

CREATE INDEX idx_messages_acc_peer_id_desc ON public.messages USING btree (account_phone, peer_id, id DESC);


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

CREATE INDEX idx_messages_acc_peer_job ON public.messages USING btree (account_phone, peer_id, broadcast_job_id);


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

CREATE INDEX idx_messages_acc_peer_out_id ON public.messages USING btree (account_phone, peer_id, is_outgoing, id DESC);


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

CREATE INDEX idx_messages_peer_user ON public.messages USING btree (peer_username);


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

CREATE INDEX idx_threads_acc_last ON public.threads USING btree (account_id, last_message_at DESC);


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

CREATE INDEX idx_threads_last ON public.threads USING btree (last_message_at DESC);


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

CREATE INDEX idx_wj_status ON public.warmup_jobs USING btree (status);


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

CREATE INDEX idx_wp_job_status ON public.warmup_job_pairs USING btree (job_id, status);


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

CREATE INDEX idx_wp_phones_a ON public.warmup_job_pairs USING btree (phone_a);


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

CREATE INDEX idx_wp_phones_b ON public.warmup_job_pairs USING btree (phone_b);


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

CREATE INDEX idx_wp_status ON public.warmup_job_pairs USING btree (status);


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

CREATE UNIQUE INDEX uq_accounts_full_phone ON public.accounts_full USING btree (phone);


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

CREATE UNIQUE INDEX uq_accounts_phone ON public.accounts USING btree (phone);


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

CREATE UNIQUE INDEX uq_broadcast_recipients_job_target ON public.broadcast_recipients USING btree (job_id, target);


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

CREATE UNIQUE INDEX uq_chat_leads_phone_peer ON public.chat_leads USING btree (account_phone, peer_id);


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

CREATE UNIQUE INDEX uq_chat_outbox_read_phone_peer ON public.chat_outbox_read USING btree (account_phone, peer_id);


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

CREATE UNIQUE INDEX uq_chat_read_state_phone_peer ON public.chat_read_state USING btree (account_phone, peer_id);


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

CREATE UNIQUE INDEX uq_deleted_chats_phone_peer ON public.deleted_chats USING btree (account_phone, peer_id);


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

CREATE UNIQUE INDEX uq_job_account_stats_job_phone ON public.job_account_stats USING btree (job_id, account_phone);


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

CREATE UNIQUE INDEX uq_job_autoreply_rules_job_trigger ON public.job_autoreply_rules USING btree (job_id, trigger_status);


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

CREATE UNIQUE INDEX uq_job_lead_statuses_job_status ON public.job_lead_statuses USING btree (job_id, status_key);


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

CREATE UNIQUE INDEX uq_messages_phone_msg_peer ON public.messages USING btree (account_phone, tg_message_id, peer_id);


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

CREATE UNIQUE INDEX uq_parsed_messages_job_msg ON public.parsed_messages USING btree (job_id, tg_message_id);


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

CREATE UNIQUE INDEX uq_parser_results_job_user ON public.parser_results USING btree (job_id, tg_user_id);


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

CREATE UNIQUE INDEX uq_peer_access_phone_peer ON public.peer_access USING btree (account_phone, peer_id);


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

CREATE UNIQUE INDEX uq_proxies_host_port_group ON public.proxies USING btree (host, port, group_id);


--
-- PostgreSQL database dump complete
--

