--
-- PostgreSQL database dump
--

\restrict 2lzp0HGi78iMtGdRe0AKt1WUC3N6zN2DAoA5IykMMKEEREzQY7OxeSfr5dPPi01

-- Dumped from database version 16.14 (daf32eb)
-- Dumped by pg_dump version 16.14

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: connectivity_mode_enum; Type: TYPE; Schema: public; Owner: -
--

CREATE TYPE public.connectivity_mode_enum AS ENUM (
    'tns',
    'ssh_sqlplus',
    'both'
);


--
-- Name: purge_old_tns_snapshots(); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION public.purge_old_tns_snapshots() RETURNS void
    LANGUAGE plpgsql
    AS $$
      BEGIN
        DELETE FROM tns_topology_snapshots
        WHERE created_at < NOW() - INTERVAL '30 days';
      END;
      $$;


--
-- Name: trim_agent_diagnose_runs(); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION public.trim_agent_diagnose_runs() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
      BEGIN
        DELETE FROM agent_diagnose_runs
        WHERE connection_id = NEW.connection_id
          AND id NOT IN (
            SELECT id FROM agent_diagnose_runs
            WHERE connection_id = NEW.connection_id
            ORDER BY created_at DESC
            LIMIT 50
          );
        RETURN NEW;
      END;
      $$;


--
-- Name: trim_preflight_runs(); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION public.trim_preflight_runs() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
      BEGIN
        DELETE FROM listener_preflight_runs
        WHERE connection_id = NEW.connection_id
          AND id NOT IN (
            SELECT id FROM listener_preflight_runs
            WHERE connection_id = NEW.connection_id
            ORDER BY created_at DESC
            LIMIT 10
          );
        RETURN NEW;
      END;
      $$;


SET default_tablespace = '';

SET default_table_access_method = heap;

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

CREATE TABLE public._migrations (
    id integer NOT NULL,
    name character varying(255) NOT NULL,
    applied_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP
);


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

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


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

ALTER SEQUENCE public._migrations_id_seq OWNED BY public._migrations.id;


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

CREATE TABLE public.activity_log (
    id bigint NOT NULL,
    company_id character varying(100),
    user_id integer,
    user_email character varying(255),
    user_name character varying(255),
    user_role character varying(50),
    action_type character varying(50) NOT NULL,
    detail jsonb DEFAULT '{}'::jsonb NOT NULL,
    connection_id integer,
    connection_name character varying(255),
    result character varying(20) DEFAULT 'success'::character varying NOT NULL,
    duration_ms integer,
    ip_address character varying(64),
    user_agent character varying(500),
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    company_domain character varying(255)
);


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

CREATE SEQUENCE public.activity_log_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


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

ALTER SEQUENCE public.activity_log_id_seq OWNED BY public.activity_log.id;


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

CREATE TABLE public.addm_runs (
    id integer NOT NULL,
    connection_id integer NOT NULL,
    created_by integer NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    task_name text,
    task_id integer,
    db_id text,
    container text,
    begin_snap_id integer,
    end_snap_id integer,
    begin_snap_time timestamp with time zone,
    end_snap_time timestamp with time zone,
    db_time_seconds numeric,
    avg_active_sessions numeric,
    findings jsonb DEFAULT '[]'::jsonb NOT NULL,
    raw_report_text text,
    ai_commentary text,
    is_idle boolean DEFAULT false NOT NULL,
    run_error text,
    snapshot_ms integer,
    analysis_ms integer,
    total_ms integer
);


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

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


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

ALTER SEQUENCE public.addm_runs_id_seq OWNED BY public.addm_runs.id;


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

CREATE TABLE public.admin_exports (
    id integer NOT NULL,
    export_type text NOT NULL,
    format text DEFAULT 'custom'::text NOT NULL,
    initiated_by text NOT NULL,
    started_at timestamp with time zone DEFAULT now() NOT NULL,
    finished_at timestamp with time zone,
    byte_count bigint,
    duration_ms integer,
    status text DEFAULT 'started'::text NOT NULL,
    error_message text,
    CONSTRAINT admin_exports_export_type_check CHECK ((export_type = ANY (ARRAY['database'::text, 'assets'::text]))),
    CONSTRAINT admin_exports_status_check CHECK ((status = ANY (ARRAY['started'::text, 'completed'::text, 'failed'::text])))
);


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

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


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

ALTER SEQUENCE public.admin_exports_id_seq OWNED BY public.admin_exports.id;


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

CREATE TABLE public.advisor_findings (
    id integer NOT NULL,
    connection_id integer NOT NULL,
    fetched_at timestamp with time zone DEFAULT now() NOT NULL,
    addm_tasks jsonb DEFAULT '[]'::jsonb NOT NULL,
    findings jsonb DEFAULT '[]'::jsonb NOT NULL,
    recommendations jsonb DEFAULT '[]'::jsonb NOT NULL,
    sql_tuning_tasks jsonb DEFAULT '[]'::jsonb NOT NULL,
    ai_summary text,
    licensed boolean DEFAULT true NOT NULL,
    not_licensed_reason text,
    fetch_error text
);


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

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


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

ALTER SEQUENCE public.advisor_findings_id_seq OWNED BY public.advisor_findings.id;


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

CREATE TABLE public.agent_channel_state (
    agent_id integer NOT NULL,
    last_poll_at timestamp with time zone,
    last_heartbeat_at timestamp with time zone,
    pending_command_id text,
    pending_command_payload jsonb,
    pending_command_enqueued_at timestamp with time zone,
    claim_holder text,
    claim_expires_at timestamp with time zone,
    updated_at timestamp with time zone DEFAULT now() NOT NULL
);


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

CREATE TABLE public.agent_command_queue (
    id bigint NOT NULL,
    agent_id integer NOT NULL,
    command_type text DEFAULT 'proxy_request'::text NOT NULL,
    payload jsonb DEFAULT '{}'::jsonb NOT NULL,
    enqueued_at timestamp with time zone DEFAULT now() NOT NULL,
    claimed_at timestamp with time zone,
    claim_holder text,
    claim_expires_at timestamp with time zone,
    completed_at timestamp with time zone,
    status text DEFAULT 'pending'::text NOT NULL,
    result jsonb,
    CONSTRAINT agent_command_queue_status_check CHECK ((status = ANY (ARRAY['pending'::text, 'claimed'::text, 'completed'::text, 'failed'::text])))
);


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

CREATE SEQUENCE public.agent_command_queue_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


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

ALTER SEQUENCE public.agent_command_queue_id_seq OWNED BY public.agent_command_queue.id;


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

CREATE TABLE public.agent_command_results (
    id bigint NOT NULL,
    connection_id integer,
    command character varying(128) NOT NULL,
    output text,
    exit_code integer,
    status character varying(16) DEFAULT 'pending'::character varying NOT NULL,
    requested_by integer,
    requested_at timestamp with time zone DEFAULT now() NOT NULL,
    completed_at timestamp with time zone,
    error_message text
);


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

CREATE SEQUENCE public.agent_command_results_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


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

ALTER SEQUENCE public.agent_command_results_id_seq OWNED BY public.agent_command_results.id;


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

CREATE TABLE public.agent_crash_alerts_sent (
    connection_id integer NOT NULL,
    sent_at timestamp with time zone DEFAULT now() NOT NULL,
    recipient text,
    agent_health character varying(32)
);


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

CREATE TABLE public.agent_diagnose_runs (
    id bigint NOT NULL,
    connection_id integer NOT NULL,
    agent_version character varying(32),
    host text,
    detected_sids text[],
    listener_services text[],
    chosen_service text,
    probes jsonb DEFAULT '[]'::jsonb NOT NULL,
    roundtrip_ms integer,
    overall_status character varying(16) DEFAULT 'pass'::character varying NOT NULL,
    pass_count smallint DEFAULT 0,
    fail_count smallint DEFAULT 0,
    skip_count smallint DEFAULT 0,
    created_at timestamp with time zone DEFAULT now() NOT NULL
);


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

CREATE SEQUENCE public.agent_diagnose_runs_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


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

ALTER SEQUENCE public.agent_diagnose_runs_id_seq OWNED BY public.agent_diagnose_runs.id;


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

CREATE TABLE public.agent_install_failures (
    id bigint NOT NULL,
    connection_id integer,
    host text,
    error_class character varying(64),
    journalctl_tail text,
    install_log_tail text,
    installer_version character varying(16),
    os_info text,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    ip_address inet,
    user_agent text,
    resolved_at timestamp with time zone
);


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

CREATE SEQUENCE public.agent_install_failures_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


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

ALTER SEQUENCE public.agent_install_failures_id_seq OWNED BY public.agent_install_failures.id;


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

CREATE TABLE public.agent_reg_tokens (
    id integer NOT NULL,
    token text NOT NULL,
    connection_id integer NOT NULL,
    user_id integer NOT NULL,
    used boolean DEFAULT false NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    expires_at timestamp with time zone DEFAULT (now() + '00:30:00'::interval) NOT NULL
);


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

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


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

ALTER SEQUENCE public.agent_reg_tokens_id_seq OWNED BY public.agent_reg_tokens.id;


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

CREATE TABLE public.agent_restart_events (
    id bigint NOT NULL,
    connection_id integer NOT NULL,
    reason_code text NOT NULL,
    last_stage_reached text,
    last_error text,
    uptime_seconds integer,
    restart_sequence_id text,
    recorded_at timestamp with time zone DEFAULT now() NOT NULL
);


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

CREATE SEQUENCE public.agent_restart_events_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


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

ALTER SEQUENCE public.agent_restart_events_id_seq OWNED BY public.agent_restart_events.id;


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

CREATE TABLE public.agent_tunnels (
    id integer NOT NULL,
    connection_id integer NOT NULL,
    tunnel_uuid text,
    tunnel_name text,
    dns_hostname text,
    status text DEFAULT 'pending'::text NOT NULL,
    os_info text,
    oracle_home text,
    oracle_sids text[],
    provisioned_at timestamp with time zone,
    confirmed_at timestamp with time zone,
    last_heartbeat timestamp with time zone,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updated_at timestamp with time zone DEFAULT now() NOT NULL,
    agent_version text,
    pdb_services text[] DEFAULT '{}'::text[] NOT NULL,
    agent_status character varying(32) DEFAULT 'starting'::character varying,
    last_oracle_error jsonb,
    oracle_retry_count integer DEFAULT 0,
    uptime_seconds integer,
    oracle_status_at timestamp with time zone,
    oracle_mode character varying(8) DEFAULT 'thin'::character varying,
    instant_client_path text,
    verifier_workaround_active boolean DEFAULT false,
    uninstalled_at timestamp with time zone
);


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

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


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

ALTER SEQUENCE public.agent_tunnels_id_seq OWNED BY public.agent_tunnels.id;


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

CREATE TABLE public.agent_upgrade_audit (
    id bigint NOT NULL,
    connection_id integer NOT NULL,
    from_version text,
    to_version text NOT NULL,
    triggered_by text DEFAULT 'auto-stale-policy'::text NOT NULL,
    triggered_at timestamp with time zone DEFAULT now() NOT NULL,
    completed_at timestamp with time zone,
    status text DEFAULT 'queued'::text NOT NULL,
    error text,
    verification_payload jsonb,
    verification_status text,
    verified_at timestamp with time zone,
    CONSTRAINT agent_upgrade_audit_status_check CHECK ((status = ANY (ARRAY['queued'::text, 'in_progress'::text, 'completed'::text, 'failed'::text])))
);


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

CREATE SEQUENCE public.agent_upgrade_audit_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


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

ALTER SEQUENCE public.agent_upgrade_audit_id_seq OWNED BY public.agent_upgrade_audit.id;


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

CREATE TABLE public.agents_log_buffer (
    id bigint NOT NULL,
    connection_id integer NOT NULL,
    lines text[] DEFAULT '{}'::text[] NOT NULL,
    updated_at timestamp with time zone DEFAULT now() NOT NULL
);


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

CREATE SEQUENCE public.agents_log_buffer_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


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

ALTER SEQUENCE public.agents_log_buffer_id_seq OWNED BY public.agents_log_buffer.id;


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

CREATE TABLE public.alert_events (
    id integer NOT NULL,
    policy_id integer NOT NULL,
    connection_id integer NOT NULL,
    check_run_id integer,
    triggered_at timestamp with time zone DEFAULT now() NOT NULL,
    resolved_at timestamp with time zone,
    acknowledged_at timestamp with time zone,
    acknowledged_by integer,
    current_value text,
    severity text DEFAULT 'warning'::text NOT NULL,
    status text DEFAULT 'triggered'::text NOT NULL,
    escalation_step integer DEFAULT 0 NOT NULL,
    next_escalation_at timestamp with time zone,
    notifications_sent jsonb DEFAULT '[]'::jsonb NOT NULL,
    CONSTRAINT alert_events_status_check CHECK ((status = ANY (ARRAY['triggered'::text, 'acknowledged'::text, 'escalated'::text, 'resolved'::text])))
);


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

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


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

ALTER SEQUENCE public.alert_events_id_seq OWNED BY public.alert_events.id;


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

CREATE TABLE public.alert_policies (
    id integer NOT NULL,
    user_id integer NOT NULL,
    name text NOT NULL,
    check_type text NOT NULL,
    connection_id integer,
    conditions jsonb DEFAULT '[]'::jsonb NOT NULL,
    sustained_minutes integer,
    notification_channels jsonb DEFAULT '[]'::jsonb NOT NULL,
    escalation_chain jsonb DEFAULT '[]'::jsonb NOT NULL,
    is_active boolean DEFAULT true NOT NULL,
    is_default boolean DEFAULT false NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updated_at timestamp with time zone DEFAULT now() NOT NULL
);


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

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


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

ALTER SEQUENCE public.alert_policies_id_seq OWNED BY public.alert_policies.id;


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

CREATE TABLE public.analysis_runs (
    id integer NOT NULL,
    health_check_id integer NOT NULL,
    t0_request_received bigint,
    t1_metrics_written bigint,
    t2_prompt_assembled bigint,
    t3_gpt_call_start bigint,
    t4_gpt_call_returned bigint,
    t5_response_parsed bigint,
    t6_persisted bigint,
    model character varying(64),
    prompt_tokens integer,
    completion_tokens integer,
    total_tokens integer,
    finish_reason character varying(32),
    dur_collect_ms integer,
    dur_prompt_ms integer,
    dur_gpt_ms integer,
    dur_parse_ms integer,
    dur_persist_ms integer,
    dur_total_ms integer,
    outcome character varying(32),
    error_message text,
    retry_log jsonb DEFAULT '[]'::jsonb,
    created_at timestamp with time zone DEFAULT now()
);


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

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


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

ALTER SEQUENCE public.analysis_runs_id_seq OWNED BY public.analysis_runs.id;


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

CREATE TABLE public.analytics_events (
    id integer NOT NULL,
    event_name character varying(100) NOT NULL,
    plan character varying(50),
    check_id integer,
    occurred_at timestamp with time zone DEFAULT now(),
    user_id integer,
    session_id character varying(64),
    page_path character varying(500),
    referrer character varying(500),
    properties jsonb,
    ip character varying(45),
    user_agent text,
    ip_hash character varying(64)
);


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

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


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

ALTER SEQUENCE public.analytics_events_id_seq OWNED BY public.analytics_events.id;


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

CREATE TABLE public.api_keys (
    id integer NOT NULL,
    user_id integer NOT NULL,
    key_prefix character varying(16) NOT NULL,
    key_hash character varying(64) NOT NULL,
    name character varying(100),
    last_used_at timestamp with time zone,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    revoked_at timestamp with time zone
);


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

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


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

ALTER SEQUENCE public.api_keys_id_seq OWNED BY public.api_keys.id;


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

CREATE TABLE public.approval_requests (
    id integer NOT NULL,
    ticket_id integer,
    requester_id integer NOT NULL,
    approver_role_id integer NOT NULL,
    status character varying(20) DEFAULT 'pending'::character varying NOT NULL,
    approved_by integer,
    approved_at timestamp without time zone,
    rejected_at timestamp without time zone,
    rejection_reason text,
    context jsonb DEFAULT '{}'::jsonb,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    CONSTRAINT approval_requests_status_check CHECK (((status)::text = ANY (ARRAY[('pending'::character varying)::text, ('approved'::character varying)::text, ('rejected'::character varying)::text])))
);


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

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


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

ALTER SEQUENCE public.approval_requests_id_seq OWNED BY public.approval_requests.id;


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

CREATE TABLE public.audit_log (
    id bigint NOT NULL,
    occurred_at timestamp with time zone DEFAULT now() NOT NULL,
    user_id integer,
    action text NOT NULL,
    slug text,
    allowed boolean NOT NULL,
    rejection_reason text,
    metadata jsonb DEFAULT '{}'::jsonb NOT NULL
);


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

CREATE SEQUENCE public.audit_log_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


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

ALTER SEQUENCE public.audit_log_id_seq OWNED BY public.audit_log.id;


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

CREATE TABLE public.blog_posts (
    id integer NOT NULL,
    title character varying(500) NOT NULL,
    slug character varying(300) NOT NULL,
    excerpt text NOT NULL,
    content text NOT NULL,
    author character varying(255) DEFAULT 'TuneVault Team'::character varying NOT NULL,
    published_at timestamp with time zone NOT NULL,
    read_time_minutes integer DEFAULT 5 NOT NULL,
    seo_noindex boolean DEFAULT false NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updated_at timestamp with time zone DEFAULT now() NOT NULL,
    coming_soon boolean DEFAULT false
);


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

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


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

ALTER SEQUENCE public.blog_posts_id_seq OWNED BY public.blog_posts.id;


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

CREATE TABLE public.check_failure_bundles (
    id bigint NOT NULL,
    check_id text,
    connection_id integer,
    user_id integer,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    source text DEFAULT 'health_check'::text NOT NULL,
    sql_text text,
    bind_values_redacted_json jsonb,
    ora_error_code text,
    ora_error_message text,
    python_traceback text,
    proxy_log_tail text,
    node_stack text,
    connection_profile_redacted_json jsonb,
    agent_version text,
    oracle_version text,
    cx_oracle_version text,
    os_release text,
    context_json jsonb,
    CONSTRAINT check_failure_bundles_source_check CHECK ((source = ANY (ARRAY['health_check'::text, 'validation_suite'::text, 'ssh_exec'::text, 'proxy'::text])))
);


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

CREATE SEQUENCE public.check_failure_bundles_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


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

ALTER SEQUENCE public.check_failure_bundles_id_seq OWNED BY public.check_failure_bundles.id;


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

CREATE TABLE public.check_results (
    id bigint NOT NULL,
    connection_id integer NOT NULL,
    run_id uuid NOT NULL,
    check_id text NOT NULL,
    check_category text NOT NULL,
    status text NOT NULL,
    metric_name text,
    metric_value numeric,
    metric_unit text,
    raw_payload jsonb DEFAULT '{}'::jsonb NOT NULL,
    ai_summary text,
    recommendation text,
    executed_at timestamp with time zone DEFAULT now() NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL
);


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

CREATE SEQUENCE public.check_results_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


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

ALTER SEQUENCE public.check_results_id_seq OWNED BY public.check_results.id;


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

CREATE TABLE public.checks_catalogue (
    id integer NOT NULL,
    check_id text NOT NULL,
    category text NOT NULL,
    name text NOT NULL,
    description text NOT NULL,
    sql_or_command text NOT NULL,
    severity_thresholds jsonb DEFAULT '{}'::jsonb NOT NULL,
    remediation_hint text,
    requires jsonb DEFAULT '[]'::jsonb NOT NULL,
    status text DEFAULT 'experimental'::text NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updated_at timestamp with time zone DEFAULT now() NOT NULL,
    CONSTRAINT checks_catalogue_status_check CHECK ((status = ANY (ARRAY['production'::text, 'experimental'::text, 'needs_validation'::text])))
);


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

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


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

ALTER SEQUENCE public.checks_catalogue_id_seq OWNED BY public.checks_catalogue.id;


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

CREATE TABLE public.clone_history (
    id integer NOT NULL,
    recipe_id integer,
    company_id character varying(255),
    source_connection_id integer,
    target_connection_id integer,
    started_by integer,
    started_at timestamp without time zone DEFAULT now() NOT NULL,
    completed_at timestamp without time zone,
    status character varying(20) DEFAULT 'running'::character varying NOT NULL,
    current_step integer DEFAULT 0,
    total_steps integer DEFAULT 0,
    step_results jsonb DEFAULT '[]'::jsonb NOT NULL,
    error_message text,
    duration_ms integer,
    CONSTRAINT clone_history_status_check CHECK (((status)::text = ANY (ARRAY[('running'::character varying)::text, ('success'::character varying)::text, ('failed'::character varying)::text, ('aborted'::character varying)::text])))
);


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

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


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

ALTER SEQUENCE public.clone_history_id_seq OWNED BY public.clone_history.id;


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

CREATE TABLE public.clone_recipes (
    id integer NOT NULL,
    company_id character varying(255),
    source_connection_id integer,
    target_connection_id integer,
    recipe_name character varying(255) NOT NULL,
    pre_checks_config jsonb DEFAULT '{}'::jsonb NOT NULL,
    clone_steps jsonb DEFAULT '[]'::jsonb NOT NULL,
    post_steps jsonb DEFAULT '[]'::jsonb NOT NULL,
    created_by integer,
    last_run_at timestamp without time zone,
    last_run_status character varying(20),
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL,
    CONSTRAINT clone_recipes_last_run_status_check CHECK (((last_run_status)::text = ANY (ARRAY[('success'::character varying)::text, ('failed'::character varying)::text, ('partial'::character varying)::text, ('running'::character varying)::text])))
);


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

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


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

ALTER SEQUENCE public.clone_recipes_id_seq OWNED BY public.clone_recipes.id;


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

CREATE TABLE public.company_hc_usage (
    id integer NOT NULL,
    company_domain character varying(255) NOT NULL,
    hc_count integer DEFAULT 0 NOT NULL,
    first_run_at timestamp with time zone DEFAULT now(),
    last_run_at timestamp with time zone DEFAULT now()
);


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

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


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

ALTER SEQUENCE public.company_hc_usage_id_seq OWNED BY public.company_hc_usage.id;


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

CREATE TABLE public.compliance_reports (
    id integer NOT NULL,
    user_id integer NOT NULL,
    report_type text NOT NULL,
    title text NOT NULL,
    date_from date NOT NULL,
    date_to date NOT NULL,
    generated_at timestamp with time zone DEFAULT now() NOT NULL,
    generated_by text NOT NULL,
    generated_data jsonb DEFAULT '{}'::jsonb NOT NULL,
    row_counts jsonb DEFAULT '{}'::jsonb NOT NULL,
    status text DEFAULT 'completed'::text NOT NULL,
    error_message text,
    company_domain character varying(255) NOT NULL,
    CONSTRAINT compliance_reports_report_type_check CHECK ((report_type = ANY (ARRAY['sox_change'::text, 'access_audit'::text, 'activity_summary'::text, 'security_posture'::text, 'resilience'::text]))),
    CONSTRAINT compliance_reports_status_check CHECK ((status = ANY (ARRAY['completed'::text, 'failed'::text])))
);


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

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


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

ALTER SEQUENCE public.compliance_reports_id_seq OWNED BY public.compliance_reports.id;


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

CREATE TABLE public.connection_health_runs (
    id integer NOT NULL,
    connection_id integer NOT NULL,
    ran_at timestamp with time zone DEFAULT now() NOT NULL,
    probe_1_status text,
    probe_1_ms integer,
    probe_1_detail text,
    probe_2_status text,
    probe_2_ms integer,
    probe_2_detail text,
    probe_3_status text,
    probe_3_ms integer,
    probe_3_detail text,
    probe_4_status text,
    probe_4_ms integer,
    probe_4_detail text,
    probe_5_status text,
    probe_5_ms integer,
    probe_5_detail text,
    probe_6_status text,
    probe_6_ms integer,
    probe_6_detail text,
    passed integer DEFAULT 0 NOT NULL,
    total integer DEFAULT 7 NOT NULL,
    agent_version text,
    agent_uptime_s integer,
    trigger text DEFAULT 'manual'::text NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    probe_7_status text,
    probe_7_ms integer,
    probe_7_detail text,
    probe_8_status text,
    probe_8_ms integer,
    probe_8_detail text,
    CONSTRAINT connection_health_runs_probe_1_status_check CHECK ((probe_1_status = ANY (ARRAY['pass'::text, 'fail'::text, 'skip'::text]))),
    CONSTRAINT connection_health_runs_probe_2_status_check CHECK ((probe_2_status = ANY (ARRAY['pass'::text, 'fail'::text, 'skip'::text]))),
    CONSTRAINT connection_health_runs_probe_3_status_check CHECK ((probe_3_status = ANY (ARRAY['pass'::text, 'fail'::text, 'skip'::text]))),
    CONSTRAINT connection_health_runs_probe_4_status_check CHECK ((probe_4_status = ANY (ARRAY['pass'::text, 'fail'::text, 'skip'::text]))),
    CONSTRAINT connection_health_runs_probe_5_status_check CHECK ((probe_5_status = ANY (ARRAY['pass'::text, 'fail'::text, 'skip'::text]))),
    CONSTRAINT connection_health_runs_probe_6_status_check CHECK ((probe_6_status = ANY (ARRAY['pass'::text, 'fail'::text, 'skip'::text]))),
    CONSTRAINT connection_health_runs_probe_7_status_check CHECK ((probe_7_status = ANY (ARRAY['pass'::text, 'fail'::text, 'skip'::text]))),
    CONSTRAINT connection_health_runs_probe_8_status_check CHECK ((probe_8_status = ANY (ARRAY['pass'::text, 'fail'::text, 'skip'::text]))),
    CONSTRAINT connection_health_runs_trigger_check CHECK ((trigger = ANY (ARRAY['sweeper'::text, 'manual'::text])))
);


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

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


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

ALTER SEQUENCE public.connection_health_runs_id_seq OWNED BY public.connection_health_runs.id;


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

CREATE TABLE public.connection_schedules (
    id integer NOT NULL,
    connection_id integer NOT NULL,
    user_id integer NOT NULL,
    cadence_minutes integer DEFAULT 240 NOT NULL,
    enabled boolean DEFAULT false NOT NULL,
    next_run_at timestamp with time zone,
    last_run_at timestamp with time zone,
    alert_email text NOT NULL,
    severity_threshold text DEFAULT 'amber'::text NOT NULL,
    last_alert_sent_at timestamp with time zone,
    last_alert_subject text,
    snoozed_until timestamp with time zone,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updated_at timestamp with time zone DEFAULT now() NOT NULL
);


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

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


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

ALTER SEQUENCE public.connection_schedules_id_seq OWNED BY public.connection_schedules.id;


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

CREATE TABLE public.connection_ssh_profiles (
    id integer NOT NULL,
    connection_id integer NOT NULL,
    role character varying(32) DEFAULT 'db_host'::character varying NOT NULL,
    ssh_host character varying(253) NOT NULL,
    ssh_port integer DEFAULT 22 NOT NULL,
    ssh_user character varying(128) DEFAULT 'oracle'::character varying NOT NULL,
    auth_method character varying(32) DEFAULT 'agent_forward'::character varying NOT NULL,
    ssh_key_encrypted text,
    ssh_key_fingerprint character varying(128),
    bastion_host character varying(253),
    bastion_port integer DEFAULT 22,
    bastion_user character varying(128),
    bastion_key_encrypted text,
    known_hosts_pin character varying(256),
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updated_at timestamp with time zone DEFAULT now() NOT NULL,
    last_tested_at timestamp with time zone,
    last_test_status character varying(16),
    CONSTRAINT connection_ssh_profiles_auth_method_check CHECK (((auth_method)::text = ANY (ARRAY[('agent_forward'::character varying)::text, ('key_upload'::character varying)::text, ('password'::character varying)::text]))),
    CONSTRAINT connection_ssh_profiles_last_test_status_check CHECK (((last_test_status)::text = ANY (ARRAY[('pass'::character varying)::text, ('fail'::character varying)::text, ('pending'::character varying)::text]))),
    CONSTRAINT connection_ssh_profiles_role_check CHECK (((role)::text = ANY (ARRAY[('db_host'::character varying)::text, ('apps_tier'::character varying)::text, ('concurrent_tier'::character varying)::text, ('web_tier'::character varying)::text])))
);


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

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


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

ALTER SEQUENCE public.connection_ssh_profiles_id_seq OWNED BY public.connection_ssh_profiles.id;


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

CREATE TABLE public.credential_access_log (
    id uuid DEFAULT gen_random_uuid() NOT NULL,
    connection_id integer NOT NULL,
    credential_type text NOT NULL,
    action text NOT NULL,
    user_id integer,
    accessed_at timestamp with time zone DEFAULT now()
);


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

CREATE TABLE public.demo_runs (
    id integer NOT NULL,
    user_id integer NOT NULL,
    run_date date DEFAULT CURRENT_DATE NOT NULL,
    run_count integer DEFAULT 1 NOT NULL,
    created_at timestamp with time zone DEFAULT now()
);


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

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


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

ALTER SEQUENCE public.demo_runs_id_seq OWNED BY public.demo_runs.id;


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

CREATE TABLE public.ebs_adop_state (
    id integer NOT NULL,
    connection_id integer NOT NULL,
    patching boolean DEFAULT false NOT NULL,
    phase text,
    session_id text,
    started_at timestamp with time zone,
    services_in_patch_mode jsonb DEFAULT '[]'::jsonb NOT NULL,
    source text DEFAULT 'vactive_services_only'::text NOT NULL,
    checked_at timestamp with time zone DEFAULT now() NOT NULL
);


--
-- Name: TABLE ebs_adop_state; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON TABLE public.ebs_adop_state IS 'Latest ADOP patch-cycle state per connection. Upserted on each health-pack sweep. patching=TRUE drives the red banner and op-gating UI.';


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

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


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

ALTER SEQUENCE public.ebs_adop_state_id_seq OWNED BY public.ebs_adop_state.id;


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

CREATE TABLE public.ebs_control_commands (
    id integer NOT NULL,
    slug text NOT NULL,
    label text NOT NULL,
    category text NOT NULL,
    shell_template text NOT NULL,
    requires_context_file boolean DEFAULT false NOT NULL,
    requires_apps_password boolean DEFAULT false NOT NULL,
    risk_level text DEFAULT 'low'::text NOT NULL,
    dry_run_only boolean DEFAULT true NOT NULL,
    description text DEFAULT ''::text NOT NULL,
    expected_effect text DEFAULT ''::text NOT NULL,
    rollback_steps text DEFAULT ''::text NOT NULL,
    CONSTRAINT ebs_control_commands_risk_level_check CHECK ((risk_level = ANY (ARRAY['low'::text, 'medium'::text, 'high'::text])))
);


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

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


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

ALTER SEQUENCE public.ebs_control_commands_id_seq OWNED BY public.ebs_control_commands.id;


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

CREATE TABLE public.ebs_credentials (
    id uuid DEFAULT gen_random_uuid() NOT NULL,
    connection_id integer NOT NULL,
    credential_type text NOT NULL,
    username text NOT NULL,
    encrypted_value text NOT NULL,
    iv text NOT NULL,
    auth_tag text NOT NULL,
    rotated_at timestamp with time zone,
    created_at timestamp with time zone DEFAULT now(),
    CONSTRAINT ebs_credentials_credential_type_check CHECK ((credential_type = ANY (ARRAY['apps'::text, 'system'::text, 'sys'::text, 'weblogic_admin'::text, 'sysadmin_user'::text, 'xml_gateway'::text])))
);


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

CREATE TABLE public.ebs_deep_reports (
    id bigint NOT NULL,
    user_id integer NOT NULL,
    connection_id integer NOT NULL,
    connection_name text DEFAULT ''::text NOT NULL,
    findings_json jsonb DEFAULT '{}'::jsonb NOT NULL,
    ai_analysis text,
    is_demo boolean DEFAULT false NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL
);


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

CREATE SEQUENCE public.ebs_deep_reports_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


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

ALTER SEQUENCE public.ebs_deep_reports_id_seq OWNED BY public.ebs_deep_reports.id;


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

CREATE TABLE public.ebs_jobs (
    id integer NOT NULL,
    connection_id integer NOT NULL,
    op_key text NOT NULL,
    status text DEFAULT 'queued'::text NOT NULL,
    ok boolean,
    stdout text,
    exit_code integer,
    duration_ms integer,
    created_by integer,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    started_at timestamp with time zone,
    finished_at timestamp with time zone,
    log_tail text
);


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

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


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

ALTER SEQUENCE public.ebs_jobs_id_seq OWNED BY public.ebs_jobs.id;


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

CREATE TABLE public.ebs_module_runs (
    id integer NOT NULL,
    connection_id integer NOT NULL,
    run_at timestamp with time zone DEFAULT now() NOT NULL,
    overall_status text NOT NULL,
    modules_json jsonb NOT NULL,
    is_demo boolean DEFAULT false
);


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

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


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

ALTER SEQUENCE public.ebs_module_runs_id_seq OWNED BY public.ebs_module_runs.id;


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

CREATE TABLE public.ebs_sanity_runs (
    id bigint NOT NULL,
    connection_id integer NOT NULL,
    run_at timestamp with time zone DEFAULT now() NOT NULL,
    overall_status text DEFAULT 'unknown'::text NOT NULL,
    findings_json jsonb DEFAULT '[]'::jsonb NOT NULL,
    is_demo boolean DEFAULT false NOT NULL,
    CONSTRAINT ebs_sanity_runs_overall_status_check CHECK ((overall_status = ANY (ARRAY['pass'::text, 'warn'::text, 'fail'::text, 'unknown'::text])))
);


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

CREATE SEQUENCE public.ebs_sanity_runs_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


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

ALTER SEQUENCE public.ebs_sanity_runs_id_seq OWNED BY public.ebs_sanity_runs.id;


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

CREATE TABLE public.ebs_validation_runs (
    id bigint NOT NULL,
    run_at timestamp with time zone DEFAULT now() NOT NULL,
    summary jsonb DEFAULT '{}'::jsonb NOT NULL,
    tests jsonb DEFAULT '[]'::jsonb NOT NULL
);


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

CREATE SEQUENCE public.ebs_validation_runs_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


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

ALTER SEQUENCE public.ebs_validation_runs_id_seq OWNED BY public.ebs_validation_runs.id;


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

CREATE TABLE public.email_drip_state (
    id integer NOT NULL,
    user_id integer NOT NULL,
    sequence_step integer NOT NULL,
    sent_at timestamp with time zone,
    suppressed_at timestamp with time zone,
    suppressed_reason text,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updated_at timestamp with time zone DEFAULT now() NOT NULL,
    CONSTRAINT email_drip_state_sequence_step_check CHECK ((sequence_step = ANY (ARRAY[1, 2, 3])))
);


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

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


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

ALTER SEQUENCE public.email_drip_state_id_seq OWNED BY public.email_drip_state.id;


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

CREATE TABLE public.email_log (
    id bigint NOT NULL,
    user_id integer,
    user_email character varying(255) NOT NULL,
    template character varying(100) NOT NULL,
    hc_id integer,
    status character varying(20) DEFAULT 'sent'::character varying NOT NULL,
    error_message text,
    postmark_message_id character varying(255),
    sent_at timestamp with time zone DEFAULT now() NOT NULL
);


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

CREATE SEQUENCE public.email_log_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


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

ALTER SEQUENCE public.email_log_id_seq OWNED BY public.email_log.id;


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

CREATE TABLE public.finding_history (
    id integer NOT NULL,
    connection_id integer NOT NULL,
    schedule_id integer,
    check_id text NOT NULL,
    finding_key text NOT NULL,
    title text,
    metric_line text,
    remediation text,
    severity text NOT NULL,
    first_seen_at timestamp with time zone DEFAULT now() NOT NULL,
    last_seen_at timestamp with time zone DEFAULT now() NOT NULL,
    resolved_at timestamp with time zone
);


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

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


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

ALTER SEQUENCE public.finding_history_id_seq OWNED BY public.finding_history.id;


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

CREATE TABLE public.fndload_history (
    id bigint NOT NULL,
    user_id integer,
    user_email character varying(255) NOT NULL,
    action character varying(50) NOT NULL,
    source_conn_id integer,
    source_conn_name character varying(255),
    target_conn_id integer,
    target_conn_name character varying(255),
    object_type character varying(100) NOT NULL,
    lct_file character varying(100) NOT NULL,
    object_names text[],
    diff_summary text,
    upload_result jsonb,
    pre_state_ldt text,
    success boolean,
    error_message text,
    executed_at timestamp with time zone DEFAULT now() NOT NULL
);


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

CREATE SEQUENCE public.fndload_history_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


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

ALTER SEQUENCE public.fndload_history_id_seq OWNED BY public.fndload_history.id;


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

CREATE TABLE public.health_check_requests (
    id integer NOT NULL,
    name character varying(255) NOT NULL,
    email character varying(255) NOT NULL,
    company character varying(255) NOT NULL,
    oracle_version character varying(50),
    env_type character varying(100),
    num_databases integer,
    pain_point text,
    status character varying(50) DEFAULT 'new'::character varying,
    created_at timestamp with time zone DEFAULT now(),
    source_url text
);


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

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


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

ALTER SEQUENCE public.health_check_requests_id_seq OWNED BY public.health_check_requests.id;


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

CREATE TABLE public.health_checks (
    id integer NOT NULL,
    connection_name character varying(255) NOT NULL,
    host character varying(255),
    port integer DEFAULT 1521,
    service_name character varying(255),
    status character varying(50) DEFAULT 'pending'::character varying,
    is_demo boolean DEFAULT false,
    metrics jsonb DEFAULT '{}'::jsonb,
    ai_analysis text,
    overall_score integer,
    created_at timestamp with time zone DEFAULT now(),
    completed_at timestamp with time zone,
    user_id integer,
    connection_id integer,
    username character varying(255),
    summary_text text,
    top_action text,
    analysis_progress_ms integer,
    analysis_stage character varying(32),
    ebs_summary text,
    ebs_action text,
    ai_recommendations jsonb
);


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

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


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

ALTER SEQUENCE public.health_checks_id_seq OWNED BY public.health_checks.id;


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

CREATE TABLE public.install_jobs (
    id bigint NOT NULL,
    user_id integer NOT NULL,
    connection_id integer,
    host text NOT NULL,
    ssh_port integer DEFAULT 22 NOT NULL,
    ssh_user text NOT NULL,
    status text DEFAULT 'queued'::text NOT NULL,
    exit_code integer,
    error_message text,
    started_at timestamp with time zone DEFAULT now() NOT NULL,
    finished_at timestamp with time zone,
    duration_ms integer,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    CONSTRAINT install_jobs_status_check CHECK ((status = ANY (ARRAY['queued'::text, 'connecting'::text, 'preflight'::text, 'installing'::text, 'verifying'::text, 'success'::text, 'failed'::text])))
);


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

CREATE SEQUENCE public.install_jobs_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


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

ALTER SEQUENCE public.install_jobs_id_seq OWNED BY public.install_jobs.id;


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

CREATE TABLE public.installer_smoke_runs (
    id bigint NOT NULL,
    run_id text NOT NULL,
    os text NOT NULL,
    trigger_source text DEFAULT 'manual'::text NOT NULL,
    started_at timestamp with time zone DEFAULT now() NOT NULL,
    finished_at timestamp with time zone,
    overall text DEFAULT 'pending'::text NOT NULL,
    step_install_ms integer,
    step_install_ok boolean,
    step_install_err text,
    step_register_ms integer,
    step_register_ok boolean,
    step_register_err text,
    step_heartbeat_ms integer,
    step_heartbeat_ok boolean,
    step_heartbeat_err text,
    step_systemd_ms integer,
    step_systemd_ok boolean,
    step_systemd_err text,
    step_command_ms integer,
    step_command_ok boolean,
    step_command_err text,
    failure_log text,
    results_json jsonb,
    agent_version text,
    install_sha text,
    duration_total_ms integer,
    CONSTRAINT installer_smoke_runs_overall_check CHECK ((overall = ANY (ARRAY['pending'::text, 'pass'::text, 'fail'::text, 'error'::text])))
);


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

CREATE SEQUENCE public.installer_smoke_runs_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


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

ALTER SEQUENCE public.installer_smoke_runs_id_seq OWNED BY public.installer_smoke_runs.id;


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

CREATE TABLE public.installer_smoke_tokens (
    id bigint NOT NULL,
    token text NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    expires_at timestamp with time zone DEFAULT (now() + '00:15:00'::interval) NOT NULL,
    used_at timestamp with time zone,
    run_id text,
    created_by text
);


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

CREATE SEQUENCE public.installer_smoke_tokens_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


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

ALTER SEQUENCE public.installer_smoke_tokens_id_seq OWNED BY public.installer_smoke_tokens.id;


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

CREATE TABLE public.installer_validation_runs (
    id integer NOT NULL,
    run_id text NOT NULL,
    started_at timestamp with time zone DEFAULT now() NOT NULL,
    finished_at timestamp with time zone,
    os text NOT NULL,
    install_sha text,
    agent_version text,
    kernel_version text,
    probe_1_status text,
    probe_1_ms integer,
    probe_1_error text,
    probe_2_status text,
    probe_2_ms integer,
    probe_2_error text,
    probe_3_status text,
    probe_3_ms integer,
    probe_3_error text,
    probe_4_status text,
    probe_4_ms integer,
    probe_4_error text,
    probe_5_status text,
    probe_5_ms integer,
    probe_5_error text,
    probe_6_status text,
    probe_6_ms integer,
    probe_6_error text,
    overall text DEFAULT 'pending'::text NOT NULL,
    duration_total_ms integer,
    trigger_source text DEFAULT 'cron'::text NOT NULL,
    error_message text,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    probe_7_status text,
    probe_7_ms integer,
    probe_7_error text,
    topology text,
    checks_passed integer,
    checks_total integer,
    ssh_runbook_executed boolean DEFAULT false NOT NULL,
    CONSTRAINT installer_validation_runs_os_check CHECK ((os = ANY (ARRAY['ol7'::text, 'ol8'::text, 'ebs12210'::text]))),
    CONSTRAINT installer_validation_runs_overall_check CHECK ((overall = ANY (ARRAY['pending'::text, 'pass'::text, 'fail'::text, 'error'::text]))),
    CONSTRAINT installer_validation_runs_probe_1_status_check CHECK ((probe_1_status = ANY (ARRAY['pass'::text, 'fail'::text, 'skip'::text]))),
    CONSTRAINT installer_validation_runs_probe_2_status_check CHECK ((probe_2_status = ANY (ARRAY['pass'::text, 'fail'::text, 'skip'::text]))),
    CONSTRAINT installer_validation_runs_probe_3_status_check CHECK ((probe_3_status = ANY (ARRAY['pass'::text, 'fail'::text, 'skip'::text]))),
    CONSTRAINT installer_validation_runs_probe_4_status_check CHECK ((probe_4_status = ANY (ARRAY['pass'::text, 'fail'::text, 'skip'::text]))),
    CONSTRAINT installer_validation_runs_probe_5_status_check CHECK ((probe_5_status = ANY (ARRAY['pass'::text, 'fail'::text, 'skip'::text]))),
    CONSTRAINT installer_validation_runs_probe_6_status_check CHECK ((probe_6_status = ANY (ARRAY['pass'::text, 'fail'::text, 'skip'::text]))),
    CONSTRAINT installer_validation_runs_probe_7_status_check CHECK ((probe_7_status = ANY (ARRAY['pass'::text, 'fail'::text, 'skip'::text]))),
    CONSTRAINT installer_validation_runs_topology_check CHECK ((topology = ANY (ARRAY['greenfield-OL7'::text, 'greenfield-OL8'::text, 'live-EBS-12.2.10-db-dev'::text]))),
    CONSTRAINT installer_validation_runs_trigger_source_check CHECK ((trigger_source = ANY (ARRAY['cron'::text, 'deploy_webhook'::text, 'manual'::text])))
);


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

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


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

ALTER SEQUENCE public.installer_validation_runs_id_seq OWNED BY public.installer_validation_runs.id;


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

CREATE TABLE public.job_log_lines (
    id bigint NOT NULL,
    job_id bigint NOT NULL,
    seq integer NOT NULL,
    stream text DEFAULT 'stdout'::text NOT NULL,
    line text NOT NULL,
    ts timestamp with time zone DEFAULT now() NOT NULL,
    CONSTRAINT job_log_lines_stream_check CHECK ((stream = ANY (ARRAY['stdout'::text, 'stderr'::text, 'system'::text])))
);


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

CREATE SEQUENCE public.job_log_lines_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


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

ALTER SEQUENCE public.job_log_lines_id_seq OWNED BY public.job_log_lines.id;


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

CREATE TABLE public.listener_preflight_runs (
    id bigint NOT NULL,
    connection_id integer NOT NULL,
    user_id integer,
    overall_status character varying(16) DEFAULT 'running'::character varying NOT NULL,
    steps jsonb,
    steps_passed smallint,
    steps_failed smallint,
    steps_skipped smallint,
    total_duration_ms integer,
    oracle_home text,
    oracle_sid text,
    ssh_host text,
    error_message text,
    triggered_by character varying(32) DEFAULT 'manual'::character varying,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    finished_at timestamp with time zone
);


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

CREATE SEQUENCE public.listener_preflight_runs_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


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

ALTER SEQUENCE public.listener_preflight_runs_id_seq OWNED BY public.listener_preflight_runs.id;


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

CREATE TABLE public.magic_link_tokens (
    id integer NOT NULL,
    email character varying(255) NOT NULL,
    token character varying(128) NOT NULL,
    expires_at timestamp with time zone NOT NULL,
    used_at timestamp with time zone,
    created_at timestamp with time zone DEFAULT now()
);


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

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


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

ALTER SEQUENCE public.magic_link_tokens_id_seq OWNED BY public.magic_link_tokens.id;


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

CREATE TABLE public.mfa_attempts (
    id integer NOT NULL,
    user_id integer NOT NULL,
    attempted_at timestamp with time zone DEFAULT now() NOT NULL,
    succeeded boolean DEFAULT false NOT NULL,
    method text DEFAULT 'totp'::text NOT NULL,
    ip text
);


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

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


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

ALTER SEQUENCE public.mfa_attempts_id_seq OWNED BY public.mfa_attempts.id;


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

CREATE TABLE public.oracle_connections (
    id integer NOT NULL,
    name character varying(255) NOT NULL,
    host character varying(255),
    port integer DEFAULT 1521,
    service_name character varying(255),
    username character varying(255),
    encrypted_password text,
    last_tested_at timestamp with time zone,
    last_test_success boolean,
    last_test_message text,
    oracle_version character varying(255),
    created_at timestamp with time zone DEFAULT now(),
    updated_at timestamp with time zone DEFAULT now(),
    user_id integer,
    connection_type character varying(20) DEFAULT 'direct'::character varying,
    proxy_url text,
    proxy_api_key_enc text,
    proxy_version character varying(20),
    is_ebs boolean,
    ebs_opt_in boolean DEFAULT false,
    schedule_enabled boolean DEFAULT false NOT NULL,
    schedule_cron text DEFAULT '0 */6 * * *'::text NOT NULL,
    last_scheduled_run_at timestamp with time zone,
    next_scheduled_run_at timestamp with time zone,
    ebs_checks_enabled boolean DEFAULT true,
    gi_os_user character varying(100),
    gi_oracle_home character varying(500),
    asm_sid character varying(50),
    ebs_login_url text,
    weblogic_console_url text,
    proxy_key_last_used_at timestamp with time zone,
    proxy_key_last_ip text,
    proxy_key_ips jsonb DEFAULT '[]'::jsonb,
    proxy_key_created_at timestamp with time zone,
    privilege_model character varying(16) DEFAULT 'sysdba'::character varying NOT NULL,
    last_diagnostics_at timestamp with time zone,
    installed_at timestamp with time zone,
    last_upgrade_at timestamp with time zone,
    python_version character varying(30),
    cx_oracle_version character varying(30),
    os_id character varying(40),
    kernel_version character varying(80),
    proxy_api_key_enc_previous text,
    key_rotated_at timestamp with time zone,
    key_rotation_status text DEFAULT 'idle'::text NOT NULL,
    key_rotation_actor text,
    status text DEFAULT 'active'::text NOT NULL,
    install_token_hash text,
    auto_upgrade_enabled boolean DEFAULT true NOT NULL,
    connectivity_mode public.connectivity_mode_enum DEFAULT 'tns'::public.connectivity_mode_enum NOT NULL,
    ssh_db_host text,
    ssh_db_user text,
    ssh_db_key_enc text,
    ssh_oracle_home text DEFAULT '/u01/app/oracle/product/19.0.0/db_1'::text,
    ssh_oracle_sid text,
    first_run_completed_at timestamp with time zone,
    service_classification jsonb,
    install_token_issued_at timestamp with time zone,
    first_heartbeat_at timestamp with time zone,
    install_id character varying(64),
    agent_in_restart_loop boolean DEFAULT false NOT NULL,
    agent_restart_loop_reason text,
    agent_restart_loop_at timestamp with time zone,
    ebs_service character varying(128),
    server_type character varying(32),
    apps_pwd_enc text,
    weblogic_pwd_enc text,
    ebs_instance_name character varying(64),
    ebs_context_file text,
    ebs_system_pwd_enc text,
    client_name text,
    client_slug text,
    CONSTRAINT oracle_connections_key_rotation_status_check CHECK ((key_rotation_status = ANY (ARRAY['idle'::text, 'pending'::text, 'acknowledged'::text]))),
    CONSTRAINT oracle_connections_privilege_model_check CHECK (((privilege_model)::text = ANY (ARRAY[('reader'::character varying)::text, ('sysdba'::character varying)::text]))),
    CONSTRAINT oracle_connections_status_check CHECK ((status = ANY (ARRAY['pending_registration'::text, 'active'::text, 'stale'::text])))
);


--
-- Name: COLUMN oracle_connections.service_classification; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN public.oracle_connections.service_classification IS 'Snapshot of the service classification at connection creation (classifyServices output). Used for connections-list badge rendering.';


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

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


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

ALTER SEQUENCE public.oracle_connections_id_seq OWNED BY public.oracle_connections.id;


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

CREATE TABLE public.outreach_attempts (
    id bigint NOT NULL,
    attempted_at timestamp with time zone DEFAULT now() NOT NULL,
    attempted_to text,
    attempted_subject text,
    attempted_by text NOT NULL,
    blocked boolean NOT NULL,
    unlock_token_present boolean DEFAULT false NOT NULL,
    blocked_reason text,
    metadata jsonb
);


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

CREATE SEQUENCE public.outreach_attempts_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


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

ALTER SEQUENCE public.outreach_attempts_id_seq OWNED BY public.outreach_attempts.id;


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

CREATE TABLE public.outreach_batches (
    id integer NOT NULL,
    name character varying(255) NOT NULL,
    template_subject text NOT NULL,
    template_body text NOT NULL,
    send_window_start timestamp with time zone,
    send_window_end timestamp with time zone,
    approval_status character varying(32) DEFAULT 'PENDING'::character varying NOT NULL,
    approved_by integer,
    approved_at timestamp with time zone,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updated_at timestamp with time zone DEFAULT now() NOT NULL,
    notes text,
    CONSTRAINT outreach_batches_approval_status_check CHECK (((approval_status)::text = ANY (ARRAY[('PENDING'::character varying)::text, ('APPROVED'::character varying)::text, ('REJECTED'::character varying)::text, ('SENT'::character varying)::text, ('CANCELLED'::character varying)::text])))
);


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

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


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

ALTER SEQUENCE public.outreach_batches_id_seq OWNED BY public.outreach_batches.id;


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

CREATE TABLE public.outreach_recipients (
    id integer NOT NULL,
    batch_id integer NOT NULL,
    email character varying(255) NOT NULL,
    name character varying(255),
    company character varying(255),
    send_authorized boolean DEFAULT false NOT NULL,
    sent_at timestamp with time zone,
    status character varying(32) DEFAULT 'PENDING'::character varying NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    CONSTRAINT outreach_recipients_status_check CHECK (((status)::text = ANY (ARRAY[('PENDING'::character varying)::text, ('SENT'::character varying)::text, ('BLOCKED'::character varying)::text, ('FAILED'::character varying)::text, ('UNSUBSCRIBED'::character varying)::text])))
);


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

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


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

ALTER SEQUENCE public.outreach_recipients_id_seq OWNED BY public.outreach_recipients.id;


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

CREATE TABLE public.outreach_send_log (
    id bigint NOT NULL,
    attempted_at timestamp with time zone DEFAULT now() NOT NULL,
    batch_id integer,
    recipient_id integer,
    recipient_email character varying(255),
    gate_result character varying(16) NOT NULL,
    blocked_reason character varying(64),
    gate_failed character varying(32),
    postmark_message_id character varying(255),
    error_message text,
    metadata jsonb,
    CONSTRAINT outreach_send_log_gate_result_check CHECK (((gate_result)::text = ANY (ARRAY[('ALLOWED'::character varying)::text, ('BLOCKED'::character varying)::text])))
);


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

CREATE SEQUENCE public.outreach_send_log_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


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

ALTER SEQUENCE public.outreach_send_log_id_seq OWNED BY public.outreach_send_log.id;


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

CREATE TABLE public.page_events (
    id bigint NOT NULL,
    event_type text NOT NULL,
    event_name text NOT NULL,
    page_url text NOT NULL,
    referrer text,
    user_agent text,
    ip_hash text,
    session_id uuid,
    created_at timestamp with time zone DEFAULT now() NOT NULL
);


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

CREATE SEQUENCE public.page_events_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


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

ALTER SEQUENCE public.page_events_id_seq OWNED BY public.page_events.id;


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

CREATE TABLE public.payment_method_test_runs (
    id integer NOT NULL,
    ran_at timestamp with time zone DEFAULT now() NOT NULL,
    method character varying(30) NOT NULL,
    flow_type character varying(30),
    bank character varying(10),
    label character varying(100),
    order_id character varying(100),
    payment_id character varying(100),
    amount_paise integer NOT NULL,
    status character varying(20) NOT NULL,
    error_code character varying(100),
    error_description text,
    latency_ms integer,
    raw_response jsonb,
    created_at timestamp with time zone DEFAULT now() NOT NULL
);


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

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


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

ALTER SEQUENCE public.payment_method_test_runs_id_seq OWNED BY public.payment_method_test_runs.id;


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

CREATE TABLE public.payment_reconciliation (
    id bigint NOT NULL,
    occurred_at timestamp with time zone DEFAULT now() NOT NULL,
    event_type text NOT NULL,
    razorpay_payment_id text,
    razorpay_order_id text,
    user_id integer,
    user_email text,
    plan_tier text,
    failure_stage text NOT NULL,
    error_message text,
    metadata jsonb DEFAULT '{}'::jsonb NOT NULL
);


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

CREATE SEQUENCE public.payment_reconciliation_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


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

ALTER SEQUENCE public.payment_reconciliation_id_seq OWNED BY public.payment_reconciliation.id;


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

CREATE TABLE public.payment_test_runs (
    id integer NOT NULL,
    ran_at timestamp with time zone DEFAULT now() NOT NULL,
    test_type character varying(20) NOT NULL,
    plan_tier character varying(20) NOT NULL,
    test_user_id integer NOT NULL,
    order_id character varying(100),
    payment_id character varying(100),
    subscription_id character varying(100),
    stage_order_created character varying(10),
    stage_sig_verified character varying(10),
    stage_credits_updated character varying(10),
    stage_webhook_received character varying(10) DEFAULT 'SKIP'::character varying,
    stage_receipt_sent character varying(10) DEFAULT 'SKIP'::character varying,
    credits_before integer,
    credits_after integer,
    overall_result character varying(10) NOT NULL,
    error_detail text,
    created_at timestamp with time zone DEFAULT now() NOT NULL
);


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

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


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

ALTER SEQUENCE public.payment_test_runs_id_seq OWNED BY public.payment_test_runs.id;


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

CREATE TABLE public.payments (
    id integer NOT NULL,
    user_id integer,
    razorpay_order_id text,
    razorpay_payment_id text,
    razorpay_signature text,
    razorpay_subscription_id text,
    amount_paise integer NOT NULL,
    currency text DEFAULT 'USD'::text NOT NULL,
    plan_tier text NOT NULL,
    payment_type text NOT NULL,
    billing_period text,
    status text DEFAULT 'created'::text NOT NULL,
    metadata jsonb DEFAULT '{}'::jsonb NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updated_at timestamp with time zone DEFAULT now() NOT NULL,
    CONSTRAINT payments_billing_period_check CHECK ((billing_period = ANY (ARRAY['monthly'::text, 'annual'::text]))),
    CONSTRAINT payments_payment_type_check CHECK ((payment_type = ANY (ARRAY['one_time'::text, 'subscription'::text]))),
    CONSTRAINT payments_plan_tier_check CHECK ((plan_tier = ANY (ARRAY['starter'::text, 'growth'::text, 'scale'::text, 'custom'::text, 'individual'::text, 'team'::text, 'business'::text, 'enterprise'::text]))),
    CONSTRAINT payments_status_check CHECK ((status = ANY (ARRAY['created'::text, 'captured'::text, 'failed'::text, 'refunded'::text])))
);


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

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


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

ALTER SEQUENCE public.payments_id_seq OWNED BY public.payments.id;


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

CREATE TABLE public.proxy_exec_audit (
    id integer NOT NULL,
    connection_id integer NOT NULL,
    user_id integer,
    command_id text NOT NULL,
    args jsonb DEFAULT '{}'::jsonb NOT NULL,
    exit_code integer DEFAULT '-1'::integer NOT NULL,
    duration_ms integer DEFAULT 0 NOT NULL,
    stdout_bytes integer DEFAULT 0 NOT NULL,
    stderr_bytes integer DEFAULT 0 NOT NULL,
    succeeded boolean DEFAULT false NOT NULL,
    error_message text,
    executed_at timestamp with time zone DEFAULT now() NOT NULL
);


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

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


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

ALTER SEQUENCE public.proxy_exec_audit_id_seq OWNED BY public.proxy_exec_audit.id;


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

CREATE TABLE public.rbac_audit_log (
    id bigint NOT NULL,
    user_id integer NOT NULL,
    method character varying(10) NOT NULL,
    path character varying(500) NOT NULL,
    required_role character varying(20) NOT NULL,
    actual_role character varying(20) NOT NULL,
    denied_at timestamp with time zone DEFAULT now() NOT NULL
);


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

CREATE SEQUENCE public.rbac_audit_log_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


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

ALTER SEQUENCE public.rbac_audit_log_id_seq OWNED BY public.rbac_audit_log.id;


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

CREATE TABLE public.roadmap_reminders (
    id integer NOT NULL,
    title text NOT NULL,
    body_md text,
    trigger_condition_json jsonb,
    doc_link text,
    manual_flag boolean DEFAULT false NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    surfaced_at timestamp with time zone,
    dismissed_at timestamp with time zone
);


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

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


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

ALTER SEQUENCE public.roadmap_reminders_id_seq OWNED BY public.roadmap_reminders.id;


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

CREATE TABLE public.roles (
    id integer NOT NULL,
    team_id integer NOT NULL,
    name character varying(100) NOT NULL,
    slug character varying(100) NOT NULL,
    branch character varying(20) NOT NULL,
    permissions jsonb DEFAULT '{}'::jsonb NOT NULL,
    approval_required_from integer,
    is_default boolean DEFAULT false NOT NULL,
    sort_order integer DEFAULT 0 NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL,
    CONSTRAINT roles_branch_check CHECK (((branch)::text = ANY (ARRAY[('dba'::character varying)::text, ('functional'::character varying)::text, ('dev'::character varying)::text, ('management'::character varying)::text])))
);


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

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


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

ALTER SEQUENCE public.roles_id_seq OWNED BY public.roles.id;


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

CREATE TABLE public.sample_report_leads (
    id integer NOT NULL,
    email text NOT NULL,
    captured_at timestamp with time zone DEFAULT now() NOT NULL,
    ip text,
    referrer text
);


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

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


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

ALTER SEQUENCE public.sample_report_leads_id_seq OWNED BY public.sample_report_leads.id;


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

CREATE TABLE public.smoke_test_runs (
    id bigint NOT NULL,
    connection_id integer NOT NULL,
    started_at timestamp with time zone DEFAULT now() NOT NULL,
    finished_at timestamp with time zone,
    overall_status text DEFAULT 'running'::text NOT NULL,
    steps_jsonb jsonb DEFAULT '[]'::jsonb NOT NULL,
    triggered_by_user_id integer,
    CONSTRAINT smoke_test_runs_overall_status_check CHECK ((overall_status = ANY (ARRAY['running'::text, 'pass'::text, 'fail'::text, 'error'::text])))
);


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

CREATE SEQUENCE public.smoke_test_runs_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


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

ALTER SEQUENCE public.smoke_test_runs_id_seq OWNED BY public.smoke_test_runs.id;


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

CREATE TABLE public.sql_audit_log (
    id bigint NOT NULL,
    user_id integer,
    user_email character varying(255) NOT NULL,
    connection_id integer NOT NULL,
    connection_name character varying(255),
    sql_text text NOT NULL,
    allowed boolean NOT NULL,
    block_reason character varying(255),
    success boolean,
    row_count integer,
    error_message text,
    duration_ms integer,
    executed_at timestamp with time zone DEFAULT now() NOT NULL
);


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

CREATE SEQUENCE public.sql_audit_log_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


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

ALTER SEQUENCE public.sql_audit_log_id_seq OWNED BY public.sql_audit_log.id;


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

CREATE TABLE public.sql_console_history (
    id integer NOT NULL,
    connection_id integer NOT NULL,
    user_id integer NOT NULL,
    sql_text text NOT NULL,
    elapsed_ms integer,
    rows_returned integer,
    error_message text,
    success boolean DEFAULT true,
    source_ip character varying(64),
    user_agent character varying(512),
    session_id character varying(128),
    executed_at timestamp with time zone DEFAULT now() NOT NULL
);


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

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


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

ALTER SEQUENCE public.sql_console_history_id_seq OWNED BY public.sql_console_history.id;


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

CREATE TABLE public.sql_fix_cache (
    id bigint NOT NULL,
    sql_id character varying(30) NOT NULL,
    plan_hash_value bigint NOT NULL,
    fix_type character varying(30) NOT NULL,
    fix_sql text NOT NULL,
    rationale text NOT NULL,
    sql_text_prefix text,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    expires_at timestamp with time zone NOT NULL
);


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

CREATE SEQUENCE public.sql_fix_cache_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


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

ALTER SEQUENCE public.sql_fix_cache_id_seq OWNED BY public.sql_fix_cache.id;


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

CREATE TABLE public.sql_tuning_findings (
    id bigint NOT NULL,
    connection_id integer NOT NULL,
    sql_id character varying(13) NOT NULL,
    plan_hash bigint,
    rank integer,
    parsing_schema_name character varying(128),
    executions bigint,
    elapsed_per_exec_ms numeric(12,2),
    cpu_per_exec_ms numeric(12,2),
    buffer_gets_per_exec bigint,
    disk_reads_per_exec bigint,
    rows_processed_per_exec numeric(12,2),
    sql_text text,
    metrics_json jsonb DEFAULT '{}'::jsonb NOT NULL,
    plan_summary_json jsonb DEFAULT '[]'::jsonb NOT NULL,
    ai_recommendation_text text,
    recommended_sql_text text,
    fix_type character varying(16),
    diagnosis_tag character varying(64),
    is_heuristic boolean DEFAULT false NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL
);


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

CREATE SEQUENCE public.sql_tuning_findings_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


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

ALTER SEQUENCE public.sql_tuning_findings_id_seq OWNED BY public.sql_tuning_findings.id;


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

CREATE TABLE public.ssh_audit (
    id bigint NOT NULL,
    target_id integer NOT NULL,
    command_key character varying(128) NOT NULL,
    rendered_command text NOT NULL,
    exit_code integer,
    stdout_bytes integer,
    stderr_bytes integer,
    duration_ms integer,
    was_rejected boolean DEFAULT false NOT NULL,
    rejection_reason character varying(128),
    initiated_by character varying(255),
    ts timestamp with time zone DEFAULT now() NOT NULL
);


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

CREATE SEQUENCE public.ssh_audit_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


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

ALTER SEQUENCE public.ssh_audit_id_seq OWNED BY public.ssh_audit.id;


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

CREATE TABLE public.ssh_install_credentials (
    id integer NOT NULL,
    connection_id integer NOT NULL,
    user_id integer NOT NULL,
    ssh_host text NOT NULL,
    ssh_port integer DEFAULT 22 NOT NULL,
    ssh_user text NOT NULL,
    auth_method text NOT NULL,
    encrypted_credential text NOT NULL,
    use_sudo boolean DEFAULT true NOT NULL,
    install_status text DEFAULT 'pending'::text NOT NULL,
    install_log text,
    error_message text,
    installed_at timestamp with time zone,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updated_at timestamp with time zone DEFAULT now() NOT NULL,
    CONSTRAINT ssh_install_credentials_auth_method_check CHECK ((auth_method = ANY (ARRAY['password'::text, 'key'::text]))),
    CONSTRAINT ssh_install_credentials_install_status_check CHECK ((install_status = ANY (ARRAY['pending'::text, 'running'::text, 'success'::text, 'failed'::text])))
);


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

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


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

ALTER SEQUENCE public.ssh_install_credentials_id_seq OWNED BY public.ssh_install_credentials.id;


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

CREATE TABLE public.ssh_targets (
    id integer NOT NULL,
    label character varying(255) NOT NULL,
    host character varying(255) NOT NULL,
    port integer DEFAULT 22 NOT NULL,
    os_user character varying(128) NOT NULL,
    auth_method character varying(16) DEFAULT 'key'::character varying NOT NULL,
    encrypted_private_key text,
    encrypted_passphrase text,
    role character varying(32) DEFAULT 'db_tier'::character varying NOT NULL,
    connection_id integer,
    last_connected_at timestamp with time zone,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updated_at timestamp with time zone DEFAULT now() NOT NULL,
    user_id integer,
    retired_at timestamp with time zone,
    orphaned boolean,
    retire_note text,
    CONSTRAINT ssh_targets_auth_method_check CHECK (((auth_method)::text = ANY (ARRAY[('key'::character varying)::text, ('password'::character varying)::text]))),
    CONSTRAINT ssh_targets_role_check CHECK (((role)::text = ANY (ARRAY[('apps_tier'::character varying)::text, ('db_tier'::character varying)::text, ('utility'::character varying)::text])))
);


--
-- Name: TABLE ssh_targets; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON TABLE public.ssh_targets IS 'DEPRECATED 2026-05-15: Replaced by proxy /exec endpoint (no port 22 required). Hidden from UI. Schema kept for data retention; will be dropped in a future migration after all callers confirmed migrated.';


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

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


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

ALTER SEQUENCE public.ssh_targets_id_seq OWNED BY public.ssh_targets.id;


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

CREATE TABLE public.sso_configs (
    id integer NOT NULL,
    company_domain text NOT NULL,
    provider_type text DEFAULT 'custom'::text NOT NULL,
    sso_url text NOT NULL,
    entity_id text NOT NULL,
    certificate text NOT NULL,
    attribute_mapping jsonb DEFAULT '{"name": "displayName", "email": "nameID"}'::jsonb NOT NULL,
    group_role_mapping jsonb DEFAULT '{}'::jsonb NOT NULL,
    default_role text DEFAULT 'junior_dba'::text NOT NULL,
    is_active boolean DEFAULT true NOT NULL,
    require_sso boolean DEFAULT false NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updated_at timestamp with time zone DEFAULT now() NOT NULL
);


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

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


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

ALTER SEQUENCE public.sso_configs_id_seq OWNED BY public.sso_configs.id;


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

CREATE TABLE public.sso_login_log (
    id integer NOT NULL,
    company_domain text NOT NULL,
    email text,
    succeeded boolean DEFAULT false NOT NULL,
    failure_reason text,
    ip text,
    user_agent text,
    attempted_at timestamp with time zone DEFAULT now() NOT NULL
);


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

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


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

ALTER SEQUENCE public.sso_login_log_id_seq OWNED BY public.sso_login_log.id;


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

CREATE TABLE public.subscriptions (
    id integer NOT NULL,
    user_id integer,
    razorpay_subscription_id text NOT NULL,
    razorpay_plan_id text NOT NULL,
    plan_tier text NOT NULL,
    billing_period text DEFAULT 'monthly'::text NOT NULL,
    status text DEFAULT 'created'::text NOT NULL,
    current_period_start timestamp with time zone,
    current_period_end timestamp with time zone,
    cancelled_at timestamp with time zone,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updated_at timestamp with time zone DEFAULT now() NOT NULL,
    CONSTRAINT subscriptions_billing_period_check CHECK ((billing_period = ANY (ARRAY['monthly'::text, 'annual'::text]))),
    CONSTRAINT subscriptions_plan_tier_check CHECK ((plan_tier = ANY (ARRAY['starter'::text, 'growth'::text, 'scale'::text, 'custom'::text, 'individual'::text, 'team'::text, 'business'::text, 'enterprise'::text]))),
    CONSTRAINT subscriptions_status_check CHECK ((status = ANY (ARRAY['created'::text, 'authenticated'::text, 'active'::text, 'pending'::text, 'halted'::text, 'cancelled'::text, 'completed'::text, 'expired'::text, 'paused'::text])))
);


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

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


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

ALTER SEQUENCE public.subscriptions_id_seq OWNED BY public.subscriptions.id;


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

CREATE TABLE public.team_invites (
    id integer NOT NULL,
    team_id integer NOT NULL,
    invited_by integer NOT NULL,
    email character varying(255) NOT NULL,
    role character varying(20) DEFAULT 'viewer'::character varying NOT NULL,
    token character varying(64) NOT NULL,
    status character varying(20) DEFAULT 'pending'::character varying NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    expires_at timestamp with time zone DEFAULT (now() + '7 days'::interval) NOT NULL,
    CONSTRAINT team_invites_role_check CHECK (((role)::text = ANY (ARRAY[('admin'::character varying)::text, ('senior_dba'::character varying)::text, ('junior_dba'::character varying)::text, ('viewer'::character varying)::text]))),
    CONSTRAINT team_invites_status_check CHECK (((status)::text = ANY (ARRAY[('pending'::character varying)::text, ('accepted'::character varying)::text, ('revoked'::character varying)::text, ('expired'::character varying)::text])))
);


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

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


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

ALTER SEQUENCE public.team_invites_id_seq OWNED BY public.team_invites.id;


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

CREATE TABLE public.team_members (
    id integer NOT NULL,
    team_id integer NOT NULL,
    user_id integer NOT NULL,
    role character varying(20) DEFAULT 'viewer'::character varying NOT NULL,
    joined_at timestamp with time zone DEFAULT now() NOT NULL,
    role_id integer,
    CONSTRAINT team_members_role_check CHECK (((role)::text = ANY (ARRAY[('admin'::character varying)::text, ('senior_dba'::character varying)::text, ('junior_dba'::character varying)::text, ('viewer'::character varying)::text])))
);


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

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


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

ALTER SEQUENCE public.team_members_id_seq OWNED BY public.team_members.id;


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

CREATE TABLE public.teams (
    id integer NOT NULL,
    name character varying(100) NOT NULL,
    owner_id integer NOT NULL,
    plan_tier character varying(20) DEFAULT 'team'::character varying NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updated_at timestamp with time zone DEFAULT now() NOT NULL,
    mfa_required boolean DEFAULT false NOT NULL
);


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

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


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

ALTER SEQUENCE public.teams_id_seq OWNED BY public.teams.id;


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

CREATE TABLE public.tns_topology_snapshots (
    id bigint NOT NULL,
    connection_id integer NOT NULL,
    snapshot_data jsonb NOT NULL,
    service_names text[],
    patch_services text[],
    recommended_svc text,
    pdb_count integer,
    instance_name text,
    db_version text,
    share_token character varying(64),
    share_expires_at timestamp with time zone,
    created_at timestamp with time zone DEFAULT now() NOT NULL
);


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

CREATE SEQUENCE public.tns_topology_snapshots_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


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

ALTER SEQUENCE public.tns_topology_snapshots_id_seq OWNED BY public.tns_topology_snapshots.id;


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

CREATE TABLE public.tuneops_notification_log (
    id bigint NOT NULL,
    ticket_number character varying(16) NOT NULL,
    event_type character varying(32) NOT NULL,
    recipient_email character varying(255) NOT NULL,
    sent_at timestamp with time zone DEFAULT now() NOT NULL,
    metadata jsonb
);


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

CREATE SEQUENCE public.tuneops_notification_log_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


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

ALTER SEQUENCE public.tuneops_notification_log_id_seq OWNED BY public.tuneops_notification_log.id;


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

CREATE TABLE public.tuneops_notification_mutes (
    id integer NOT NULL,
    user_id integer NOT NULL,
    connection_id integer NOT NULL,
    muted_until timestamp with time zone NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL
);


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

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


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

ALTER SEQUENCE public.tuneops_notification_mutes_id_seq OWNED BY public.tuneops_notification_mutes.id;


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

CREATE TABLE public.tuneops_notification_prefs (
    id integer NOT NULL,
    user_id integer NOT NULL,
    notifications_enabled boolean DEFAULT true NOT NULL,
    severity_threshold character varying(16) DEFAULT 'warning'::character varying NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updated_at timestamp with time zone DEFAULT now() NOT NULL
);


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

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


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

ALTER SEQUENCE public.tuneops_notification_prefs_id_seq OWNED BY public.tuneops_notification_prefs.id;


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

CREATE TABLE public.tuneops_tickets (
    id integer NOT NULL,
    company_id character varying(255),
    connection_id integer,
    ticket_number character varying(20) NOT NULL,
    canonical_key character varying(500),
    title character varying(500) NOT NULL,
    description text,
    severity character varying(20) DEFAULT 'info'::character varying NOT NULL,
    status character varying(20) DEFAULT 'OPEN'::character varying NOT NULL,
    source character varying(20) DEFAULT 'health_check'::character varying NOT NULL,
    source_reference jsonb DEFAULT '{}'::jsonb,
    assigned_to integer,
    recommended_fix text,
    fix_type character varying(10),
    requires_approval boolean DEFAULT false NOT NULL,
    approved_by integer,
    approved_at timestamp without time zone,
    executed_by integer,
    executed_at timestamp without time zone,
    execution_result jsonb,
    resolved_at timestamp without time zone,
    resolved_by integer,
    resolution_notes text,
    reopened_count integer DEFAULT 0 NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL,
    acknowledged_at timestamp with time zone,
    CONSTRAINT tuneops_tickets_fix_type_check CHECK (((fix_type)::text = ANY (ARRAY[('sql'::character varying)::text, ('ssh'::character varying)::text, ('manual'::character varying)::text]))),
    CONSTRAINT tuneops_tickets_severity_check CHECK (((severity)::text = ANY (ARRAY[('critical'::character varying)::text, ('warning'::character varying)::text, ('info'::character varying)::text]))),
    CONSTRAINT tuneops_tickets_source_check CHECK (((source)::text = ANY (ARRAY[('health_check'::character varying)::text, ('db_ops'::character varying)::text, ('control_tab'::character varying)::text, ('ssh_command'::character varying)::text, ('sql_command'::character varying)::text, ('manual'::character varying)::text]))),
    CONSTRAINT tuneops_tickets_status_check CHECK (((status)::text = ANY ((ARRAY['OPEN'::character varying, 'ACKNOWLEDGED'::character varying, 'EXECUTING'::character varying, 'RESOLVED'::character varying, 'REOPENED'::character varying, 'DEFERRED'::character varying])::text[])))
);


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

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


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

ALTER SEQUENCE public.tuneops_tickets_id_seq OWNED BY public.tuneops_tickets.id;


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

CREATE TABLE public.user_credits (
    id integer NOT NULL,
    user_id integer NOT NULL,
    checks_remaining integer DEFAULT 0 NOT NULL,
    checks_total integer DEFAULT 0 NOT NULL,
    plan_tier text DEFAULT 'free'::text NOT NULL,
    subscription_id integer,
    period_start timestamp with time zone,
    period_end timestamp with time zone,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updated_at timestamp with time zone DEFAULT now() NOT NULL,
    scheduled_plan_change text,
    scheduled_plan_change_date timestamp with time zone,
    cancel_at_period_end boolean DEFAULT false NOT NULL,
    CONSTRAINT user_credits_plan_tier_check CHECK ((plan_tier = ANY (ARRAY['free'::text, 'starter'::text, 'growth'::text, 'scale'::text, 'custom'::text, 'individual'::text, 'team'::text, 'business'::text, 'enterprise'::text])))
);


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

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


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

ALTER SEQUENCE public.user_credits_id_seq OWNED BY public.user_credits.id;


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

CREATE TABLE public.user_hc_usage (
    id integer NOT NULL,
    user_email character varying(255) NOT NULL,
    hc_count integer DEFAULT 0 NOT NULL,
    first_run_at timestamp with time zone DEFAULT now(),
    last_run_at timestamp with time zone DEFAULT now()
);


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

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


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

ALTER SEQUENCE public.user_hc_usage_id_seq OWNED BY public.user_hc_usage.id;


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

CREATE TABLE public.user_mfa (
    id integer NOT NULL,
    user_id integer NOT NULL,
    totp_secret text NOT NULL,
    is_enabled boolean DEFAULT false NOT NULL,
    recovery_codes jsonb DEFAULT '[]'::jsonb NOT NULL,
    verified_at timestamp with time zone,
    last_used_at timestamp with time zone,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updated_at timestamp with time zone DEFAULT now() NOT NULL
);


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

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


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

ALTER SEQUENCE public.user_mfa_id_seq OWNED BY public.user_mfa.id;


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

CREATE TABLE public.user_preferences (
    id integer NOT NULL,
    user_id integer NOT NULL,
    hc_completion_email boolean DEFAULT true NOT NULL,
    last_hc_email_sent_at timestamp with time zone,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updated_at timestamp with time zone DEFAULT now() NOT NULL
);


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

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


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

ALTER SEQUENCE public.user_preferences_id_seq OWNED BY public.user_preferences.id;


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

CREATE TABLE public.users (
    id integer NOT NULL,
    email character varying(255) NOT NULL,
    name character varying(255),
    password_hash character varying(255),
    created_at timestamp with time zone DEFAULT now(),
    updated_at timestamp with time zone DEFAULT now(),
    stripe_subscription_id character varying(255),
    subscription_status character varying(50),
    subscription_plan character varying(255),
    subscription_expires_at timestamp with time zone,
    subscription_updated_at timestamp with time zone,
    company_domain character varying(255),
    google_id character varying(255),
    last_login timestamp with time zone,
    team_id integer,
    sso_provider text,
    manager_role text,
    CONSTRAINT users_manager_role_check CHECK ((manager_role = ANY (ARRAY['dba'::text, 'apps_dba'::text, 'functional'::text, 'developer'::text, 'manager'::text, 'sdm'::text, 'admin'::text])))
);


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

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


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

ALTER SEQUENCE public.users_id_seq OWNED BY public.users.id;


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

CREATE TABLE public.validation_runs (
    id bigint NOT NULL,
    connection_id integer NOT NULL,
    user_id integer,
    started_at timestamp with time zone DEFAULT now() NOT NULL,
    finished_at timestamp with time zone,
    status text DEFAULT 'running'::text NOT NULL,
    share_token text,
    share_expires_at timestamp with time zone,
    summary_json jsonb,
    full_results_json jsonb,
    CONSTRAINT validation_runs_status_check CHECK ((status = ANY (ARRAY['running'::text, 'pass'::text, 'partial'::text, 'fail'::text, 'error'::text])))
);


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

CREATE SEQUENCE public.validation_runs_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


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

ALTER SEQUENCE public.validation_runs_id_seq OWNED BY public.validation_runs.id;


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


--
-- Name: _migrations _migrations_name_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public._migrations
    ADD CONSTRAINT _migrations_name_key UNIQUE (name);


--
-- Name: _migrations _migrations_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public._migrations
    ADD CONSTRAINT _migrations_pkey PRIMARY KEY (id);


--
-- Name: activity_log activity_log_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.activity_log
    ADD CONSTRAINT activity_log_pkey PRIMARY KEY (id);


--
-- Name: addm_runs addm_runs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.addm_runs
    ADD CONSTRAINT addm_runs_pkey PRIMARY KEY (id);


--
-- Name: admin_exports admin_exports_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.admin_exports
    ADD CONSTRAINT admin_exports_pkey PRIMARY KEY (id);


--
-- Name: advisor_findings advisor_findings_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.advisor_findings
    ADD CONSTRAINT advisor_findings_pkey PRIMARY KEY (id);


--
-- Name: agent_channel_state agent_channel_state_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.agent_channel_state
    ADD CONSTRAINT agent_channel_state_pkey PRIMARY KEY (agent_id);


--
-- Name: agent_command_queue agent_command_queue_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.agent_command_queue
    ADD CONSTRAINT agent_command_queue_pkey PRIMARY KEY (id);


--
-- Name: agent_command_results agent_command_results_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.agent_command_results
    ADD CONSTRAINT agent_command_results_pkey PRIMARY KEY (id);


--
-- Name: agent_crash_alerts_sent agent_crash_alerts_sent_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.agent_crash_alerts_sent
    ADD CONSTRAINT agent_crash_alerts_sent_pkey PRIMARY KEY (connection_id);


--
-- Name: agent_diagnose_runs agent_diagnose_runs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.agent_diagnose_runs
    ADD CONSTRAINT agent_diagnose_runs_pkey PRIMARY KEY (id);


--
-- Name: agent_install_failures agent_install_failures_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.agent_install_failures
    ADD CONSTRAINT agent_install_failures_pkey PRIMARY KEY (id);


--
-- Name: agent_reg_tokens agent_reg_tokens_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.agent_reg_tokens
    ADD CONSTRAINT agent_reg_tokens_pkey PRIMARY KEY (id);


--
-- Name: agent_reg_tokens agent_reg_tokens_token_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.agent_reg_tokens
    ADD CONSTRAINT agent_reg_tokens_token_key UNIQUE (token);


--
-- Name: agent_restart_events agent_restart_events_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.agent_restart_events
    ADD CONSTRAINT agent_restart_events_pkey PRIMARY KEY (id);


--
-- Name: agent_tunnels agent_tunnels_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.agent_tunnels
    ADD CONSTRAINT agent_tunnels_pkey PRIMARY KEY (id);


--
-- Name: agent_upgrade_audit agent_upgrade_audit_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.agent_upgrade_audit
    ADD CONSTRAINT agent_upgrade_audit_pkey PRIMARY KEY (id);


--
-- Name: agents_log_buffer agents_log_buffer_connection_id_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.agents_log_buffer
    ADD CONSTRAINT agents_log_buffer_connection_id_key UNIQUE (connection_id);


--
-- Name: agents_log_buffer agents_log_buffer_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.agents_log_buffer
    ADD CONSTRAINT agents_log_buffer_pkey PRIMARY KEY (id);


--
-- Name: alert_events alert_events_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.alert_events
    ADD CONSTRAINT alert_events_pkey PRIMARY KEY (id);


--
-- Name: alert_policies alert_policies_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.alert_policies
    ADD CONSTRAINT alert_policies_pkey PRIMARY KEY (id);


--
-- Name: analysis_runs analysis_runs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.analysis_runs
    ADD CONSTRAINT analysis_runs_pkey PRIMARY KEY (id);


--
-- Name: analytics_events analytics_events_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.analytics_events
    ADD CONSTRAINT analytics_events_pkey PRIMARY KEY (id);


--
-- Name: api_keys api_keys_key_hash_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.api_keys
    ADD CONSTRAINT api_keys_key_hash_key UNIQUE (key_hash);


--
-- Name: api_keys api_keys_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.api_keys
    ADD CONSTRAINT api_keys_pkey PRIMARY KEY (id);


--
-- Name: approval_requests approval_requests_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.approval_requests
    ADD CONSTRAINT approval_requests_pkey PRIMARY KEY (id);


--
-- Name: audit_log audit_log_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.audit_log
    ADD CONSTRAINT audit_log_pkey PRIMARY KEY (id);


--
-- Name: blog_posts blog_posts_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.blog_posts
    ADD CONSTRAINT blog_posts_pkey PRIMARY KEY (id);


--
-- Name: blog_posts blog_posts_slug_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.blog_posts
    ADD CONSTRAINT blog_posts_slug_key UNIQUE (slug);


--
-- Name: check_failure_bundles check_failure_bundles_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.check_failure_bundles
    ADD CONSTRAINT check_failure_bundles_pkey PRIMARY KEY (id);


--
-- Name: check_results check_results_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.check_results
    ADD CONSTRAINT check_results_pkey PRIMARY KEY (id);


--
-- Name: checks_catalogue checks_catalogue_check_id_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.checks_catalogue
    ADD CONSTRAINT checks_catalogue_check_id_key UNIQUE (check_id);


--
-- Name: checks_catalogue checks_catalogue_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.checks_catalogue
    ADD CONSTRAINT checks_catalogue_pkey PRIMARY KEY (id);


--
-- Name: clone_history clone_history_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.clone_history
    ADD CONSTRAINT clone_history_pkey PRIMARY KEY (id);


--
-- Name: clone_recipes clone_recipes_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.clone_recipes
    ADD CONSTRAINT clone_recipes_pkey PRIMARY KEY (id);


--
-- Name: company_hc_usage company_hc_usage_company_domain_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.company_hc_usage
    ADD CONSTRAINT company_hc_usage_company_domain_key UNIQUE (company_domain);


--
-- Name: company_hc_usage company_hc_usage_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.company_hc_usage
    ADD CONSTRAINT company_hc_usage_pkey PRIMARY KEY (id);


--
-- Name: compliance_reports compliance_reports_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.compliance_reports
    ADD CONSTRAINT compliance_reports_pkey PRIMARY KEY (id);


--
-- Name: connection_health_runs connection_health_runs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.connection_health_runs
    ADD CONSTRAINT connection_health_runs_pkey PRIMARY KEY (id);


--
-- Name: connection_schedules connection_schedules_connection_id_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.connection_schedules
    ADD CONSTRAINT connection_schedules_connection_id_key UNIQUE (connection_id);


--
-- Name: connection_schedules connection_schedules_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.connection_schedules
    ADD CONSTRAINT connection_schedules_pkey PRIMARY KEY (id);


--
-- Name: connection_ssh_profiles connection_ssh_profiles_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.connection_ssh_profiles
    ADD CONSTRAINT connection_ssh_profiles_pkey PRIMARY KEY (id);


--
-- Name: credential_access_log credential_access_log_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.credential_access_log
    ADD CONSTRAINT credential_access_log_pkey PRIMARY KEY (id);


--
-- Name: demo_runs demo_runs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.demo_runs
    ADD CONSTRAINT demo_runs_pkey PRIMARY KEY (id);


--
-- Name: demo_runs demo_runs_user_id_run_date_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.demo_runs
    ADD CONSTRAINT demo_runs_user_id_run_date_key UNIQUE (user_id, run_date);


--
-- Name: ebs_adop_state ebs_adop_state_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.ebs_adop_state
    ADD CONSTRAINT ebs_adop_state_pkey PRIMARY KEY (id);


--
-- Name: ebs_control_commands ebs_control_commands_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.ebs_control_commands
    ADD CONSTRAINT ebs_control_commands_pkey PRIMARY KEY (id);


--
-- Name: ebs_control_commands ebs_control_commands_slug_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.ebs_control_commands
    ADD CONSTRAINT ebs_control_commands_slug_key UNIQUE (slug);


--
-- Name: ebs_credentials ebs_credentials_connection_id_credential_type_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.ebs_credentials
    ADD CONSTRAINT ebs_credentials_connection_id_credential_type_key UNIQUE (connection_id, credential_type);


--
-- Name: ebs_credentials ebs_credentials_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.ebs_credentials
    ADD CONSTRAINT ebs_credentials_pkey PRIMARY KEY (id);


--
-- Name: ebs_deep_reports ebs_deep_reports_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.ebs_deep_reports
    ADD CONSTRAINT ebs_deep_reports_pkey PRIMARY KEY (id);


--
-- Name: ebs_jobs ebs_jobs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.ebs_jobs
    ADD CONSTRAINT ebs_jobs_pkey PRIMARY KEY (id);


--
-- Name: ebs_module_runs ebs_module_runs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.ebs_module_runs
    ADD CONSTRAINT ebs_module_runs_pkey PRIMARY KEY (id);


--
-- Name: ebs_sanity_runs ebs_sanity_runs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.ebs_sanity_runs
    ADD CONSTRAINT ebs_sanity_runs_pkey PRIMARY KEY (id);


--
-- Name: ebs_validation_runs ebs_validation_runs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.ebs_validation_runs
    ADD CONSTRAINT ebs_validation_runs_pkey PRIMARY KEY (id);


--
-- Name: email_drip_state email_drip_state_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.email_drip_state
    ADD CONSTRAINT email_drip_state_pkey PRIMARY KEY (id);


--
-- Name: email_drip_state email_drip_state_user_id_sequence_step_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.email_drip_state
    ADD CONSTRAINT email_drip_state_user_id_sequence_step_key UNIQUE (user_id, sequence_step);


--
-- Name: email_log email_log_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.email_log
    ADD CONSTRAINT email_log_pkey PRIMARY KEY (id);


--
-- Name: finding_history finding_history_connection_id_finding_key_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.finding_history
    ADD CONSTRAINT finding_history_connection_id_finding_key_key UNIQUE (connection_id, finding_key);


--
-- Name: finding_history finding_history_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.finding_history
    ADD CONSTRAINT finding_history_pkey PRIMARY KEY (id);


--
-- Name: fndload_history fndload_history_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.fndload_history
    ADD CONSTRAINT fndload_history_pkey PRIMARY KEY (id);


--
-- Name: health_check_requests health_check_requests_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.health_check_requests
    ADD CONSTRAINT health_check_requests_pkey PRIMARY KEY (id);


--
-- Name: health_checks health_checks_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.health_checks
    ADD CONSTRAINT health_checks_pkey PRIMARY KEY (id);


--
-- Name: install_jobs install_jobs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.install_jobs
    ADD CONSTRAINT install_jobs_pkey PRIMARY KEY (id);


--
-- Name: installer_smoke_runs installer_smoke_runs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.installer_smoke_runs
    ADD CONSTRAINT installer_smoke_runs_pkey PRIMARY KEY (id);


--
-- Name: installer_smoke_tokens installer_smoke_tokens_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.installer_smoke_tokens
    ADD CONSTRAINT installer_smoke_tokens_pkey PRIMARY KEY (id);


--
-- Name: installer_smoke_tokens installer_smoke_tokens_token_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.installer_smoke_tokens
    ADD CONSTRAINT installer_smoke_tokens_token_key UNIQUE (token);


--
-- Name: installer_validation_runs installer_validation_runs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.installer_validation_runs
    ADD CONSTRAINT installer_validation_runs_pkey PRIMARY KEY (id);


--
-- Name: job_log_lines job_log_lines_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.job_log_lines
    ADD CONSTRAINT job_log_lines_pkey PRIMARY KEY (id);


--
-- Name: listener_preflight_runs listener_preflight_runs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.listener_preflight_runs
    ADD CONSTRAINT listener_preflight_runs_pkey PRIMARY KEY (id);


--
-- Name: magic_link_tokens magic_link_tokens_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.magic_link_tokens
    ADD CONSTRAINT magic_link_tokens_pkey PRIMARY KEY (id);


--
-- Name: magic_link_tokens magic_link_tokens_token_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.magic_link_tokens
    ADD CONSTRAINT magic_link_tokens_token_key UNIQUE (token);


--
-- Name: mfa_attempts mfa_attempts_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.mfa_attempts
    ADD CONSTRAINT mfa_attempts_pkey PRIMARY KEY (id);


--
-- Name: oracle_connections oracle_connections_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.oracle_connections
    ADD CONSTRAINT oracle_connections_pkey PRIMARY KEY (id);


--
-- Name: outreach_attempts outreach_attempts_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.outreach_attempts
    ADD CONSTRAINT outreach_attempts_pkey PRIMARY KEY (id);


--
-- Name: outreach_batches outreach_batches_name_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.outreach_batches
    ADD CONSTRAINT outreach_batches_name_key UNIQUE (name);


--
-- Name: outreach_batches outreach_batches_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.outreach_batches
    ADD CONSTRAINT outreach_batches_pkey PRIMARY KEY (id);


--
-- Name: outreach_recipients outreach_recipients_batch_id_email_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.outreach_recipients
    ADD CONSTRAINT outreach_recipients_batch_id_email_key UNIQUE (batch_id, email);


--
-- Name: outreach_recipients outreach_recipients_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.outreach_recipients
    ADD CONSTRAINT outreach_recipients_pkey PRIMARY KEY (id);


--
-- Name: outreach_send_log outreach_send_log_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.outreach_send_log
    ADD CONSTRAINT outreach_send_log_pkey PRIMARY KEY (id);


--
-- Name: page_events page_events_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.page_events
    ADD CONSTRAINT page_events_pkey PRIMARY KEY (id);


--
-- Name: payment_method_test_runs payment_method_test_runs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.payment_method_test_runs
    ADD CONSTRAINT payment_method_test_runs_pkey PRIMARY KEY (id);


--
-- Name: payment_reconciliation payment_reconciliation_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.payment_reconciliation
    ADD CONSTRAINT payment_reconciliation_pkey PRIMARY KEY (id);


--
-- Name: payment_test_runs payment_test_runs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.payment_test_runs
    ADD CONSTRAINT payment_test_runs_pkey PRIMARY KEY (id);


--
-- Name: payments payments_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.payments
    ADD CONSTRAINT payments_pkey PRIMARY KEY (id);


--
-- Name: payments payments_razorpay_order_id_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.payments
    ADD CONSTRAINT payments_razorpay_order_id_key UNIQUE (razorpay_order_id);


--
-- Name: proxy_exec_audit proxy_exec_audit_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.proxy_exec_audit
    ADD CONSTRAINT proxy_exec_audit_pkey PRIMARY KEY (id);


--
-- Name: rbac_audit_log rbac_audit_log_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.rbac_audit_log
    ADD CONSTRAINT rbac_audit_log_pkey PRIMARY KEY (id);


--
-- Name: roadmap_reminders roadmap_reminders_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.roadmap_reminders
    ADD CONSTRAINT roadmap_reminders_pkey PRIMARY KEY (id);


--
-- Name: roles roles_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.roles
    ADD CONSTRAINT roles_pkey PRIMARY KEY (id);


--
-- Name: roles roles_team_id_slug_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.roles
    ADD CONSTRAINT roles_team_id_slug_key UNIQUE (team_id, slug);


--
-- Name: sample_report_leads sample_report_leads_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.sample_report_leads
    ADD CONSTRAINT sample_report_leads_pkey PRIMARY KEY (id);


--
-- Name: smoke_test_runs smoke_test_runs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.smoke_test_runs
    ADD CONSTRAINT smoke_test_runs_pkey PRIMARY KEY (id);


--
-- Name: sql_audit_log sql_audit_log_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.sql_audit_log
    ADD CONSTRAINT sql_audit_log_pkey PRIMARY KEY (id);


--
-- Name: sql_console_history sql_console_history_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.sql_console_history
    ADD CONSTRAINT sql_console_history_pkey PRIMARY KEY (id);


--
-- Name: sql_fix_cache sql_fix_cache_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.sql_fix_cache
    ADD CONSTRAINT sql_fix_cache_pkey PRIMARY KEY (id);


--
-- Name: sql_tuning_findings sql_tuning_findings_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.sql_tuning_findings
    ADD CONSTRAINT sql_tuning_findings_pkey PRIMARY KEY (id);


--
-- Name: ssh_audit ssh_audit_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.ssh_audit
    ADD CONSTRAINT ssh_audit_pkey PRIMARY KEY (id);


--
-- Name: ssh_install_credentials ssh_install_credentials_connection_id_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.ssh_install_credentials
    ADD CONSTRAINT ssh_install_credentials_connection_id_key UNIQUE (connection_id);


--
-- Name: ssh_install_credentials ssh_install_credentials_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.ssh_install_credentials
    ADD CONSTRAINT ssh_install_credentials_pkey PRIMARY KEY (id);


--
-- Name: ssh_targets ssh_targets_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.ssh_targets
    ADD CONSTRAINT ssh_targets_pkey PRIMARY KEY (id);


--
-- Name: sso_configs sso_configs_company_domain_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.sso_configs
    ADD CONSTRAINT sso_configs_company_domain_key UNIQUE (company_domain);


--
-- Name: sso_configs sso_configs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.sso_configs
    ADD CONSTRAINT sso_configs_pkey PRIMARY KEY (id);


--
-- Name: sso_login_log sso_login_log_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.sso_login_log
    ADD CONSTRAINT sso_login_log_pkey PRIMARY KEY (id);


--
-- Name: subscriptions subscriptions_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.subscriptions
    ADD CONSTRAINT subscriptions_pkey PRIMARY KEY (id);


--
-- Name: subscriptions subscriptions_razorpay_subscription_id_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.subscriptions
    ADD CONSTRAINT subscriptions_razorpay_subscription_id_key UNIQUE (razorpay_subscription_id);


--
-- Name: team_invites team_invites_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.team_invites
    ADD CONSTRAINT team_invites_pkey PRIMARY KEY (id);


--
-- Name: team_invites team_invites_token_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.team_invites
    ADD CONSTRAINT team_invites_token_key UNIQUE (token);


--
-- Name: team_members team_members_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.team_members
    ADD CONSTRAINT team_members_pkey PRIMARY KEY (id);


--
-- Name: team_members team_members_team_id_user_id_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.team_members
    ADD CONSTRAINT team_members_team_id_user_id_key UNIQUE (team_id, user_id);


--
-- Name: teams teams_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.teams
    ADD CONSTRAINT teams_pkey PRIMARY KEY (id);


--
-- Name: tns_topology_snapshots tns_topology_snapshots_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.tns_topology_snapshots
    ADD CONSTRAINT tns_topology_snapshots_pkey PRIMARY KEY (id);


--
-- Name: tns_topology_snapshots tns_topology_snapshots_share_token_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.tns_topology_snapshots
    ADD CONSTRAINT tns_topology_snapshots_share_token_key UNIQUE (share_token);


--
-- Name: tuneops_notification_log tuneops_notification_log_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.tuneops_notification_log
    ADD CONSTRAINT tuneops_notification_log_pkey PRIMARY KEY (id);


--
-- Name: tuneops_notification_mutes tuneops_notification_mutes_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.tuneops_notification_mutes
    ADD CONSTRAINT tuneops_notification_mutes_pkey PRIMARY KEY (id);


--
-- Name: tuneops_notification_prefs tuneops_notification_prefs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.tuneops_notification_prefs
    ADD CONSTRAINT tuneops_notification_prefs_pkey PRIMARY KEY (id);


--
-- Name: tuneops_notification_prefs tuneops_notification_prefs_user_id_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.tuneops_notification_prefs
    ADD CONSTRAINT tuneops_notification_prefs_user_id_key UNIQUE (user_id);


--
-- Name: tuneops_tickets tuneops_tickets_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.tuneops_tickets
    ADD CONSTRAINT tuneops_tickets_pkey PRIMARY KEY (id);


--
-- Name: ebs_adop_state uq_ebs_adop_state_connection; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.ebs_adop_state
    ADD CONSTRAINT uq_ebs_adop_state_connection UNIQUE (connection_id);


--
-- Name: user_credits user_credits_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.user_credits
    ADD CONSTRAINT user_credits_pkey PRIMARY KEY (id);


--
-- Name: user_credits user_credits_user_id_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.user_credits
    ADD CONSTRAINT user_credits_user_id_key UNIQUE (user_id);


--
-- Name: user_hc_usage user_hc_usage_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.user_hc_usage
    ADD CONSTRAINT user_hc_usage_pkey PRIMARY KEY (id);


--
-- Name: user_hc_usage user_hc_usage_user_email_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.user_hc_usage
    ADD CONSTRAINT user_hc_usage_user_email_key UNIQUE (user_email);


--
-- Name: user_mfa user_mfa_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.user_mfa
    ADD CONSTRAINT user_mfa_pkey PRIMARY KEY (id);


--
-- Name: user_mfa user_mfa_user_id_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.user_mfa
    ADD CONSTRAINT user_mfa_user_id_key UNIQUE (user_id);


--
-- Name: user_preferences user_preferences_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.user_preferences
    ADD CONSTRAINT user_preferences_pkey PRIMARY KEY (id);


--
-- Name: user_preferences user_preferences_user_id_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.user_preferences
    ADD CONSTRAINT user_preferences_user_id_key UNIQUE (user_id);


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

ALTER TABLE ONLY public.users
    ADD CONSTRAINT users_google_id_key UNIQUE (google_id);


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

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


--
-- Name: validation_runs validation_runs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.validation_runs
    ADD CONSTRAINT validation_runs_pkey PRIMARY KEY (id);


--
-- Name: validation_runs validation_runs_share_token_key; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.validation_runs
    ADD CONSTRAINT validation_runs_share_token_key UNIQUE (share_token);


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

CREATE INDEX activity_log_action_type_idx ON public.activity_log USING btree (action_type, created_at DESC);


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

CREATE INDEX activity_log_company_domain_idx ON public.activity_log USING btree (company_domain, created_at DESC) WHERE (company_domain IS NOT NULL);


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

CREATE INDEX activity_log_connection_id_idx ON public.activity_log USING btree (connection_id, created_at DESC) WHERE (connection_id IS NOT NULL);


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

CREATE INDEX activity_log_created_at_idx ON public.activity_log USING btree (created_at DESC);


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

CREATE INDEX activity_log_result_idx ON public.activity_log USING btree (result, created_at DESC);


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

CREATE INDEX activity_log_user_id_idx ON public.activity_log USING btree (user_id, created_at DESC) WHERE (user_id IS NOT NULL);


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

CREATE INDEX addm_runs_connection_created ON public.addm_runs USING btree (connection_id, created_at DESC);


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

CREATE INDEX addm_runs_created_at ON public.addm_runs USING btree (created_at DESC);


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

CREATE UNIQUE INDEX advisor_findings_connection_unique ON public.advisor_findings USING btree (connection_id);


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

CREATE INDEX advisor_findings_fetched_at ON public.advisor_findings USING btree (fetched_at DESC);


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

CREATE INDEX agent_reg_tokens_expires ON public.agent_reg_tokens USING btree (expires_at);


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

CREATE UNIQUE INDEX agent_tunnels_connection_unique ON public.agent_tunnels USING btree (connection_id);


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

CREATE INDEX analysis_runs_hc_idx ON public.analysis_runs USING btree (health_check_id);


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

CREATE INDEX analytics_events_event_name_idx ON public.analytics_events USING btree (event_name, occurred_at DESC);


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

CREATE INDEX analytics_events_ip_idx ON public.analytics_events USING btree (ip, occurred_at DESC) WHERE (ip IS NOT NULL);


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

CREATE INDEX analytics_events_session_idx ON public.analytics_events USING btree (session_id, occurred_at DESC) WHERE (session_id IS NOT NULL);


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

CREATE INDEX analytics_events_user_id_idx ON public.analytics_events USING btree (user_id, occurred_at DESC) WHERE (user_id IS NOT NULL);


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

CREATE INDEX api_keys_key_prefix_idx ON public.api_keys USING btree (key_prefix);


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

CREATE INDEX api_keys_user_id_idx ON public.api_keys USING btree (user_id);


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

CREATE INDEX credential_access_log_accessed_at_idx ON public.credential_access_log USING btree (accessed_at DESC);


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

CREATE INDEX credential_access_log_connection_id_idx ON public.credential_access_log USING btree (connection_id);


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

CREATE INDEX ebs_credentials_connection_id_idx ON public.ebs_credentials USING btree (connection_id);


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

CREATE INDEX ebs_jobs_conn_status ON public.ebs_jobs USING btree (connection_id, status);


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

CREATE INDEX health_check_requests_created_at_idx ON public.health_check_requests USING btree (created_at DESC);


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

CREATE INDEX health_check_requests_status_idx ON public.health_check_requests USING btree (status);


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

CREATE INDEX health_checks_created_at_idx ON public.health_checks USING btree (created_at DESC);


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

CREATE INDEX health_checks_status_idx ON public.health_checks USING btree (status);


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

CREATE INDEX idx_admin_exports_started_at ON public.admin_exports USING btree (started_at DESC);


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

CREATE INDEX idx_agent_channel_state_claim_expires ON public.agent_channel_state USING btree (agent_id, claim_expires_at);


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

CREATE INDEX idx_agent_cmd_results_conn ON public.agent_command_results USING btree (connection_id, requested_at DESC);


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

CREATE INDEX idx_agent_command_queue_expired_claims ON public.agent_command_queue USING btree (status, claim_expires_at) WHERE (status = 'claimed'::text);


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

CREATE INDEX idx_agent_command_queue_lookup ON public.agent_command_queue USING btree (agent_id, status, enqueued_at);


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

CREATE INDEX idx_agent_diagnose_runs_conn_created ON public.agent_diagnose_runs USING btree (connection_id, created_at DESC);


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

CREATE INDEX idx_agent_install_failures_conn ON public.agent_install_failures USING btree (connection_id, created_at DESC);


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

CREATE INDEX idx_agent_install_failures_created ON public.agent_install_failures USING btree (created_at DESC);


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

CREATE INDEX idx_agent_install_failures_resolved ON public.agent_install_failures USING btree (resolved_at) WHERE (resolved_at IS NULL);


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

CREATE INDEX idx_agent_restart_events_conn_time ON public.agent_restart_events USING btree (connection_id, recorded_at DESC);


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

CREATE INDEX idx_agent_tunnels_agent_status ON public.agent_tunnels USING btree (agent_status);


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

CREATE INDEX idx_agent_tunnels_uninstalled ON public.agent_tunnels USING btree (status, uninstalled_at) WHERE (status = 'uninstalled'::text);


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

CREATE INDEX idx_agent_upgrade_audit_connection_verified ON public.agent_upgrade_audit USING btree (connection_id, verified_at DESC NULLS LAST) WHERE (verified_at IS NOT NULL);


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

CREATE INDEX idx_agents_log_buffer_conn ON public.agents_log_buffer USING btree (connection_id);


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

CREATE INDEX idx_alert_events_connection_id ON public.alert_events USING btree (connection_id, status);


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

CREATE INDEX idx_alert_events_open ON public.alert_events USING btree (status, next_escalation_at) WHERE (status = ANY (ARRAY['triggered'::text, 'escalated'::text]));


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

CREATE INDEX idx_alert_events_policy_id ON public.alert_events USING btree (policy_id, status);


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

CREATE INDEX idx_alert_policies_connection_id ON public.alert_policies USING btree (connection_id);


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

CREATE INDEX idx_alert_policies_user_id ON public.alert_policies USING btree (user_id, is_active);


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

CREATE INDEX idx_approval_requests_requester ON public.approval_requests USING btree (requester_id);


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

CREATE INDEX idx_approval_requests_role ON public.approval_requests USING btree (approver_role_id);


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

CREATE INDEX idx_approval_requests_status ON public.approval_requests USING btree (status) WHERE ((status)::text = 'pending'::text);


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

CREATE INDEX idx_audit_log_occurred_at ON public.audit_log USING btree (occurred_at DESC);


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

CREATE INDEX idx_audit_log_slug ON public.audit_log USING btree (slug);


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

CREATE INDEX idx_blog_posts_published_at ON public.blog_posts USING btree (published_at);


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

CREATE INDEX idx_blog_posts_slug ON public.blog_posts USING btree (slug);


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

CREATE INDEX idx_cfb_connection_created ON public.check_failure_bundles USING btree (connection_id, created_at DESC);


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

CREATE INDEX idx_cfb_created_at ON public.check_failure_bundles USING btree (created_at DESC);


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

CREATE INDEX idx_check_results_conn_check_time ON public.check_results USING btree (connection_id, check_id, executed_at DESC);


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

CREATE INDEX idx_check_results_run ON public.check_results USING btree (run_id);


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

CREATE INDEX idx_check_results_status_time ON public.check_results USING btree (connection_id, status, executed_at DESC) WHERE (status = ANY (ARRAY['amber'::text, 'red'::text]));


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

CREATE INDEX idx_checks_catalogue_category ON public.checks_catalogue USING btree (category);


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

CREATE INDEX idx_checks_catalogue_status ON public.checks_catalogue USING btree (status);


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

CREATE INDEX idx_chr_connection_ran ON public.connection_health_runs USING btree (connection_id, ran_at DESC);


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

CREATE INDEX idx_clone_history_company ON public.clone_history USING btree (company_id) WHERE (company_id IS NOT NULL);


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

CREATE INDEX idx_clone_history_recipe ON public.clone_history USING btree (recipe_id);


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

CREATE INDEX idx_clone_recipes_company ON public.clone_recipes USING btree (company_id) WHERE (company_id IS NOT NULL);


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

CREATE INDEX idx_clone_recipes_source ON public.clone_recipes USING btree (source_connection_id);


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

CREATE INDEX idx_clone_recipes_target ON public.clone_recipes USING btree (target_connection_id);


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

CREATE INDEX idx_compliance_reports_company_domain ON public.compliance_reports USING btree (company_domain, generated_at DESC);


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

CREATE INDEX idx_compliance_reports_user_id ON public.compliance_reports USING btree (user_id, generated_at DESC);


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

CREATE INDEX idx_connections_key_rotation_status ON public.oracle_connections USING btree (key_rotation_status) WHERE (key_rotation_status <> 'idle'::text);


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

CREATE INDEX idx_connections_schedule_due ON public.oracle_connections USING btree (next_scheduled_run_at) WHERE (schedule_enabled = true);


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

CREATE INDEX idx_ebs_adop_state_patching ON public.ebs_adop_state USING btree (patching) WHERE (patching = true);


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

CREATE INDEX idx_ebs_deep_reports_connection_id ON public.ebs_deep_reports USING btree (connection_id);


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

CREATE INDEX idx_ebs_deep_reports_created_at ON public.ebs_deep_reports USING btree (created_at DESC);


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

CREATE INDEX idx_ebs_deep_reports_user_id ON public.ebs_deep_reports USING btree (user_id);


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

CREATE INDEX idx_ebs_module_runs_conn_at ON public.ebs_module_runs USING btree (connection_id, run_at DESC);


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

CREATE INDEX idx_ebs_sanity_runs_connection_id ON public.ebs_sanity_runs USING btree (connection_id);


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

CREATE INDEX idx_ebs_sanity_runs_run_at ON public.ebs_sanity_runs USING btree (run_at DESC);


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

CREATE INDEX idx_ebs_validation_runs_run_at ON public.ebs_validation_runs USING btree (run_at DESC);


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

CREATE INDEX idx_email_drip_state_step ON public.email_drip_state USING btree (sequence_step);


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

CREATE INDEX idx_email_drip_state_user_id ON public.email_drip_state USING btree (user_id);


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

CREATE INDEX idx_email_log_hc_id ON public.email_log USING btree (hc_id);


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

CREATE INDEX idx_email_log_sent_at ON public.email_log USING btree (sent_at DESC);


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

CREATE INDEX idx_email_log_template ON public.email_log USING btree (template);


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

CREATE INDEX idx_email_log_user_id ON public.email_log USING btree (user_id);


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

CREATE INDEX idx_finding_history_connection ON public.finding_history USING btree (connection_id);


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

CREATE INDEX idx_finding_history_first_seen_at ON public.finding_history USING btree (first_seen_at);


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

CREATE INDEX idx_finding_history_resolved_at ON public.finding_history USING btree (resolved_at) WHERE (resolved_at IS NOT NULL);


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

CREATE INDEX idx_fndload_history_action ON public.fndload_history USING btree (action);


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

CREATE INDEX idx_fndload_history_executed_at ON public.fndload_history USING btree (executed_at DESC);


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

CREATE INDEX idx_fndload_history_source_conn ON public.fndload_history USING btree (source_conn_id);


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

CREATE INDEX idx_fndload_history_target_conn ON public.fndload_history USING btree (target_conn_id);


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

CREATE INDEX idx_fndload_history_user_id ON public.fndload_history USING btree (user_id);


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

CREATE INDEX idx_install_jobs_conn_id ON public.install_jobs USING btree (connection_id);


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

CREATE INDEX idx_install_jobs_created ON public.install_jobs USING btree (created_at DESC);


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

CREATE INDEX idx_install_jobs_status ON public.install_jobs USING btree (status);


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

CREATE INDEX idx_install_jobs_user_id ON public.install_jobs USING btree (user_id);


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

CREATE INDEX idx_installer_runs_os_started ON public.installer_validation_runs USING btree (os, started_at DESC);


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

CREATE INDEX idx_installer_runs_overall ON public.installer_validation_runs USING btree (overall, started_at DESC);


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

CREATE INDEX idx_installer_runs_run_id ON public.installer_validation_runs USING btree (run_id);


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

CREATE INDEX idx_installer_runs_topology_started ON public.installer_validation_runs USING btree (topology, started_at DESC) WHERE (topology IS NOT NULL);


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

CREATE INDEX idx_installer_smoke_runs_run_id ON public.installer_smoke_runs USING btree (run_id);


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

CREATE INDEX idx_installer_smoke_runs_started_at ON public.installer_smoke_runs USING btree (started_at DESC);


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

CREATE INDEX idx_installer_smoke_tokens_token ON public.installer_smoke_tokens USING btree (token) WHERE (used_at IS NULL);


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

CREATE INDEX idx_job_log_lines_job_seq ON public.job_log_lines USING btree (job_id, seq);


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

CREATE INDEX idx_mfa_attempts_user_id_time ON public.mfa_attempts USING btree (user_id, attempted_at DESC);


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

CREATE INDEX idx_oc_ebs_instance_name ON public.oracle_connections USING btree (ebs_instance_name) WHERE (ebs_instance_name IS NOT NULL);


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

CREATE INDEX idx_oracle_connections_first_run ON public.oracle_connections USING btree (first_run_completed_at) WHERE (first_run_completed_at IS NULL);


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

CREATE INDEX idx_oracle_connections_install_stalled ON public.oracle_connections USING btree (install_token_issued_at) WHERE ((install_token_issued_at IS NOT NULL) AND (first_heartbeat_at IS NULL));


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

CREATE INDEX idx_oracle_connections_status ON public.oracle_connections USING btree (status) WHERE (status = 'pending_registration'::text);


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

CREATE INDEX idx_outreach_attempts_at ON public.outreach_attempts USING btree (attempted_at DESC);


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

CREATE INDEX idx_page_events_name_created ON public.page_events USING btree (event_name, created_at);


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

CREATE INDEX idx_page_events_type_created ON public.page_events USING btree (event_type, created_at);


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

CREATE INDEX idx_payment_reconciliation_occurred_at ON public.payment_reconciliation USING btree (occurred_at DESC);


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

CREATE INDEX idx_payment_reconciliation_user_id ON public.payment_reconciliation USING btree (user_id);


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

CREATE INDEX idx_payments_razorpay_order_id ON public.payments USING btree (razorpay_order_id);


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

CREATE INDEX idx_payments_razorpay_payment_id ON public.payments USING btree (razorpay_payment_id);


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

CREATE INDEX idx_payments_status ON public.payments USING btree (status);


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

CREATE INDEX idx_payments_user_id ON public.payments USING btree (user_id);


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

CREATE INDEX idx_preflight_runs_conn_created ON public.listener_preflight_runs USING btree (connection_id, created_at);


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

CREATE INDEX idx_preflight_runs_user ON public.listener_preflight_runs USING btree (user_id);


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

CREATE INDEX idx_roles_team_id ON public.roles USING btree (team_id);


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

CREATE INDEX idx_sample_report_leads_email ON public.sample_report_leads USING btree (email);


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

CREATE INDEX idx_schedules_due ON public.connection_schedules USING btree (next_run_at) WHERE (enabled = true);


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

CREATE INDEX idx_smoke_test_runs_connection ON public.smoke_test_runs USING btree (connection_id, started_at DESC);


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

CREATE INDEX idx_sql_audit_log_allowed ON public.sql_audit_log USING btree (allowed);


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

CREATE INDEX idx_sql_audit_log_connection_id ON public.sql_audit_log USING btree (connection_id);


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

CREATE INDEX idx_sql_audit_log_executed_at ON public.sql_audit_log USING btree (executed_at);


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

CREATE INDEX idx_sql_audit_log_user_id ON public.sql_audit_log USING btree (user_id);


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

CREATE INDEX idx_sql_console_history_executed_at ON public.sql_console_history USING btree (executed_at);


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

CREATE INDEX idx_sql_console_history_user_conn ON public.sql_console_history USING btree (user_id, connection_id, executed_at DESC);


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

CREATE INDEX idx_sql_fix_cache_expires ON public.sql_fix_cache USING btree (expires_at);


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

CREATE UNIQUE INDEX idx_sql_fix_cache_key ON public.sql_fix_cache USING btree (sql_id, plan_hash_value);


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

CREATE INDEX idx_sql_tuning_connection_created ON public.sql_tuning_findings USING btree (connection_id, created_at DESC);


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

CREATE INDEX idx_sql_tuning_connection_sql ON public.sql_tuning_findings USING btree (connection_id, sql_id);


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

CREATE INDEX idx_ssh_audit_target ON public.ssh_audit USING btree (target_id);


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

CREATE INDEX idx_ssh_audit_ts ON public.ssh_audit USING btree (ts DESC);


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

CREATE INDEX idx_ssh_install_creds_conn ON public.ssh_install_credentials USING btree (connection_id);


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

CREATE INDEX idx_ssh_install_creds_user ON public.ssh_install_credentials USING btree (user_id);


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

CREATE UNIQUE INDEX idx_ssh_profiles_conn_role ON public.connection_ssh_profiles USING btree (connection_id, role);


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

CREATE INDEX idx_ssh_profiles_connection ON public.connection_ssh_profiles USING btree (connection_id);


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

CREATE INDEX idx_ssh_targets_connection ON public.ssh_targets USING btree (connection_id);


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

CREATE INDEX idx_ssh_targets_user ON public.ssh_targets USING btree (user_id);


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

CREATE INDEX idx_sso_configs_domain ON public.sso_configs USING btree (company_domain);


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

CREATE INDEX idx_sso_login_log_domain_time ON public.sso_login_log USING btree (company_domain, attempted_at DESC);


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

CREATE INDEX idx_subscriptions_razorpay_id ON public.subscriptions USING btree (razorpay_subscription_id);


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

CREATE INDEX idx_subscriptions_status ON public.subscriptions USING btree (status);


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

CREATE INDEX idx_subscriptions_user_id ON public.subscriptions USING btree (user_id);


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

CREATE INDEX idx_team_invites_email ON public.team_invites USING btree (email);


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

CREATE INDEX idx_team_invites_team_id ON public.team_invites USING btree (team_id);


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

CREATE INDEX idx_team_invites_token ON public.team_invites USING btree (token);


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

CREATE INDEX idx_team_members_team_id ON public.team_members USING btree (team_id);


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

CREATE INDEX idx_team_members_user_id ON public.team_members USING btree (user_id);


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

CREATE INDEX idx_tns_topology_snapshots_conn_created ON public.tns_topology_snapshots USING btree (connection_id, created_at);


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

CREATE INDEX idx_tns_topology_snapshots_share_token ON public.tns_topology_snapshots USING btree (share_token) WHERE (share_token IS NOT NULL);


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

CREATE INDEX idx_tuneops_notif_log_dedup ON public.tuneops_notification_log USING btree (ticket_number, event_type, recipient_email, sent_at);


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

CREATE INDEX idx_tuneops_notif_log_ticket ON public.tuneops_notification_log USING btree (ticket_number, sent_at);


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

CREATE INDEX idx_tuneops_notif_mutes_lookup ON public.tuneops_notification_mutes USING btree (user_id, connection_id);


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

CREATE INDEX idx_tuneops_notif_prefs_user_id ON public.tuneops_notification_prefs USING btree (user_id);


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

CREATE INDEX idx_tuneops_tickets_canonical ON public.tuneops_tickets USING btree (canonical_key) WHERE (canonical_key IS NOT NULL);


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

CREATE INDEX idx_tuneops_tickets_company ON public.tuneops_tickets USING btree (company_id) WHERE (company_id IS NOT NULL);


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

CREATE INDEX idx_tuneops_tickets_connection ON public.tuneops_tickets USING btree (connection_id);


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

CREATE UNIQUE INDEX idx_tuneops_tickets_number ON public.tuneops_tickets USING btree (ticket_number);


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

CREATE INDEX idx_tuneops_tickets_status ON public.tuneops_tickets USING btree (status);


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

CREATE INDEX idx_upgrade_audit_connection_id ON public.agent_upgrade_audit USING btree (connection_id, triggered_at DESC);


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

CREATE INDEX idx_upgrade_audit_failures ON public.agent_upgrade_audit USING btree (connection_id, triggered_at) WHERE (status = 'failed'::text);


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

CREATE INDEX idx_user_credits_user_id ON public.user_credits USING btree (user_id);


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

CREATE INDEX idx_user_hc_usage_email ON public.user_hc_usage USING btree (lower((user_email)::text));


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

CREATE INDEX idx_user_mfa_user_id ON public.user_mfa USING btree (user_id);


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

CREATE INDEX idx_user_preferences_user_id ON public.user_preferences USING btree (user_id);


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

CREATE INDEX idx_validation_runs_connection ON public.validation_runs USING btree (connection_id, started_at DESC);


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

CREATE INDEX idx_validation_runs_share_token ON public.validation_runs USING btree (share_token) WHERE (share_token IS NOT NULL);


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

CREATE INDEX magic_link_tokens_email_idx ON public.magic_link_tokens USING btree (email);


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

CREATE INDEX magic_link_tokens_token_idx ON public.magic_link_tokens USING btree (token);


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

CREATE INDEX oracle_connections_created_at_idx ON public.oracle_connections USING btree (created_at DESC);


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

CREATE INDEX outreach_send_log_attempted_at_idx ON public.outreach_send_log USING btree (attempted_at DESC);


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

CREATE INDEX outreach_send_log_batch_id_idx ON public.outreach_send_log USING btree (batch_id);


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

CREATE INDEX payment_test_runs_ran_at_idx ON public.payment_test_runs USING btree (ran_at);


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

CREATE INDEX pmtr_ran_at_idx ON public.payment_method_test_runs USING btree (ran_at DESC);


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

CREATE INDEX proxy_exec_audit_conn_idx ON public.proxy_exec_audit USING btree (connection_id, executed_at DESC);


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

CREATE INDEX proxy_exec_audit_user_idx ON public.proxy_exec_audit USING btree (user_id, executed_at DESC);


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

CREATE INDEX rbac_audit_log_denied_at_idx ON public.rbac_audit_log USING btree (denied_at DESC);


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

CREATE INDEX rbac_audit_log_user_id_idx ON public.rbac_audit_log USING btree (user_id);


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

CREATE INDEX roadmap_reminders_dismissed_at_idx ON public.roadmap_reminders USING btree (dismissed_at);


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

CREATE UNIQUE INDEX users_email_unique_idx ON public.users USING btree (lower((email)::text));


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

CREATE UNIQUE INDEX users_google_id_idx ON public.users USING btree (google_id) WHERE (google_id IS NOT NULL);


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

CREATE INDEX users_stripe_subscription_id_idx ON public.users USING btree (stripe_subscription_id);


--
-- Name: agent_diagnose_runs after_diagnose_insert; Type: TRIGGER; Schema: public; Owner: -
--

CREATE TRIGGER after_diagnose_insert AFTER INSERT ON public.agent_diagnose_runs FOR EACH ROW EXECUTE FUNCTION public.trim_agent_diagnose_runs();


--
-- Name: listener_preflight_runs after_preflight_insert; Type: TRIGGER; Schema: public; Owner: -
--

CREATE TRIGGER after_preflight_insert AFTER INSERT ON public.listener_preflight_runs FOR EACH ROW EXECUTE FUNCTION public.trim_preflight_runs();


--
-- Name: activity_log activity_log_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.activity_log
    ADD CONSTRAINT activity_log_connection_id_fkey FOREIGN KEY (connection_id) REFERENCES public.oracle_connections(id) ON DELETE SET NULL;


--
-- Name: activity_log activity_log_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.activity_log
    ADD CONSTRAINT activity_log_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE SET NULL;


--
-- Name: addm_runs addm_runs_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.addm_runs
    ADD CONSTRAINT addm_runs_connection_id_fkey FOREIGN KEY (connection_id) REFERENCES public.oracle_connections(id) ON DELETE CASCADE;


--
-- Name: addm_runs addm_runs_created_by_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.addm_runs
    ADD CONSTRAINT addm_runs_created_by_fkey FOREIGN KEY (created_by) REFERENCES public.users(id);


--
-- Name: advisor_findings advisor_findings_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.advisor_findings
    ADD CONSTRAINT advisor_findings_connection_id_fkey FOREIGN KEY (connection_id) REFERENCES public.oracle_connections(id) ON DELETE CASCADE;


--
-- Name: agent_channel_state agent_channel_state_agent_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.agent_channel_state
    ADD CONSTRAINT agent_channel_state_agent_id_fkey FOREIGN KEY (agent_id) REFERENCES public.oracle_connections(id) ON DELETE CASCADE;


--
-- Name: agent_command_queue agent_command_queue_agent_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.agent_command_queue
    ADD CONSTRAINT agent_command_queue_agent_id_fkey FOREIGN KEY (agent_id) REFERENCES public.oracle_connections(id) ON DELETE CASCADE;


--
-- Name: agent_command_results agent_command_results_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.agent_command_results
    ADD CONSTRAINT agent_command_results_connection_id_fkey FOREIGN KEY (connection_id) REFERENCES public.oracle_connections(id) ON DELETE CASCADE;


--
-- Name: agent_command_results agent_command_results_requested_by_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.agent_command_results
    ADD CONSTRAINT agent_command_results_requested_by_fkey FOREIGN KEY (requested_by) REFERENCES public.users(id) ON DELETE SET NULL;


--
-- Name: agent_crash_alerts_sent agent_crash_alerts_sent_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.agent_crash_alerts_sent
    ADD CONSTRAINT agent_crash_alerts_sent_connection_id_fkey FOREIGN KEY (connection_id) REFERENCES public.oracle_connections(id) ON DELETE CASCADE;


--
-- Name: agent_diagnose_runs agent_diagnose_runs_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.agent_diagnose_runs
    ADD CONSTRAINT agent_diagnose_runs_connection_id_fkey FOREIGN KEY (connection_id) REFERENCES public.oracle_connections(id) ON DELETE CASCADE;


--
-- Name: agent_install_failures agent_install_failures_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.agent_install_failures
    ADD CONSTRAINT agent_install_failures_connection_id_fkey FOREIGN KEY (connection_id) REFERENCES public.oracle_connections(id) ON DELETE SET NULL;


--
-- Name: agent_reg_tokens agent_reg_tokens_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.agent_reg_tokens
    ADD CONSTRAINT agent_reg_tokens_connection_id_fkey FOREIGN KEY (connection_id) REFERENCES public.oracle_connections(id) ON DELETE CASCADE;


--
-- Name: agent_restart_events agent_restart_events_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.agent_restart_events
    ADD CONSTRAINT agent_restart_events_connection_id_fkey FOREIGN KEY (connection_id) REFERENCES public.oracle_connections(id) ON DELETE CASCADE;


--
-- Name: agent_tunnels agent_tunnels_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.agent_tunnels
    ADD CONSTRAINT agent_tunnels_connection_id_fkey FOREIGN KEY (connection_id) REFERENCES public.oracle_connections(id) ON DELETE CASCADE;


--
-- Name: agent_upgrade_audit agent_upgrade_audit_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.agent_upgrade_audit
    ADD CONSTRAINT agent_upgrade_audit_connection_id_fkey FOREIGN KEY (connection_id) REFERENCES public.oracle_connections(id) ON DELETE CASCADE;


--
-- Name: agents_log_buffer agents_log_buffer_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.agents_log_buffer
    ADD CONSTRAINT agents_log_buffer_connection_id_fkey FOREIGN KEY (connection_id) REFERENCES public.oracle_connections(id) ON DELETE CASCADE;


--
-- Name: alert_events alert_events_acknowledged_by_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.alert_events
    ADD CONSTRAINT alert_events_acknowledged_by_fkey FOREIGN KEY (acknowledged_by) REFERENCES public.users(id) ON DELETE SET NULL;


--
-- Name: alert_events alert_events_check_run_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.alert_events
    ADD CONSTRAINT alert_events_check_run_id_fkey FOREIGN KEY (check_run_id) REFERENCES public.health_checks(id) ON DELETE SET NULL;


--
-- Name: alert_events alert_events_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.alert_events
    ADD CONSTRAINT alert_events_connection_id_fkey FOREIGN KEY (connection_id) REFERENCES public.oracle_connections(id) ON DELETE CASCADE;


--
-- Name: alert_events alert_events_policy_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.alert_events
    ADD CONSTRAINT alert_events_policy_id_fkey FOREIGN KEY (policy_id) REFERENCES public.alert_policies(id) ON DELETE CASCADE;


--
-- Name: alert_policies alert_policies_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.alert_policies
    ADD CONSTRAINT alert_policies_connection_id_fkey FOREIGN KEY (connection_id) REFERENCES public.oracle_connections(id) ON DELETE CASCADE;


--
-- Name: alert_policies alert_policies_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

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


--
-- Name: analysis_runs analysis_runs_health_check_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.analysis_runs
    ADD CONSTRAINT analysis_runs_health_check_id_fkey FOREIGN KEY (health_check_id) REFERENCES public.health_checks(id);


--
-- Name: api_keys api_keys_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

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


--
-- Name: approval_requests approval_requests_approved_by_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.approval_requests
    ADD CONSTRAINT approval_requests_approved_by_fkey FOREIGN KEY (approved_by) REFERENCES public.users(id) ON DELETE SET NULL;


--
-- Name: approval_requests approval_requests_approver_role_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.approval_requests
    ADD CONSTRAINT approval_requests_approver_role_id_fkey FOREIGN KEY (approver_role_id) REFERENCES public.roles(id) ON DELETE CASCADE;


--
-- Name: approval_requests approval_requests_requester_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.approval_requests
    ADD CONSTRAINT approval_requests_requester_id_fkey FOREIGN KEY (requester_id) REFERENCES public.users(id) ON DELETE CASCADE;


--
-- Name: check_failure_bundles check_failure_bundles_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.check_failure_bundles
    ADD CONSTRAINT check_failure_bundles_connection_id_fkey FOREIGN KEY (connection_id) REFERENCES public.oracle_connections(id) ON DELETE SET NULL;


--
-- Name: check_failure_bundles check_failure_bundles_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.check_failure_bundles
    ADD CONSTRAINT check_failure_bundles_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE SET NULL;


--
-- Name: check_results check_results_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.check_results
    ADD CONSTRAINT check_results_connection_id_fkey FOREIGN KEY (connection_id) REFERENCES public.oracle_connections(id) ON DELETE CASCADE;


--
-- Name: clone_history clone_history_recipe_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.clone_history
    ADD CONSTRAINT clone_history_recipe_id_fkey FOREIGN KEY (recipe_id) REFERENCES public.clone_recipes(id) ON DELETE SET NULL;


--
-- Name: clone_history clone_history_source_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.clone_history
    ADD CONSTRAINT clone_history_source_connection_id_fkey FOREIGN KEY (source_connection_id) REFERENCES public.oracle_connections(id) ON DELETE SET NULL;


--
-- Name: clone_history clone_history_started_by_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.clone_history
    ADD CONSTRAINT clone_history_started_by_fkey FOREIGN KEY (started_by) REFERENCES public.users(id) ON DELETE SET NULL;


--
-- Name: clone_history clone_history_target_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.clone_history
    ADD CONSTRAINT clone_history_target_connection_id_fkey FOREIGN KEY (target_connection_id) REFERENCES public.oracle_connections(id) ON DELETE SET NULL;


--
-- Name: clone_recipes clone_recipes_created_by_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.clone_recipes
    ADD CONSTRAINT clone_recipes_created_by_fkey FOREIGN KEY (created_by) REFERENCES public.users(id) ON DELETE SET NULL;


--
-- Name: clone_recipes clone_recipes_source_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.clone_recipes
    ADD CONSTRAINT clone_recipes_source_connection_id_fkey FOREIGN KEY (source_connection_id) REFERENCES public.oracle_connections(id) ON DELETE SET NULL;


--
-- Name: clone_recipes clone_recipes_target_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.clone_recipes
    ADD CONSTRAINT clone_recipes_target_connection_id_fkey FOREIGN KEY (target_connection_id) REFERENCES public.oracle_connections(id) ON DELETE SET NULL;


--
-- Name: compliance_reports compliance_reports_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

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


--
-- Name: connection_health_runs connection_health_runs_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.connection_health_runs
    ADD CONSTRAINT connection_health_runs_connection_id_fkey FOREIGN KEY (connection_id) REFERENCES public.oracle_connections(id) ON DELETE CASCADE;


--
-- Name: connection_schedules connection_schedules_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.connection_schedules
    ADD CONSTRAINT connection_schedules_connection_id_fkey FOREIGN KEY (connection_id) REFERENCES public.oracle_connections(id) ON DELETE CASCADE;


--
-- Name: connection_ssh_profiles connection_ssh_profiles_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.connection_ssh_profiles
    ADD CONSTRAINT connection_ssh_profiles_connection_id_fkey FOREIGN KEY (connection_id) REFERENCES public.oracle_connections(id) ON DELETE CASCADE;


--
-- Name: demo_runs demo_runs_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

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


--
-- Name: ebs_adop_state ebs_adop_state_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.ebs_adop_state
    ADD CONSTRAINT ebs_adop_state_connection_id_fkey FOREIGN KEY (connection_id) REFERENCES public.oracle_connections(id) ON DELETE CASCADE;


--
-- Name: ebs_credentials ebs_credentials_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.ebs_credentials
    ADD CONSTRAINT ebs_credentials_connection_id_fkey FOREIGN KEY (connection_id) REFERENCES public.oracle_connections(id) ON DELETE CASCADE;


--
-- Name: ebs_deep_reports ebs_deep_reports_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.ebs_deep_reports
    ADD CONSTRAINT ebs_deep_reports_connection_id_fkey FOREIGN KEY (connection_id) REFERENCES public.oracle_connections(id) ON DELETE CASCADE;


--
-- Name: ebs_deep_reports ebs_deep_reports_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

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


--
-- Name: ebs_jobs ebs_jobs_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.ebs_jobs
    ADD CONSTRAINT ebs_jobs_connection_id_fkey FOREIGN KEY (connection_id) REFERENCES public.oracle_connections(id) ON DELETE CASCADE;


--
-- Name: ebs_sanity_runs ebs_sanity_runs_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.ebs_sanity_runs
    ADD CONSTRAINT ebs_sanity_runs_connection_id_fkey FOREIGN KEY (connection_id) REFERENCES public.oracle_connections(id) ON DELETE CASCADE;


--
-- Name: email_drip_state email_drip_state_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

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


--
-- Name: email_log email_log_hc_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.email_log
    ADD CONSTRAINT email_log_hc_id_fkey FOREIGN KEY (hc_id) REFERENCES public.health_checks(id) ON DELETE SET NULL;


--
-- Name: email_log email_log_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.email_log
    ADD CONSTRAINT email_log_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE SET NULL;


--
-- Name: finding_history finding_history_schedule_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.finding_history
    ADD CONSTRAINT finding_history_schedule_id_fkey FOREIGN KEY (schedule_id) REFERENCES public.connection_schedules(id) ON DELETE CASCADE;


--
-- Name: fndload_history fndload_history_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.fndload_history
    ADD CONSTRAINT fndload_history_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE SET NULL;


--
-- Name: health_checks health_checks_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.health_checks
    ADD CONSTRAINT health_checks_connection_id_fkey FOREIGN KEY (connection_id) REFERENCES public.oracle_connections(id);


--
-- Name: health_checks health_checks_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

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


--
-- Name: install_jobs install_jobs_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.install_jobs
    ADD CONSTRAINT install_jobs_connection_id_fkey FOREIGN KEY (connection_id) REFERENCES public.oracle_connections(id) ON DELETE SET NULL;


--
-- Name: job_log_lines job_log_lines_job_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.job_log_lines
    ADD CONSTRAINT job_log_lines_job_id_fkey FOREIGN KEY (job_id) REFERENCES public.install_jobs(id) ON DELETE CASCADE;


--
-- Name: listener_preflight_runs listener_preflight_runs_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.listener_preflight_runs
    ADD CONSTRAINT listener_preflight_runs_connection_id_fkey FOREIGN KEY (connection_id) REFERENCES public.oracle_connections(id) ON DELETE CASCADE;


--
-- Name: listener_preflight_runs listener_preflight_runs_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.listener_preflight_runs
    ADD CONSTRAINT listener_preflight_runs_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE SET NULL;


--
-- Name: mfa_attempts mfa_attempts_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

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


--
-- Name: oracle_connections oracle_connections_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

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


--
-- Name: outreach_batches outreach_batches_approved_by_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.outreach_batches
    ADD CONSTRAINT outreach_batches_approved_by_fkey FOREIGN KEY (approved_by) REFERENCES public.users(id);


--
-- Name: outreach_recipients outreach_recipients_batch_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.outreach_recipients
    ADD CONSTRAINT outreach_recipients_batch_id_fkey FOREIGN KEY (batch_id) REFERENCES public.outreach_batches(id) ON DELETE CASCADE;


--
-- Name: payments payments_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.payments
    ADD CONSTRAINT payments_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE SET NULL;


--
-- Name: proxy_exec_audit proxy_exec_audit_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.proxy_exec_audit
    ADD CONSTRAINT proxy_exec_audit_connection_id_fkey FOREIGN KEY (connection_id) REFERENCES public.oracle_connections(id) ON DELETE CASCADE;


--
-- Name: proxy_exec_audit proxy_exec_audit_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.proxy_exec_audit
    ADD CONSTRAINT proxy_exec_audit_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE SET NULL;


--
-- Name: rbac_audit_log rbac_audit_log_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

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


--
-- Name: roles roles_approval_required_from_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.roles
    ADD CONSTRAINT roles_approval_required_from_fkey FOREIGN KEY (approval_required_from) REFERENCES public.roles(id) ON DELETE SET NULL;


--
-- Name: roles roles_team_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.roles
    ADD CONSTRAINT roles_team_id_fkey FOREIGN KEY (team_id) REFERENCES public.teams(id) ON DELETE CASCADE;


--
-- Name: smoke_test_runs smoke_test_runs_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.smoke_test_runs
    ADD CONSTRAINT smoke_test_runs_connection_id_fkey FOREIGN KEY (connection_id) REFERENCES public.oracle_connections(id) ON DELETE CASCADE;


--
-- Name: smoke_test_runs smoke_test_runs_triggered_by_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.smoke_test_runs
    ADD CONSTRAINT smoke_test_runs_triggered_by_user_id_fkey FOREIGN KEY (triggered_by_user_id) REFERENCES public.users(id) ON DELETE SET NULL;


--
-- Name: sql_audit_log sql_audit_log_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.sql_audit_log
    ADD CONSTRAINT sql_audit_log_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE SET NULL;


--
-- Name: sql_tuning_findings sql_tuning_findings_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.sql_tuning_findings
    ADD CONSTRAINT sql_tuning_findings_connection_id_fkey FOREIGN KEY (connection_id) REFERENCES public.oracle_connections(id) ON DELETE CASCADE;


--
-- Name: ssh_audit ssh_audit_target_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.ssh_audit
    ADD CONSTRAINT ssh_audit_target_id_fkey FOREIGN KEY (target_id) REFERENCES public.ssh_targets(id) ON DELETE CASCADE;


--
-- Name: ssh_install_credentials ssh_install_credentials_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.ssh_install_credentials
    ADD CONSTRAINT ssh_install_credentials_connection_id_fkey FOREIGN KEY (connection_id) REFERENCES public.oracle_connections(id) ON DELETE CASCADE;


--
-- Name: ssh_install_credentials ssh_install_credentials_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

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


--
-- Name: ssh_targets ssh_targets_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.ssh_targets
    ADD CONSTRAINT ssh_targets_connection_id_fkey FOREIGN KEY (connection_id) REFERENCES public.oracle_connections(id) ON DELETE SET NULL;


--
-- Name: ssh_targets ssh_targets_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

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


--
-- Name: subscriptions subscriptions_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.subscriptions
    ADD CONSTRAINT subscriptions_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE SET NULL;


--
-- Name: team_invites team_invites_invited_by_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.team_invites
    ADD CONSTRAINT team_invites_invited_by_fkey FOREIGN KEY (invited_by) REFERENCES public.users(id) ON DELETE CASCADE;


--
-- Name: team_invites team_invites_team_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.team_invites
    ADD CONSTRAINT team_invites_team_id_fkey FOREIGN KEY (team_id) REFERENCES public.teams(id) ON DELETE CASCADE;


--
-- Name: team_members team_members_role_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.team_members
    ADD CONSTRAINT team_members_role_id_fkey FOREIGN KEY (role_id) REFERENCES public.roles(id) ON DELETE SET NULL;


--
-- Name: team_members team_members_team_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.team_members
    ADD CONSTRAINT team_members_team_id_fkey FOREIGN KEY (team_id) REFERENCES public.teams(id) ON DELETE CASCADE;


--
-- Name: team_members team_members_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

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


--
-- Name: teams teams_owner_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.teams
    ADD CONSTRAINT teams_owner_id_fkey FOREIGN KEY (owner_id) REFERENCES public.users(id) ON DELETE CASCADE;


--
-- Name: tns_topology_snapshots tns_topology_snapshots_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.tns_topology_snapshots
    ADD CONSTRAINT tns_topology_snapshots_connection_id_fkey FOREIGN KEY (connection_id) REFERENCES public.oracle_connections(id) ON DELETE CASCADE;


--
-- Name: tuneops_notification_mutes tuneops_notification_mutes_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

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


--
-- Name: tuneops_notification_prefs tuneops_notification_prefs_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

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


--
-- Name: tuneops_tickets tuneops_tickets_approved_by_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.tuneops_tickets
    ADD CONSTRAINT tuneops_tickets_approved_by_fkey FOREIGN KEY (approved_by) REFERENCES public.users(id) ON DELETE SET NULL;


--
-- Name: tuneops_tickets tuneops_tickets_assigned_to_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.tuneops_tickets
    ADD CONSTRAINT tuneops_tickets_assigned_to_fkey FOREIGN KEY (assigned_to) REFERENCES public.users(id) ON DELETE SET NULL;


--
-- Name: tuneops_tickets tuneops_tickets_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.tuneops_tickets
    ADD CONSTRAINT tuneops_tickets_connection_id_fkey FOREIGN KEY (connection_id) REFERENCES public.oracle_connections(id) ON DELETE SET NULL;


--
-- Name: tuneops_tickets tuneops_tickets_executed_by_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.tuneops_tickets
    ADD CONSTRAINT tuneops_tickets_executed_by_fkey FOREIGN KEY (executed_by) REFERENCES public.users(id) ON DELETE SET NULL;


--
-- Name: tuneops_tickets tuneops_tickets_resolved_by_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.tuneops_tickets
    ADD CONSTRAINT tuneops_tickets_resolved_by_fkey FOREIGN KEY (resolved_by) REFERENCES public.users(id) ON DELETE SET NULL;


--
-- Name: user_credits user_credits_subscription_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.user_credits
    ADD CONSTRAINT user_credits_subscription_id_fkey FOREIGN KEY (subscription_id) REFERENCES public.subscriptions(id) ON DELETE SET NULL;


--
-- Name: user_credits user_credits_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

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


--
-- Name: user_mfa user_mfa_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

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


--
-- Name: user_preferences user_preferences_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

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


--
-- Name: users users_team_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.users
    ADD CONSTRAINT users_team_id_fkey FOREIGN KEY (team_id) REFERENCES public.teams(id) ON DELETE SET NULL;


--
-- Name: validation_runs validation_runs_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.validation_runs
    ADD CONSTRAINT validation_runs_connection_id_fkey FOREIGN KEY (connection_id) REFERENCES public.oracle_connections(id) ON DELETE CASCADE;


--
-- Name: validation_runs validation_runs_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.validation_runs
    ADD CONSTRAINT validation_runs_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE SET NULL;


--
-- PostgreSQL database dump complete
--

\unrestrict 2lzp0HGi78iMtGdRe0AKt1WUC3N6zN2DAoA5IykMMKEEREzQY7OxeSfr5dPPi01

