--
-- PostgreSQL database dump
--

\restrict hRi4nBNv2E5FXxBTf47fTk0vxfJNiXtnegSYFeraY46zaCyMMlYNanEdl70C1E7

-- Dumped from database version 18.1 (Homebrew)
-- Dumped by pg_dump version 18.1 (Homebrew)

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

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

CREATE SCHEMA public;


ALTER SCHEMA public OWNER TO pg_database_owner;

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

COMMENT ON SCHEMA public IS 'standard public schema';


--
-- Name: auto_match_face_speaker(character varying, double precision); Type: FUNCTION; Schema: public; Owner: accusys
--

CREATE FUNCTION public.auto_match_face_speaker(p_video_uuid character varying, p_threshold double precision DEFAULT 0.5) RETURNS TABLE(face_id character varying, speaker_id character varying, confidence double precision, match_count bigint)
    LANGUAGE plpgsql
    AS $$
BEGIN
    RETURN QUERY
    -- Find face detections that overlap with ASRX segments
    SELECT 
        fd.face_id,
        seg.speaker_id,
        COUNT(*)::DOUBLE PRECISION / NULLIF(COUNT(DISTINCT seg.speaker_id), 0) AS confidence,
        COUNT(*) AS match_count
    FROM face_detections fd
    CROSS JOIN LATERAL (
        SELECT 
            seg_data->>'speaker_id' AS speaker_id,
            (seg_data->>'start')::DOUBLE PRECISION AS seg_start,
            (seg_data->>'end')::DOUBLE PRECISION AS seg_end
        FROM face_recognition_results frr,
             jsonb_array_elements(frr.result_data->'frames') AS frame_data,
             jsonb_array_elements(frame_data->'faces') AS face_data,
             jsonb_array_elements(frr.result_data->'segments') AS seg_data
        WHERE frr.video_uuid = p_video_uuid
          AND face_data->>'face_id' = fd.face_id
    ) seg
    WHERE fd.video_uuid = p_video_uuid
      AND fd.timestamp_secs >= seg.seg_start
      AND fd.timestamp_secs <= seg.seg_end
      AND fd.face_id IS NOT NULL
      AND seg.speaker_id IS NOT NULL
    GROUP BY fd.face_id, seg.speaker_id
    HAVING COUNT(*)::DOUBLE PRECISION / NULLIF(COUNT(DISTINCT seg.speaker_id), 0) >= p_threshold
    ORDER BY confidence DESC;
END;
$$;


ALTER FUNCTION public.auto_match_face_speaker(p_video_uuid character varying, p_threshold double precision) OWNER TO accusys;

--
-- Name: FUNCTION auto_match_face_speaker(p_video_uuid character varying, p_threshold double precision); Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON FUNCTION public.auto_match_face_speaker(p_video_uuid character varying, p_threshold double precision) IS 'Automatically matches face detections with speaker segments';


--
-- Name: find_or_create_face_identity(character varying, character varying, public.vector, jsonb, jsonb); Type: FUNCTION; Schema: public; Owner: accusys
--

CREATE FUNCTION public.find_or_create_face_identity(p_face_id character varying, p_name character varying DEFAULT NULL::character varying, p_embedding public.vector DEFAULT NULL::public.vector, p_attributes jsonb DEFAULT NULL::jsonb, p_metadata jsonb DEFAULT '{}'::jsonb) RETURNS integer
    LANGUAGE plpgsql
    AS $$
DECLARE
    v_id INTEGER;
BEGIN
    -- Try to find existing face identity
    SELECT id INTO v_id
    FROM face_identities
    WHERE face_id = p_face_id;
    
    IF v_id IS NULL THEN
        -- Create new face identity
        INSERT INTO face_identities (face_id, name, embedding, attributes, metadata)
        VALUES (p_face_id, p_name, p_embedding, p_attributes, p_metadata)
        RETURNING id INTO v_id;
    ELSE
        -- Update existing face identity
        UPDATE face_identities
        SET 
            name = COALESCE(p_name, name),
            embedding = COALESCE(p_embedding, embedding),
            attributes = COALESCE(p_attributes, attributes),
            metadata = COALESCE(p_metadata, metadata),
            updated_at = CURRENT_TIMESTAMP
        WHERE id = v_id;
    END IF;
    
    RETURN v_id;
END;
$$;


ALTER FUNCTION public.find_or_create_face_identity(p_face_id character varying, p_name character varying, p_embedding public.vector, p_attributes jsonb, p_metadata jsonb) OWNER TO accusys;

--
-- Name: FUNCTION find_or_create_face_identity(p_face_id character varying, p_name character varying, p_embedding public.vector, p_attributes jsonb, p_metadata jsonb); Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON FUNCTION public.find_or_create_face_identity(p_face_id character varying, p_name character varying, p_embedding public.vector, p_attributes jsonb, p_metadata jsonb) IS 'Finds or creates a face identity record';


--
-- Name: find_persons_at_time(character varying, double precision, double precision); Type: FUNCTION; Schema: public; Owner: accusys
--

CREATE FUNCTION public.find_persons_at_time(p_video_uuid character varying, p_time double precision, p_tolerance double precision DEFAULT 0.0) RETURNS TABLE(person_id character varying, name character varying, confidence double precision, appearance_id integer)
    LANGUAGE plpgsql
    AS $$
BEGIN
    RETURN QUERY
    SELECT 
        pi.person_id,
        pi.name,
        pa.confidence,
        pa.id AS appearance_id
    FROM person_appearances pa
    JOIN person_identities pi ON pa.person_id = pi.person_id
    WHERE pa.video_uuid = p_video_uuid
      AND pa.start_time <= p_time + p_tolerance
      AND pa.end_time >= p_time - p_tolerance
    ORDER BY pa.confidence DESC;
END;
$$;


ALTER FUNCTION public.find_persons_at_time(p_video_uuid character varying, p_time double precision, p_tolerance double precision) OWNER TO accusys;

--
-- Name: FUNCTION find_persons_at_time(p_video_uuid character varying, p_time double precision, p_tolerance double precision); Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON FUNCTION public.find_persons_at_time(p_video_uuid character varying, p_time double precision, p_tolerance double precision) IS 'Finds persons appearing at a specific time in video';


--
-- Name: find_persons_in_range(character varying, double precision, double precision); Type: FUNCTION; Schema: public; Owner: accusys
--

CREATE FUNCTION public.find_persons_in_range(p_video_uuid character varying, p_start_time double precision, p_end_time double precision) RETURNS TABLE(person_id character varying, name character varying, overlap_duration double precision, confidence double precision)
    LANGUAGE plpgsql
    AS $$
BEGIN
    RETURN QUERY
    SELECT 
        pi.person_id,
        pi.name,
        LEAST(pa.end_time, p_end_time) - GREATEST(pa.start_time, p_start_time) AS overlap_duration,
        AVG(pa.confidence) AS confidence
    FROM person_appearances pa
    JOIN person_identities pi ON pa.person_id = pi.person_id
    WHERE pa.video_uuid = p_video_uuid
      AND pa.start_time < p_end_time
      AND pa.end_time > p_start_time
    GROUP BY pi.person_id, pi.name, pa.end_time, pa.start_time
    ORDER BY overlap_duration DESC;
END;
$$;


ALTER FUNCTION public.find_persons_in_range(p_video_uuid character varying, p_start_time double precision, p_end_time double precision) OWNER TO accusys;

--
-- Name: FUNCTION find_persons_in_range(p_video_uuid character varying, p_start_time double precision, p_end_time double precision); Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON FUNCTION public.find_persons_in_range(p_video_uuid character varying, p_start_time double precision, p_end_time double precision) IS 'Finds persons appearing in a time range with overlap calculation';


--
-- Name: find_similar_faces(public.vector, double precision, integer); Type: FUNCTION; Schema: public; Owner: accusys
--

CREATE FUNCTION public.find_similar_faces(query_embedding public.vector, similarity_threshold double precision DEFAULT 0.6, limit_count integer DEFAULT 10) RETURNS TABLE(face_id character varying, name character varying, similarity double precision, attributes jsonb, metadata jsonb)
    LANGUAGE plpgsql
    AS $$
BEGIN
    RETURN QUERY
    SELECT 
        fi.face_id,
        fi.name,
        1 - (fi.embedding <=> query_embedding) AS similarity,
        fi.attributes,
        fi.metadata
    FROM face_identities fi
    WHERE fi.is_active = TRUE
      AND fi.embedding IS NOT NULL
      AND 1 - (fi.embedding <=> query_embedding) >= similarity_threshold
    ORDER BY fi.embedding <=> query_embedding
    LIMIT limit_count;
END;
$$;


ALTER FUNCTION public.find_similar_faces(query_embedding public.vector, similarity_threshold double precision, limit_count integer) OWNER TO accusys;

--
-- Name: FUNCTION find_similar_faces(query_embedding public.vector, similarity_threshold double precision, limit_count integer); Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON FUNCTION public.find_similar_faces(query_embedding public.vector, similarity_threshold double precision, limit_count integer) IS 'Finds similar faces based on embedding similarity';


--
-- Name: merge_person_identities(character varying, character varying[]); Type: FUNCTION; Schema: public; Owner: accusys
--

CREATE FUNCTION public.merge_person_identities(p_target_person_id character varying, p_source_person_ids character varying[]) RETURNS void
    LANGUAGE plpgsql
    AS $$
BEGIN
    -- Update all appearances to point to target person
    UPDATE person_appearances
    SET person_id = p_target_person_id
    WHERE person_id = ANY(p_source_person_ids);
    
    -- Delete source person identities
    DELETE FROM person_identities
    WHERE person_id = ANY(p_source_person_ids)
      AND person_id != p_target_person_id;
    
    -- Update target person statistics
    PERFORM update_person_appearance_stats(p_target_person_id);
END;
$$;


ALTER FUNCTION public.merge_person_identities(p_target_person_id character varying, p_source_person_ids character varying[]) OWNER TO accusys;

--
-- Name: FUNCTION merge_person_identities(p_target_person_id character varying, p_source_person_ids character varying[]); Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON FUNCTION public.merge_person_identities(p_target_person_id character varying, p_source_person_ids character varying[]) IS 'Merges multiple person identities into one';


--
-- Name: trigger_update_person_stats(); Type: FUNCTION; Schema: public; Owner: accusys
--

CREATE FUNCTION public.trigger_update_person_stats() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
BEGIN
    IF TG_OP = 'INSERT' THEN
        PERFORM update_person_appearance_stats(NEW.person_id);
    ELSIF TG_OP = 'UPDATE' THEN
        PERFORM update_person_appearance_stats(NEW.person_id);
        IF NEW.person_id != OLD.person_id THEN
            PERFORM update_person_appearance_stats(OLD.person_id);
        END IF;
    ELSIF TG_OP = 'DELETE' THEN
        PERFORM update_person_appearance_stats(OLD.person_id);
    END IF;
    
    RETURN NULL;
END;
$$;


ALTER FUNCTION public.trigger_update_person_stats() OWNER TO accusys;

--
-- Name: update_cluster_centroid(character varying); Type: FUNCTION; Schema: public; Owner: accusys
--

CREATE FUNCTION public.update_cluster_centroid(cluster_uuid character varying) RETURNS void
    LANGUAGE plpgsql
    AS $$
DECLARE
    new_centroid VECTOR(512);
BEGIN
    -- Calculate new centroid from all face embeddings in the cluster
    SELECT AVG(embedding) INTO new_centroid
    FROM face_detections
    WHERE cluster_id = cluster_uuid
      AND embedding IS NOT NULL;
    
    -- Update cluster centroid
    UPDATE face_clusters
    SET centroid = new_centroid,
        size = (SELECT COUNT(*) FROM face_detections WHERE cluster_id = cluster_uuid)
    WHERE cluster_id = cluster_uuid;
END;
$$;


ALTER FUNCTION public.update_cluster_centroid(cluster_uuid character varying) OWNER TO accusys;

--
-- Name: FUNCTION update_cluster_centroid(cluster_uuid character varying); Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON FUNCTION public.update_cluster_centroid(cluster_uuid character varying) IS 'Updates cluster centroid from member embeddings';


--
-- Name: update_person_appearance_stats(character varying); Type: FUNCTION; Schema: public; Owner: accusys
--

CREATE FUNCTION public.update_person_appearance_stats(p_person_id character varying) RETURNS void
    LANGUAGE plpgsql
    AS $$
BEGIN
    UPDATE person_identities
    SET 
        appearance_count = (
            SELECT COUNT(*) 
            FROM person_appearances 
            WHERE person_id = p_person_id
        ),
        total_appearance_duration = (
            SELECT COALESCE(SUM(duration), 0.0)
            FROM person_appearances 
            WHERE person_id = p_person_id
        ),
        first_appearance_time = (
            SELECT MIN(start_time)
            FROM person_appearances 
            WHERE person_id = p_person_id
        ),
        last_appearance_time = (
            SELECT MAX(end_time)
            FROM person_appearances 
            WHERE person_id = p_person_id
        ),
        updated_at = CURRENT_TIMESTAMP
    WHERE person_id = p_person_id;
END;
$$;


ALTER FUNCTION public.update_person_appearance_stats(p_person_id character varying) OWNER TO accusys;

--
-- Name: FUNCTION update_person_appearance_stats(p_person_id character varying); Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON FUNCTION public.update_person_appearance_stats(p_person_id character varying) IS 'Updates person identity statistics from appearances';


--
-- Name: update_search_vector(); Type: FUNCTION; Schema: public; Owner: accusys
--

CREATE FUNCTION public.update_search_vector() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
            BEGIN
                NEW.search_vector := to_tsvector('english', COALESCE(NEW.text_content, ''));
                RETURN NEW;
            END;
            $$;


ALTER FUNCTION public.update_search_vector() OWNER TO accusys;

--
-- Name: update_updated_at_column(); Type: FUNCTION; Schema: public; Owner: accusys
--

CREATE FUNCTION public.update_updated_at_column() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
BEGIN
    NEW.updated_at = CURRENT_TIMESTAMP;
    RETURN NEW;
END;
$$;


ALTER FUNCTION public.update_updated_at_column() OWNER TO accusys;

SET default_tablespace = '';

SET default_table_access_method = heap;

--
-- Name: api_key_anomalies; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.api_key_anomalies (
    id integer NOT NULL,
    key_id character varying(32) NOT NULL,
    anomaly_type character varying(30) NOT NULL,
    severity character varying(10) NOT NULL,
    ip_address character varying(45),
    request_count integer,
    error_count integer,
    error_rate double precision,
    unique_ips integer,
    details jsonb,
    resolved boolean DEFAULT false,
    resolved_at timestamp without time zone,
    resolved_by character varying(128),
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP
);


ALTER TABLE public.api_key_anomalies OWNER TO accusys;

--
-- Name: api_key_anomalies_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.api_key_anomalies_id_seq OWNER TO accusys;

--
-- Name: api_key_anomalies_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.api_key_anomalies_id_seq OWNED BY public.api_key_anomalies.id;


--
-- Name: api_key_audit_log; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.api_key_audit_log (
    id integer NOT NULL,
    key_id character varying(32) NOT NULL,
    action character varying(50) NOT NULL,
    actor character varying(128),
    ip_address character varying(45),
    user_agent text,
    request_path text,
    response_code integer,
    anomaly_type character varying(30),
    details jsonb,
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP
);


ALTER TABLE public.api_key_audit_log OWNER TO accusys;

--
-- Name: api_key_audit_log_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.api_key_audit_log_id_seq OWNER TO accusys;

--
-- Name: api_key_audit_log_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.api_key_audit_log_id_seq OWNED BY public.api_key_audit_log.id;


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

CREATE TABLE public.api_keys (
    id integer NOT NULL,
    key_id character varying(48) NOT NULL,
    key_hash character varying(64) NOT NULL,
    key_prefix character varying(8) NOT NULL,
    name character varying(128) NOT NULL,
    key_type character varying(20) DEFAULT 'user'::character varying NOT NULL,
    user_id bigint,
    service_name character varying(64),
    permissions jsonb DEFAULT '["read", "write"]'::jsonb,
    expires_at timestamp with time zone,
    last_used_at timestamp with time zone,
    last_used_ip character varying(45),
    usage_count bigint DEFAULT 0,
    status character varying(20) DEFAULT 'active'::character varying NOT NULL,
    rotation_required boolean DEFAULT false,
    rotation_reason text,
    grace_period_end timestamp with time zone,
    created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
    updated_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP
);


ALTER TABLE public.api_keys OWNER TO accusys;

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

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


ALTER SEQUENCE public.api_keys_id_seq OWNER TO accusys;

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

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


--
-- Name: backup_history; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.backup_history (
    id integer NOT NULL,
    service_name character varying(50) NOT NULL,
    operation character varying(20),
    backup_file character varying(500),
    backup_tier character varying(20),
    source_tier character varying(20),
    dest_tier character varying(20),
    file_count bigint,
    size_bytes bigint,
    duration_seconds integer,
    status character varying(20),
    error_message text,
    executed_at timestamp without time zone DEFAULT now(),
    CONSTRAINT backup_history_operation_check CHECK (((operation)::text = ANY ((ARRAY['backup'::character varying, 'restore'::character varying, 'tier_migration'::character varying, 'cleanup'::character varying, 'verify'::character varying])::text[]))),
    CONSTRAINT backup_history_status_check CHECK (((status)::text = ANY ((ARRAY['success'::character varying, 'failed'::character varying, 'partial'::character varying])::text[])))
);


ALTER TABLE public.backup_history OWNER TO accusys;

--
-- Name: backup_history_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.backup_history_id_seq OWNER TO accusys;

--
-- Name: backup_history_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.backup_history_id_seq OWNED BY public.backup_history.id;


--
-- Name: backup_registry; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.backup_registry (
    id integer NOT NULL,
    service_name character varying(50) NOT NULL,
    backup_file character varying(500) NOT NULL,
    backup_size_bytes bigint,
    backup_type character varying(20),
    status character varying(20),
    created_at timestamp without time zone DEFAULT now()
);


ALTER TABLE public.backup_registry OWNER TO accusys;

--
-- Name: backup_registry_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.backup_registry_id_seq OWNER TO accusys;

--
-- Name: backup_registry_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.backup_registry_id_seq OWNED BY public.backup_registry.id;


--
-- Name: backup_storage_stats; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.backup_storage_stats (
    id integer NOT NULL,
    tier character varying(20),
    file_count bigint,
    total_size_bytes bigint,
    record_time timestamp without time zone DEFAULT now(),
    CONSTRAINT backup_storage_stats_tier_check CHECK (((tier)::text = ANY ((ARRAY['daily'::character varying, 'weekly'::character varying, 'monthly'::character varying, 'archive'::character varying, 'total'::character varying])::text[])))
);


ALTER TABLE public.backup_storage_stats OWNER TO accusys;

--
-- Name: backup_storage_stats_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.backup_storage_stats_id_seq OWNER TO accusys;

--
-- Name: backup_storage_stats_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.backup_storage_stats_id_seq OWNED BY public.backup_storage_stats.id;


--
-- Name: castings; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.castings (
    id bigint NOT NULL,
    character_id bigint,
    talent_id bigint,
    track_type character varying(32) DEFAULT 'original'::character varying,
    role_type character varying(32) DEFAULT 'both'::character varying
);


ALTER TABLE public.castings OWNER TO accusys;

--
-- Name: TABLE castings; Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON TABLE public.castings IS 'Talent 與 Character 的飾演關係';


--
-- Name: castings_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.castings_id_seq OWNER TO accusys;

--
-- Name: castings_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.castings_id_seq OWNED BY public.castings.id;


--
-- Name: characters; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.characters (
    id bigint NOT NULL,
    video_uuid text NOT NULL,
    name text NOT NULL,
    language_track text DEFAULT 'original'::text,
    is_voice_only boolean DEFAULT false,
    metadata jsonb DEFAULT '{}'::jsonb
);


ALTER TABLE public.characters OWNER TO accusys;

--
-- Name: TABLE characters; Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON TABLE public.characters IS '視頻中的劇中角色';


--
-- Name: characters_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.characters_id_seq OWNER TO accusys;

--
-- Name: characters_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.characters_id_seq OWNED BY public.characters.id;


--
-- Name: child_chunks; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.child_chunks (
    id integer NOT NULL,
    parent_id integer,
    uuid text NOT NULL,
    start_time double precision NOT NULL,
    end_time double precision NOT NULL,
    raw_text text,
    raw_text_vector public.vector(768),
    speaker_ids text[],
    tags text[],
    created_at timestamp with time zone DEFAULT now(),
    face_ids text[] DEFAULT '{}'::text[],
    start_frame bigint,
    end_frame bigint,
    fps double precision DEFAULT 24.0
);


ALTER TABLE public.child_chunks OWNER TO accusys;

--
-- Name: child_chunks_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.child_chunks_id_seq OWNER TO accusys;

--
-- Name: child_chunks_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.child_chunks_id_seq OWNED BY public.child_chunks.id;


--
-- Name: chunk_vectors; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.chunk_vectors (
    id integer NOT NULL,
    chunk_id character varying(64) NOT NULL,
    uuid character varying(32) NOT NULL,
    chunk_type character varying(32) NOT NULL,
    start_time double precision,
    end_time double precision,
    embedding text,
    metadata jsonb,
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
    embedding_vector public.vector(768),
    file_id integer
);


ALTER TABLE public.chunk_vectors OWNER TO accusys;

--
-- Name: chunk_vectors_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.chunk_vectors_id_seq OWNER TO accusys;

--
-- Name: chunk_vectors_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.chunk_vectors_id_seq OWNED BY public.chunk_vectors.id;


--
-- Name: chunks; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.chunks (
    id integer NOT NULL,
    uuid character varying(32) NOT NULL,
    chunk_id character varying(64) NOT NULL,
    chunk_index integer NOT NULL,
    chunk_type character varying(32) NOT NULL,
    start_time double precision NOT NULL,
    end_time double precision NOT NULL,
    content jsonb NOT NULL,
    vector_id character varying(64),
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
    fps double precision DEFAULT 24.0,
    start_frame bigint DEFAULT 0,
    end_frame bigint DEFAULT 0,
    metadata jsonb,
    updated_at timestamp without time zone DEFAULT now(),
    file_id integer,
    text_content text,
    frame_count integer DEFAULT 0,
    pre_chunk_ids integer[],
    parent_chunk_id character varying(64),
    child_chunk_ids text[],
    search_vector tsvector,
    speaker_ids text[] DEFAULT '{}'::text[],
    face_ids text[] DEFAULT '{}'::text[],
    visual_stats jsonb DEFAULT '{}'::jsonb
);


ALTER TABLE public.chunks OWNER TO accusys;

--
-- Name: chunks_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.chunks_id_seq OWNER TO accusys;

--
-- Name: chunks_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.chunks_id_seq OWNED BY public.chunks.id;


--
-- Name: face_clusters; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.face_clusters (
    id integer NOT NULL,
    cluster_id character varying(255) NOT NULL,
    video_uuid character varying(255) NOT NULL,
    centroid public.vector(512),
    size integer DEFAULT 0 NOT NULL,
    representative_face_id character varying(255),
    metadata jsonb DEFAULT '{}'::jsonb,
    created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP
);


ALTER TABLE public.face_clusters OWNER TO accusys;

--
-- Name: TABLE face_clusters; Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON TABLE public.face_clusters IS 'Stores face clusters from video analysis';


--
-- Name: face_clusters_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.face_clusters_id_seq OWNER TO accusys;

--
-- Name: face_clusters_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.face_clusters_id_seq OWNED BY public.face_clusters.id;


--
-- Name: face_detections; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.face_detections (
    id integer NOT NULL,
    video_uuid character varying(255) NOT NULL,
    frame_number bigint NOT NULL,
    timestamp_secs double precision NOT NULL,
    face_id character varying(255),
    x integer NOT NULL,
    y integer NOT NULL,
    width integer NOT NULL,
    height integer NOT NULL,
    confidence double precision NOT NULL,
    embedding public.vector(512),
    attributes jsonb,
    identity_id integer,
    identity_confidence double precision,
    cluster_id character varying(255),
    created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP
);


ALTER TABLE public.face_detections OWNER TO accusys;

--
-- Name: TABLE face_detections; Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON TABLE public.face_detections IS 'Stores individual face detections from videos';


--
-- Name: face_detections_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.face_detections_id_seq OWNER TO accusys;

--
-- Name: face_detections_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.face_detections_id_seq OWNED BY public.face_detections.id;


--
-- Name: face_identities; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.face_identities (
    id integer NOT NULL,
    face_id character varying(255) NOT NULL,
    name character varying(255),
    embedding public.vector(512),
    attributes jsonb,
    metadata jsonb DEFAULT '{}'::jsonb,
    created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
    updated_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
    is_active boolean DEFAULT true
);


ALTER TABLE public.face_identities OWNER TO accusys;

--
-- Name: TABLE face_identities; Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON TABLE public.face_identities IS 'Stores registered face identities with embeddings';


--
-- Name: face_identities_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.face_identities_id_seq OWNER TO accusys;

--
-- Name: face_identities_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.face_identities_id_seq OWNED BY public.face_identities.id;


--
-- Name: face_recognition_results; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.face_recognition_results (
    id integer NOT NULL,
    video_uuid character varying(255) NOT NULL,
    frame_count bigint DEFAULT 0 NOT NULL,
    fps double precision DEFAULT 0.0 NOT NULL,
    total_faces integer DEFAULT 0 NOT NULL,
    recognized_faces integer DEFAULT 0 NOT NULL,
    clusters_count integer DEFAULT 0 NOT NULL,
    result_data jsonb NOT NULL,
    processing_time_secs double precision,
    created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
    updated_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP
);


ALTER TABLE public.face_recognition_results OWNER TO accusys;

--
-- Name: TABLE face_recognition_results; Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON TABLE public.face_recognition_results IS 'Stores face recognition processing results';


--
-- Name: face_recognition_results_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.face_recognition_results_id_seq OWNER TO accusys;

--
-- Name: face_recognition_results_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.face_recognition_results_id_seq OWNED BY public.face_recognition_results.id;


--
-- Name: file_lifecycle; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.file_lifecycle (
    id integer NOT NULL,
    file_uuid uuid,
    file_path text,
    user_cluster character varying(50),
    storage_tier character varying(20),
    created_at timestamp without time zone,
    last_accessed_at timestamp without time zone,
    last_modified_at timestamp without time zone,
    access_count integer DEFAULT 0,
    current_status character varying(20) DEFAULT 'active'::character varying,
    tier_migration_count integer DEFAULT 0,
    migrated_at timestamp without time zone
);


ALTER TABLE public.file_lifecycle OWNER TO accusys;

--
-- Name: file_lifecycle_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.file_lifecycle_id_seq OWNER TO accusys;

--
-- Name: file_lifecycle_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.file_lifecycle_id_seq OWNED BY public.file_lifecycle.id;


--
-- Name: file_registry; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.file_registry (
    file_uuid uuid DEFAULT gen_random_uuid() NOT NULL,
    file_name character varying(255) NOT NULL,
    file_path text NOT NULL,
    file_path_hash character varying(64) NOT NULL,
    file_size bigint NOT NULL,
    file_hash character varying(64),
    mime_type character varying(100),
    user_cluster character varying(50),
    owner_id character varying(100),
    storage_tier character varying(20) DEFAULT 'hot'::character varying,
    storage_location character varying(500),
    status character varying(20) DEFAULT 'active'::character varying,
    is_registered boolean DEFAULT true,
    created_at timestamp without time zone DEFAULT now(),
    updated_at timestamp without time zone DEFAULT now(),
    last_accessed_at timestamp without time zone,
    access_count integer DEFAULT 0,
    archived_at timestamp without time zone,
    archive_location character varying(500),
    retention_until timestamp without time zone,
    CONSTRAINT file_registry_status_check CHECK (((status)::text = ANY ((ARRAY['active'::character varying, 'temporary'::character varying, 'archived'::character varying, 'deleted'::character varying])::text[]))),
    CONSTRAINT file_registry_storage_tier_check CHECK (((storage_tier)::text = ANY ((ARRAY['hot'::character varying, 'warm'::character varying, 'cold'::character varying])::text[]))),
    CONSTRAINT file_registry_user_cluster_check CHECK (((user_cluster)::text = ANY ((ARRAY['family'::character varying, 'work'::character varying, 'wordpress'::character varying, 'shared'::character varying, 'system'::character varying])::text[])))
);


ALTER TABLE public.file_registry OWNER TO accusys;

--
-- Name: frames; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.frames (
    id integer NOT NULL,
    file_id integer NOT NULL,
    frame_number bigint NOT NULL,
    "timestamp" double precision NOT NULL,
    fps double precision DEFAULT 24.0 NOT NULL,
    yolo_objects jsonb,
    ocr_results jsonb,
    face_results jsonb,
    frame_path text,
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
    pose_results jsonb
);


ALTER TABLE public.frames OWNER TO accusys;

--
-- Name: frames_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.frames_id_seq OWNER TO accusys;

--
-- Name: frames_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.frames_id_seq OWNED BY public.frames.id;


--
-- Name: gitea_tokens; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.gitea_tokens (
    id integer NOT NULL,
    gitea_token_id bigint NOT NULL,
    gitea_user character varying(128) NOT NULL,
    token_name character varying(128) NOT NULL,
    token_last_eight character varying(8) NOT NULL,
    scopes jsonb DEFAULT '[]'::jsonb,
    api_key_id character varying(48),
    last_verified timestamp without time zone,
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP
);


ALTER TABLE public.gitea_tokens OWNER TO accusys;

--
-- Name: gitea_tokens_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.gitea_tokens_id_seq OWNER TO accusys;

--
-- Name: gitea_tokens_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.gitea_tokens_id_seq OWNED BY public.gitea_tokens.id;


--
-- Name: identities; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.identities (
    id integer NOT NULL,
    name character varying(255) NOT NULL,
    metadata jsonb DEFAULT '{}'::jsonb,
    uuid uuid DEFAULT gen_random_uuid(),
    identity_type character varying(30) DEFAULT 'people'::character varying,
    source character varying(20) DEFAULT 'manual'::character varying,
    status character varying(20) DEFAULT 'pending'::character varying,
    voice_embedding public.vector(192),
    identity_embedding public.vector(768),
    reference_data jsonb DEFAULT '{}'::jsonb,
    created_at timestamp with time zone DEFAULT now(),
    updated_at timestamp with time zone DEFAULT now(),
    tmdb_id integer,
    tmdb_profile text,
    face_embedding public.vector(512),
    CONSTRAINT identities_identity_type_check CHECK (((identity_type)::text = ANY ((ARRAY['people'::character varying, 'brand'::character varying, 'object'::character varying, 'concept'::character varying, 'logo'::character varying, 'symbol'::character varying, 'scene'::character varying, 'sound'::character varying, 'animal'::character varying, 'environmental'::character varying])::text[])))
);


ALTER TABLE public.identities OWNER TO accusys;

--
-- Name: COLUMN identities.identity_type; Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON COLUMN public.identities.identity_type IS 'Identity type: people, brand, object, concept, logo, symbol, scene, sound, animal, environmental';


--
-- Name: COLUMN identities.source; Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON COLUMN public.identities.source IS 'Identity source: manual, tmdb, agent_suggested, ai_detection';


--
-- Name: COLUMN identities.status; Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON COLUMN public.identities.status IS 'Identity status: pending, confirmed, skipped';


--
-- Name: COLUMN identities.voice_embedding; Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON COLUMN public.identities.voice_embedding IS 'ECAPA-TDNN 192-dim voice embedding';


--
-- Name: COLUMN identities.identity_embedding; Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON COLUMN public.identities.identity_embedding IS 'CLIP ViT-L/14 768-dim embedding for logo/symbol/object identity';


--
-- Name: COLUMN identities.reference_data; Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON COLUMN public.identities.reference_data IS 'JSONB: {face_embeddings[], voice_embeddings[], identity_embeddings[], sound_embeddings[], image_urls[]}';


--
-- Name: COLUMN identities.tmdb_id; Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON COLUMN public.identities.tmdb_id IS 'TMDB person ID';


--
-- Name: COLUMN identities.tmdb_profile; Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON COLUMN public.identities.tmdb_profile IS 'TMDB profile image URL';


--
-- Name: COLUMN identities.face_embedding; Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON COLUMN public.identities.face_embedding IS 'InsightFace ArcFace 512-dim embedding';


--
-- Name: identities_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.identities_id_seq OWNER TO accusys;

--
-- Name: identities_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.identities_id_seq OWNED BY public.identities.id;


--
-- Name: identity_bindings; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.identity_bindings (
    id integer NOT NULL,
    identity_id integer,
    uuid text NOT NULL,
    binding_type character varying(32) NOT NULL,
    binding_value character varying(64) NOT NULL
);


ALTER TABLE public.identity_bindings OWNER TO accusys;

--
-- Name: identity_bindings_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.identity_bindings_id_seq OWNER TO accusys;

--
-- Name: identity_bindings_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.identity_bindings_id_seq OWNED BY public.identity_bindings.id;


--
-- Name: merge_history; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.merge_history (
    id integer NOT NULL,
    merge_id uuid DEFAULT gen_random_uuid() NOT NULL,
    target_person_id character varying(255) NOT NULL,
    source_person_ids text[] NOT NULL,
    original_target_stats jsonb NOT NULL,
    original_source_stats jsonb NOT NULL,
    merged_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
    merged_by character varying(255),
    is_undone boolean DEFAULT false,
    undone_at timestamp with time zone,
    metadata jsonb DEFAULT '{}'::jsonb
);


ALTER TABLE public.merge_history OWNER TO accusys;

--
-- Name: TABLE merge_history; Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON TABLE public.merge_history IS 'Tracks person merges for undo capability';


--
-- Name: merge_history_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.merge_history_id_seq OWNER TO accusys;

--
-- Name: merge_history_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.merge_history_id_seq OWNED BY public.merge_history.id;


--
-- Name: monitor_anomalies; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.monitor_anomalies (
    id integer NOT NULL,
    anomaly_type character varying(50),
    severity character varying(20),
    source_type character varying(20),
    username character varying(100),
    source_ip character varying(45),
    description text,
    details jsonb,
    detected_at timestamp without time zone DEFAULT now(),
    resolved boolean DEFAULT false,
    resolved_at timestamp without time zone,
    CONSTRAINT monitor_anomalies_anomaly_type_check CHECK (((anomaly_type)::text = ANY ((ARRAY['brute_force'::character varying, 'privilege_escalation'::character varying, 'unusual_access'::character varying, 'unusual_time'::character varying, 'excessive_queries'::character varying, 'idle_session'::character varying, 'schema_change'::character varying])::text[]))),
    CONSTRAINT monitor_anomalies_severity_check CHECK (((severity)::text = ANY ((ARRAY['low'::character varying, 'medium'::character varying, 'high'::character varying, 'critical'::character varying])::text[])))
);


ALTER TABLE public.monitor_anomalies OWNER TO accusys;

--
-- Name: monitor_anomalies_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.monitor_anomalies_id_seq OWNER TO accusys;

--
-- Name: monitor_anomalies_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.monitor_anomalies_id_seq OWNED BY public.monitor_anomalies.id;


--
-- Name: monitor_config; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.monitor_config (
    id integer NOT NULL,
    config_key character varying(50) NOT NULL,
    config_value text,
    description character varying(255),
    updated_at timestamp without time zone DEFAULT now()
);


ALTER TABLE public.monitor_config OWNER TO accusys;

--
-- Name: monitor_config_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.monitor_config_id_seq OWNER TO accusys;

--
-- Name: monitor_config_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.monitor_config_id_seq OWNED BY public.monitor_config.id;


--
-- Name: monitor_databases; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.monitor_databases (
    id integer NOT NULL,
    db_type character varying(20) NOT NULL,
    db_name character varying(50),
    metric_name character varying(50) NOT NULL,
    metric_value jsonb,
    checked_at timestamp without time zone DEFAULT now(),
    CONSTRAINT monitor_databases_db_type_check CHECK (((db_type)::text = ANY ((ARRAY['postgresql'::character varying, 'redis'::character varying, 'qdrant'::character varying, 'mariadb'::character varying, 'mongodb'::character varying])::text[])))
);


ALTER TABLE public.monitor_databases OWNER TO accusys;

--
-- Name: monitor_databases_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.monitor_databases_id_seq OWNER TO accusys;

--
-- Name: monitor_databases_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.monitor_databases_id_seq OWNED BY public.monitor_databases.id;


--
-- Name: monitor_external; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.monitor_external (
    id integer NOT NULL,
    target_name character varying(50) NOT NULL,
    target_type character varying(20),
    target_host character varying(255),
    is_reachable boolean,
    response_time_ms integer,
    dns_resolved_ip character varying(45),
    error_message text,
    checked_at timestamp without time zone DEFAULT now(),
    CONSTRAINT monitor_external_target_type_check CHECK (((target_type)::text = ANY ((ARRAY['ddns'::character varying, 'gateway'::character varying, 'internet'::character varying, 'api'::character varying])::text[])))
);


ALTER TABLE public.monitor_external OWNER TO accusys;

--
-- Name: monitor_external_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.monitor_external_id_seq OWNER TO accusys;

--
-- Name: monitor_external_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.monitor_external_id_seq OWNED BY public.monitor_external.id;


--
-- Name: monitor_jobs; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.monitor_jobs (
    id integer NOT NULL,
    uuid character varying(16) NOT NULL,
    video_path character varying(512),
    status character varying(20) DEFAULT 'pending'::character varying NOT NULL,
    current_processor character varying(20),
    progress_total integer DEFAULT 0,
    progress_current integer DEFAULT 0,
    error_count integer DEFAULT 0,
    last_error text,
    started_at timestamp without time zone,
    updated_at timestamp without time zone,
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
    video_id bigint,
    user_id bigint,
    processors character varying(20)[] DEFAULT '{asr,cut,yolo,ocr,face,pose,asrx,caption,story}'::character varying[],
    completed_processors character varying(20)[] DEFAULT '{}'::character varying[],
    failed_processors character varying(20)[] DEFAULT '{}'::character varying[],
    CONSTRAINT chk_monitor_jobs_status CHECK (((status)::text = ANY ((ARRAY['pending'::character varying, 'running'::character varying, 'completed'::character varying, 'failed'::character varying, 'cancelled'::character varying])::text[])))
);


ALTER TABLE public.monitor_jobs OWNER TO accusys;

--
-- Name: COLUMN monitor_jobs.video_id; Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON COLUMN public.monitor_jobs.video_id IS 'Foreign key to videos.id';


--
-- Name: COLUMN monitor_jobs.user_id; Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON COLUMN public.monitor_jobs.user_id IS 'WordPress user ID';


--
-- Name: COLUMN monitor_jobs.processors; Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON COLUMN public.monitor_jobs.processors IS 'Processors to run: asr, cut, yolo, ocr, face, pose, asrx';


--
-- Name: COLUMN monitor_jobs.completed_processors; Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON COLUMN public.monitor_jobs.completed_processors IS 'Successfully completed processors';


--
-- Name: COLUMN monitor_jobs.failed_processors; Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON COLUMN public.monitor_jobs.failed_processors IS 'Failed processors';


--
-- Name: monitor_jobs_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.monitor_jobs_id_seq OWNER TO accusys;

--
-- Name: monitor_jobs_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.monitor_jobs_id_seq OWNED BY public.monitor_jobs.id;


--
-- Name: monitor_logins; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.monitor_logins (
    id integer NOT NULL,
    user_type character varying(20),
    username character varying(100),
    source_ip character varying(45),
    user_agent text,
    login_method character varying(20),
    success boolean,
    failure_reason character varying(200),
    login_at timestamp without time zone DEFAULT now(),
    CONSTRAINT monitor_logins_user_type_check CHECK (((user_type)::text = ANY ((ARRAY['system'::character varying, 'wordpress'::character varying, 'n8n'::character varying, 'gitea'::character varying, 'sftpgo'::character varying, 'database'::character varying])::text[])))
);


ALTER TABLE public.monitor_logins OWNER TO accusys;

--
-- Name: monitor_logins_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.monitor_logins_id_seq OWNER TO accusys;

--
-- Name: monitor_logins_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.monitor_logins_id_seq OWNED BY public.monitor_logins.id;


--
-- Name: monitor_pg_schema_changes; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.monitor_pg_schema_changes (
    id integer NOT NULL,
    database_name character varying(50),
    schema_name character varying(50),
    table_name character varying(100),
    change_type character varying(20),
    column_name character varying(100),
    old_value text,
    new_value text,
    detected_at timestamp without time zone DEFAULT now(),
    CONSTRAINT monitor_pg_schema_changes_change_type_check CHECK (((change_type)::text = ANY ((ARRAY['table_created'::character varying, 'table_dropped'::character varying, 'column_added'::character varying, 'column_removed'::character varying, 'column_type_changed'::character varying])::text[])))
);


ALTER TABLE public.monitor_pg_schema_changes OWNER TO accusys;

--
-- Name: monitor_pg_schema_changes_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.monitor_pg_schema_changes_id_seq OWNER TO accusys;

--
-- Name: monitor_pg_schema_changes_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.monitor_pg_schema_changes_id_seq OWNED BY public.monitor_pg_schema_changes.id;


--
-- Name: monitor_pg_tables; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.monitor_pg_tables (
    id integer NOT NULL,
    database_name character varying(50),
    schema_name character varying(50),
    table_name character varying(100),
    table_type character varying(20),
    row_count bigint,
    table_size_bytes bigint,
    index_size_bytes bigint,
    snapshot_at timestamp without time zone DEFAULT now()
);


ALTER TABLE public.monitor_pg_tables OWNER TO accusys;

--
-- Name: monitor_pg_tables_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.monitor_pg_tables_id_seq OWNER TO accusys;

--
-- Name: monitor_pg_tables_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.monitor_pg_tables_id_seq OWNED BY public.monitor_pg_tables.id;


--
-- Name: monitor_portal_pages; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.monitor_portal_pages (
    id integer NOT NULL,
    page_url character varying(500) NOT NULL,
    page_type character varying(20),
    is_accessible boolean,
    response_time_ms integer,
    http_status integer,
    error_message text,
    checked_at timestamp without time zone DEFAULT now()
);


ALTER TABLE public.monitor_portal_pages OWNER TO accusys;

--
-- Name: monitor_portal_pages_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.monitor_portal_pages_id_seq OWNER TO accusys;

--
-- Name: monitor_portal_pages_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.monitor_portal_pages_id_seq OWNED BY public.monitor_portal_pages.id;


--
-- Name: monitor_portal_users; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.monitor_portal_users (
    id integer NOT NULL,
    user_id bigint,
    username character varying(100),
    email character varying(255),
    role character varying(50),
    is_active boolean,
    last_login timestamp without time zone,
    created_at timestamp without time zone,
    detected_at timestamp without time zone DEFAULT now()
);


ALTER TABLE public.monitor_portal_users OWNER TO accusys;

--
-- Name: monitor_portal_users_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.monitor_portal_users_id_seq OWNER TO accusys;

--
-- Name: monitor_portal_users_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.monitor_portal_users_id_seq OWNED BY public.monitor_portal_users.id;


--
-- Name: monitor_qdrant_collections; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.monitor_qdrant_collections (
    id integer NOT NULL,
    collection_name character varying(100),
    vectors_count bigint,
    points_count bigint,
    disk_size_bytes bigint,
    status character varying(20),
    snapshot_at timestamp without time zone DEFAULT now()
);


ALTER TABLE public.monitor_qdrant_collections OWNER TO accusys;

--
-- Name: monitor_qdrant_collections_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.monitor_qdrant_collections_id_seq OWNER TO accusys;

--
-- Name: monitor_qdrant_collections_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.monitor_qdrant_collections_id_seq OWNED BY public.monitor_qdrant_collections.id;


--
-- Name: monitor_resource_usage; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.monitor_resource_usage (
    id integer NOT NULL,
    user_type character varying(20),
    username character varying(100),
    service_name character varying(50),
    cpu_percent numeric(5,2),
    memory_mb integer,
    disk_io_read_mb bigint,
    disk_io_write_mb bigint,
    network_rx_mb bigint,
    network_tx_mb bigint,
    recorded_at timestamp without time zone DEFAULT now()
);


ALTER TABLE public.monitor_resource_usage OWNER TO accusys;

--
-- Name: monitor_resource_usage_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.monitor_resource_usage_id_seq OWNER TO accusys;

--
-- Name: monitor_resource_usage_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.monitor_resource_usage_id_seq OWNED BY public.monitor_resource_usage.id;


--
-- Name: monitor_services; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.monitor_services (
    id integer NOT NULL,
    service_name character varying(50) NOT NULL,
    service_type character varying(20),
    port integer,
    status character varying(20),
    response_time_ms integer,
    error_message text,
    checked_at timestamp without time zone DEFAULT now(),
    CONSTRAINT monitor_services_status_check CHECK (((status)::text = ANY ((ARRAY['up'::character varying, 'down'::character varying, 'degraded'::character varying, 'unknown'::character varying])::text[])))
);


ALTER TABLE public.monitor_services OWNER TO accusys;

--
-- Name: monitor_services_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.monitor_services_id_seq OWNER TO accusys;

--
-- Name: monitor_services_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.monitor_services_id_seq OWNED BY public.monitor_services.id;


--
-- Name: monitor_sessions; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.monitor_sessions (
    id integer NOT NULL,
    session_type character varying(20),
    service_name character varying(50),
    username character varying(100),
    source_ip character varying(45),
    source_port integer,
    connected_at timestamp without time zone,
    last_activity_at timestamp without time zone,
    disconnected_at timestamp without time zone,
    bytes_sent bigint,
    bytes_received bigint,
    status character varying(20),
    CONSTRAINT monitor_sessions_session_type_check CHECK (((session_type)::text = ANY ((ARRAY['ssh'::character varying, 'web'::character varying, 'db'::character varying, 'sftp'::character varying, 'rdp'::character varying])::text[]))),
    CONSTRAINT monitor_sessions_status_check CHECK (((status)::text = ANY ((ARRAY['active'::character varying, 'disconnected'::character varying, 'timeout'::character varying])::text[])))
);


ALTER TABLE public.monitor_sessions OWNER TO accusys;

--
-- Name: monitor_sessions_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.monitor_sessions_id_seq OWNER TO accusys;

--
-- Name: monitor_sessions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.monitor_sessions_id_seq OWNED BY public.monitor_sessions.id;


--
-- Name: monitor_sudo_history; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.monitor_sudo_history (
    id integer NOT NULL,
    username character varying(100),
    command text,
    run_as character varying(100),
    tty character varying(50),
    source_ip character varying(45),
    exit_code integer,
    executed_at timestamp without time zone DEFAULT now()
);


ALTER TABLE public.monitor_sudo_history OWNER TO accusys;

--
-- Name: monitor_sudo_history_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.monitor_sudo_history_id_seq OWNER TO accusys;

--
-- Name: monitor_sudo_history_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.monitor_sudo_history_id_seq OWNED BY public.monitor_sudo_history.id;


--
-- Name: monitor_workflows; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.monitor_workflows (
    id integer NOT NULL,
    workflow_id character varying(50) NOT NULL,
    workflow_name character varying(255),
    workflow_type character varying(50),
    is_active boolean DEFAULT false,
    last_executed_at timestamp without time zone,
    execution_count integer DEFAULT 0,
    success_count integer DEFAULT 0,
    failure_count integer DEFAULT 0,
    avg_duration_ms integer,
    has_schedule boolean DEFAULT false,
    has_webhook boolean DEFAULT false,
    idle_days integer,
    suggestion character varying(100),
    checked_at timestamp without time zone DEFAULT now()
);


ALTER TABLE public.monitor_workflows OWNER TO accusys;

--
-- Name: monitor_workflows_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.monitor_workflows_id_seq OWNER TO accusys;

--
-- Name: monitor_workflows_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.monitor_workflows_id_seq OWNED BY public.monitor_workflows.id;


--
-- Name: n8n_api_keys; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.n8n_api_keys (
    id integer NOT NULL,
    n8n_key_id character varying(64) NOT NULL,
    label character varying(100) NOT NULL,
    api_key_last_eight character varying(8) NOT NULL,
    momentry_api_key_id character varying(48),
    expires_at timestamp with time zone,
    last_verified timestamp with time zone,
    created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP
);


ALTER TABLE public.n8n_api_keys OWNER TO accusys;

--
-- Name: n8n_api_keys_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.n8n_api_keys_id_seq OWNER TO accusys;

--
-- Name: n8n_api_keys_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.n8n_api_keys_id_seq OWNED BY public.n8n_api_keys.id;


--
-- Name: node_process_tracking; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.node_process_tracking (
    id integer NOT NULL,
    process_name character varying(100) NOT NULL,
    pid integer,
    command character varying(500),
    node_version character varying(20),
    is_managed boolean DEFAULT false,
    started_at timestamp without time zone,
    checked_at timestamp without time zone DEFAULT now()
);


ALTER TABLE public.node_process_tracking OWNER TO accusys;

--
-- Name: node_process_tracking_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.node_process_tracking_id_seq OWNER TO accusys;

--
-- Name: node_process_tracking_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.node_process_tracking_id_seq OWNED BY public.node_process_tracking.id;


--
-- Name: node_version_baseline; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.node_version_baseline (
    id integer NOT NULL,
    runtime_name character varying(50) NOT NULL,
    required_version character varying(20) NOT NULL,
    current_version character varying(20),
    process_name character varying(100),
    process_path text,
    is_compliant boolean,
    locked_path character varying(500),
    checked_at timestamp without time zone DEFAULT now()
);


ALTER TABLE public.node_version_baseline OWNER TO accusys;

--
-- Name: node_version_baseline_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.node_version_baseline_id_seq OWNER TO accusys;

--
-- Name: node_version_baseline_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.node_version_baseline_id_seq OWNED BY public.node_version_baseline.id;


--
-- Name: parent_chunks; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.parent_chunks (
    id integer NOT NULL,
    uuid text NOT NULL,
    scene_order integer,
    start_time double precision NOT NULL,
    end_time double precision NOT NULL,
    summary_text text,
    summary_vector public.vector(768),
    metadata jsonb,
    created_at timestamp with time zone DEFAULT now(),
    rule_3_markers jsonb DEFAULT '{}'::jsonb,
    start_frame bigint,
    end_frame bigint,
    fps double precision DEFAULT 24.0
);


ALTER TABLE public.parent_chunks OWNER TO accusys;

--
-- Name: parent_chunks_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.parent_chunks_id_seq OWNER TO accusys;

--
-- Name: parent_chunks_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.parent_chunks_id_seq OWNED BY public.parent_chunks.id;


--
-- Name: parent_chunks_poc; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.parent_chunks_poc (
    id integer NOT NULL,
    uuid text NOT NULL,
    scene_order integer,
    start_time double precision NOT NULL,
    end_time double precision NOT NULL,
    summary_text text,
    summary_vector public.vector(768),
    metadata jsonb,
    created_at timestamp with time zone DEFAULT now()
);


ALTER TABLE public.parent_chunks_poc OWNER TO accusys;

--
-- Name: parent_chunks_poc_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.parent_chunks_poc_id_seq OWNER TO accusys;

--
-- Name: parent_chunks_poc_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.parent_chunks_poc_id_seq OWNED BY public.parent_chunks_poc.id;


--
-- Name: person_appearances; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.person_appearances (
    id integer NOT NULL,
    person_id character varying(255) NOT NULL,
    video_uuid character varying(255) NOT NULL,
    start_time double precision NOT NULL,
    end_time double precision NOT NULL,
    duration double precision NOT NULL,
    face_detection_id integer,
    asrx_segment_start double precision,
    asrx_segment_end double precision,
    confidence double precision DEFAULT 0.0,
    metadata jsonb DEFAULT '{}'::jsonb,
    created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT person_appearances_confidence_check CHECK (((confidence >= (0.0)::double precision) AND (confidence <= (1.0)::double precision))),
    CONSTRAINT person_appearances_duration_check CHECK ((duration > (0)::double precision)),
    CONSTRAINT person_appearances_end_time_check CHECK ((end_time >= (0)::double precision)),
    CONSTRAINT person_appearances_start_time_check CHECK ((start_time >= (0)::double precision)),
    CONSTRAINT valid_appearance_time CHECK ((end_time > start_time)),
    CONSTRAINT valid_duration CHECK (((end_time - start_time) = duration))
);


ALTER TABLE public.person_appearances OWNER TO accusys;

--
-- Name: TABLE person_appearances; Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON TABLE public.person_appearances IS 'Stores individual person appearance records with time ranges';


--
-- Name: person_appearances_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.person_appearances_id_seq OWNER TO accusys;

--
-- Name: person_appearances_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.person_appearances_id_seq OWNED BY public.person_appearances.id;


--
-- Name: person_identities; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.person_identities (
    id integer NOT NULL,
    person_id character varying(255) NOT NULL,
    face_identity_id integer,
    speaker_id character varying(64),
    video_uuid character varying(255) NOT NULL,
    confidence double precision DEFAULT 0.0,
    name character varying(255),
    metadata jsonb DEFAULT '{}'::jsonb,
    first_appearance_time double precision,
    last_appearance_time double precision,
    total_appearance_duration double precision DEFAULT 0.0,
    appearance_count integer DEFAULT 0,
    created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
    updated_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
    is_confirmed boolean DEFAULT false,
    aliases jsonb DEFAULT '[]'::jsonb,
    original_name character varying(255),
    character_name character varying(255),
    age integer,
    gender character varying(20),
    CONSTRAINT person_identities_confidence_check CHECK (((confidence >= (0.0)::double precision) AND (confidence <= (1.0)::double precision))),
    CONSTRAINT valid_time_range CHECK (((first_appearance_time IS NULL) OR (last_appearance_time IS NULL) OR (last_appearance_time >= first_appearance_time)))
);


ALTER TABLE public.person_identities OWNER TO accusys;

--
-- Name: TABLE person_identities; Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON TABLE public.person_identities IS 'Stores person identity associations linking face and speaker identities';


--
-- Name: person_identities_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.person_identities_id_seq OWNER TO accusys;

--
-- Name: person_identities_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.person_identities_id_seq OWNED BY public.person_identities.id;


--
-- Name: processor_results; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.processor_results (
    id integer NOT NULL,
    job_id integer,
    video_id bigint,
    processor character varying(20) NOT NULL,
    status character varying(20) DEFAULT 'pending'::character varying NOT NULL,
    output_path text,
    started_at timestamp without time zone,
    completed_at timestamp without time zone,
    error_message text,
    progress_total integer DEFAULT 0,
    progress_current integer DEFAULT 0,
    last_checkpoint jsonb,
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
    updated_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
    output_data jsonb,
    duration_secs double precision GENERATED ALWAYS AS (
CASE
    WHEN ((completed_at IS NOT NULL) AND (started_at IS NOT NULL)) THEN EXTRACT(epoch FROM (completed_at - started_at))
    ELSE NULL::numeric
END) STORED,
    processor_version character varying(50),
    model_name character varying(100),
    model_version character varying(50),
    contract_version character varying(20),
    CONSTRAINT chk_processor_results_processor CHECK (((processor)::text = ANY ((ARRAY['asr'::character varying, 'cut'::character varying, 'yolo'::character varying, 'ocr'::character varying, 'face'::character varying, 'pose'::character varying, 'asrx'::character varying])::text[]))),
    CONSTRAINT chk_processor_results_status CHECK (((status)::text = ANY ((ARRAY['pending'::character varying, 'running'::character varying, 'completed'::character varying, 'failed'::character varying, 'skipped'::character varying])::text[])))
);


ALTER TABLE public.processor_results OWNER TO accusys;

--
-- Name: TABLE processor_results; Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON TABLE public.processor_results IS 'Tracks individual processor execution status';


--
-- Name: COLUMN processor_results.status; Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON COLUMN public.processor_results.status IS 'pending, running, completed, failed, skipped';


--
-- Name: COLUMN processor_results.output_data; Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON COLUMN public.processor_results.output_data IS 'JSON output from processor execution';


--
-- Name: COLUMN processor_results.duration_secs; Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON COLUMN public.processor_results.duration_secs IS 'Computed duration in seconds (completed - started) as double precision';


--
-- Name: processor_results_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.processor_results_id_seq OWNER TO accusys;

--
-- Name: processor_results_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.processor_results_id_seq OWNED BY public.processor_results.id;


--
-- Name: python_script_tracking; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.python_script_tracking (
    id integer NOT NULL,
    script_path text NOT NULL,
    shebang_version character varying(20),
    actual_version character varying(20),
    is_compliant boolean DEFAULT false,
    last_run_at timestamp without time zone,
    exit_code integer,
    error_output text,
    checked_at timestamp without time zone DEFAULT now()
);


ALTER TABLE public.python_script_tracking OWNER TO accusys;

--
-- Name: python_script_tracking_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.python_script_tracking_id_seq OWNER TO accusys;

--
-- Name: python_script_tracking_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.python_script_tracking_id_seq OWNED BY public.python_script_tracking.id;


--
-- Name: python_version_baseline; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.python_version_baseline (
    id integer NOT NULL,
    runtime_name character varying(50) NOT NULL,
    required_version character varying(20) NOT NULL,
    current_version character varying(20),
    interpreter_path character varying(500),
    is_compliant boolean,
    checked_at timestamp without time zone DEFAULT now()
);


ALTER TABLE public.python_version_baseline OWNER TO accusys;

--
-- Name: python_version_baseline_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.python_version_baseline_id_seq OWNER TO accusys;

--
-- Name: python_version_baseline_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.python_version_baseline_id_seq OWNED BY public.python_version_baseline.id;


--
-- Name: storage_access_logs; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.storage_access_logs (
    id integer NOT NULL,
    user_cluster character varying(50),
    owner_id character varying(100),
    file_path text,
    access_type character varying(20),
    access_time timestamp without time zone DEFAULT now(),
    client_ip character varying(45),
    access_method character varying(20),
    CONSTRAINT storage_access_logs_access_type_check CHECK (((access_type)::text = ANY ((ARRAY['read'::character varying, 'write'::character varying, 'delete'::character varying, 'download'::character varying, 'move'::character varying])::text[])))
);


ALTER TABLE public.storage_access_logs OWNER TO accusys;

--
-- Name: storage_access_logs_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.storage_access_logs_id_seq OWNER TO accusys;

--
-- Name: storage_access_logs_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.storage_access_logs_id_seq OWNED BY public.storage_access_logs.id;


--
-- Name: storage_usage_stats; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.storage_usage_stats (
    id integer NOT NULL,
    user_cluster character varying(50),
    storage_tier character varying(20),
    file_count bigint,
    total_size_bytes bigint,
    record_time timestamp without time zone DEFAULT now()
);


ALTER TABLE public.storage_usage_stats OWNER TO accusys;

--
-- Name: storage_usage_stats_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.storage_usage_stats_id_seq OWNER TO accusys;

--
-- Name: storage_usage_stats_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.storage_usage_stats_id_seq OWNED BY public.storage_usage_stats.id;


--
-- Name: v_idle_workflows; Type: VIEW; Schema: public; Owner: accusys
--

CREATE VIEW public.v_idle_workflows AS
 SELECT workflow_name,
    idle_days,
    suggestion,
    last_executed_at
   FROM public.monitor_workflows
  WHERE ((idle_days > 30) AND (is_active = true))
  ORDER BY idle_days DESC;


ALTER VIEW public.v_idle_workflows OWNER TO accusys;

--
-- Name: v_recent_anomalies; Type: VIEW; Schema: public; Owner: accusys
--

CREATE VIEW public.v_recent_anomalies AS
 SELECT anomaly_type,
    severity,
    username,
    source_ip,
    description,
    detected_at
   FROM public.monitor_anomalies
  WHERE (detected_at > (now() - '24:00:00'::interval))
  ORDER BY detected_at DESC;


ALTER VIEW public.v_recent_anomalies OWNER TO accusys;

--
-- Name: v_service_health; Type: VIEW; Schema: public; Owner: accusys
--

CREATE VIEW public.v_service_health AS
 SELECT service_name,
    status,
    count(*) AS check_count,
    count(*) FILTER (WHERE ((status)::text = 'up'::text)) AS up_count,
    count(*) FILTER (WHERE ((status)::text = 'down'::text)) AS down_count,
    avg(response_time_ms) AS avg_response_time,
    max(checked_at) AS last_check
   FROM public.monitor_services
  WHERE (checked_at > (now() - '24:00:00'::interval))
  GROUP BY service_name, status;


ALTER VIEW public.v_service_health OWNER TO accusys;

--
-- Name: v_storage_overview; Type: VIEW; Schema: public; Owner: accusys
--

CREATE VIEW public.v_storage_overview AS
 SELECT user_cluster,
    storage_tier,
    count(*) AS file_count,
    sum(file_size) AS total_size
   FROM public.file_registry
  WHERE ((status)::text = 'active'::text)
  GROUP BY user_cluster, storage_tier;


ALTER VIEW public.v_storage_overview OWNER TO accusys;

--
-- Name: video_events; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.video_events (
    id integer NOT NULL,
    uuid text NOT NULL,
    start_time double precision NOT NULL,
    end_time double precision NOT NULL,
    event_type text NOT NULL,
    confidence double precision DEFAULT 0.0,
    metadata jsonb,
    created_at timestamp with time zone DEFAULT now()
);


ALTER TABLE public.video_events OWNER TO accusys;

--
-- Name: video_events_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.video_events_id_seq OWNER TO accusys;

--
-- Name: video_events_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.video_events_id_seq OWNED BY public.video_events.id;


--
-- Name: video_identities; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.video_identities (
    id integer NOT NULL,
    uuid text NOT NULL,
    name text NOT NULL,
    metadata jsonb DEFAULT '{}'::jsonb,
    created_at timestamp with time zone DEFAULT now()
);


ALTER TABLE public.video_identities OWNER TO accusys;

--
-- Name: video_identities_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.video_identities_id_seq OWNER TO accusys;

--
-- Name: video_identities_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.video_identities_id_seq OWNED BY public.video_identities.id;


--
-- Name: videos; Type: TABLE; Schema: public; Owner: accusys
--

CREATE TABLE public.videos (
    id integer NOT NULL,
    file_uuid character varying(32) CONSTRAINT videos_uuid_not_null NOT NULL,
    file_path text NOT NULL,
    file_name text NOT NULL,
    duration double precision,
    width integer,
    height integer,
    fps double precision,
    probe_json jsonb,
    created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
    updated_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
    fs_video boolean DEFAULT false,
    fs_json boolean DEFAULT false,
    psql_chunk boolean DEFAULT false,
    pobject_chunk boolean DEFAULT false,
    mobject_chunk boolean DEFAULT false,
    pvector_chunk boolean DEFAULT false,
    qvector_chunk boolean DEFAULT false,
    status character varying(20) DEFAULT 'pending'::character varying,
    user_id bigint,
    job_id integer,
    registered_at timestamp without time zone,
    registration_time timestamp with time zone,
    total_frames bigint DEFAULT 0,
    processing_status jsonb DEFAULT '{}'::jsonb,
    file_type character varying(20),
    birth_registration jsonb DEFAULT '{}'::jsonb,
    CONSTRAINT chk_videos_status CHECK (((status)::text = ANY ((ARRAY['pending'::character varying, 'processing'::character varying, 'completed'::character varying, 'failed'::character varying])::text[])))
);


ALTER TABLE public.videos OWNER TO accusys;

--
-- Name: COLUMN videos.status; Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON COLUMN public.videos.status IS 'Video processing status: pending, processing, completed, failed';


--
-- Name: COLUMN videos.user_id; Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON COLUMN public.videos.user_id IS 'WordPress user ID (for user association tracking)';


--
-- Name: COLUMN videos.job_id; Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON COLUMN public.videos.job_id IS 'Associated monitor_jobs ID';


--
-- Name: COLUMN videos.processing_status; Type: COMMENT; Schema: public; Owner: accusys
--

COMMENT ON COLUMN public.videos.processing_status IS 'Processing progress JSON: {"active_processors": [...], "progress": {...}}';


--
-- Name: videos_id_seq; Type: SEQUENCE; Schema: public; Owner: accusys
--

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


ALTER SEQUENCE public.videos_id_seq OWNER TO accusys;

--
-- Name: videos_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: accusys
--

ALTER SEQUENCE public.videos_id_seq OWNED BY public.videos.id;


--
-- Name: api_key_anomalies id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: api_key_audit_log id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


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

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


--
-- Name: backup_history id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: backup_registry id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: backup_storage_stats id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: castings id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: characters id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: child_chunks id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: chunk_vectors id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: chunks id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: face_clusters id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: face_detections id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: face_identities id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: face_recognition_results id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: file_lifecycle id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: frames id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: gitea_tokens id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: identities id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: identity_bindings id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: merge_history id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: monitor_anomalies id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: monitor_config id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: monitor_databases id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: monitor_external id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: monitor_jobs id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: monitor_logins id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: monitor_pg_schema_changes id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: monitor_pg_tables id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: monitor_portal_pages id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: monitor_portal_users id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: monitor_qdrant_collections id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: monitor_resource_usage id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: monitor_services id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: monitor_sessions id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: monitor_sudo_history id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: monitor_workflows id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: n8n_api_keys id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: node_process_tracking id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: node_version_baseline id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: parent_chunks id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: parent_chunks_poc id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: person_appearances id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: person_identities id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: processor_results id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: python_script_tracking id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: python_version_baseline id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: storage_access_logs id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: storage_usage_stats id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: video_events id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: video_identities id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: videos id; Type: DEFAULT; Schema: public; Owner: accusys
--

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


--
-- Name: api_key_anomalies api_key_anomalies_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.api_key_anomalies
    ADD CONSTRAINT api_key_anomalies_pkey PRIMARY KEY (id);


--
-- Name: api_key_audit_log api_key_audit_log_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.api_key_audit_log
    ADD CONSTRAINT api_key_audit_log_pkey PRIMARY KEY (id);


--
-- Name: api_keys api_keys_key_id_key; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.api_keys
    ADD CONSTRAINT api_keys_key_id_key UNIQUE (key_id);


--
-- Name: api_keys api_keys_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.api_keys
    ADD CONSTRAINT api_keys_pkey PRIMARY KEY (id);


--
-- Name: backup_history backup_history_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.backup_history
    ADD CONSTRAINT backup_history_pkey PRIMARY KEY (id);


--
-- Name: backup_registry backup_registry_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.backup_registry
    ADD CONSTRAINT backup_registry_pkey PRIMARY KEY (id);


--
-- Name: backup_storage_stats backup_storage_stats_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.backup_storage_stats
    ADD CONSTRAINT backup_storage_stats_pkey PRIMARY KEY (id);


--
-- Name: castings castings_character_id_talent_id_track_type_key; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.castings
    ADD CONSTRAINT castings_character_id_talent_id_track_type_key UNIQUE (character_id, talent_id, track_type);


--
-- Name: castings castings_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.castings
    ADD CONSTRAINT castings_pkey PRIMARY KEY (id);


--
-- Name: characters characters_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.characters
    ADD CONSTRAINT characters_pkey PRIMARY KEY (id);


--
-- Name: characters characters_video_uuid_name_language_track_key; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.characters
    ADD CONSTRAINT characters_video_uuid_name_language_track_key UNIQUE (video_uuid, name, language_track);


--
-- Name: child_chunks child_chunks_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.child_chunks
    ADD CONSTRAINT child_chunks_pkey PRIMARY KEY (id);


--
-- Name: chunk_vectors chunk_vectors_chunk_id_uuid_key; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.chunk_vectors
    ADD CONSTRAINT chunk_vectors_chunk_id_uuid_key UNIQUE (chunk_id, uuid);


--
-- Name: chunk_vectors chunk_vectors_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.chunk_vectors
    ADD CONSTRAINT chunk_vectors_pkey PRIMARY KEY (id);


--
-- Name: chunks chunks_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.chunks
    ADD CONSTRAINT chunks_pkey PRIMARY KEY (id);


--
-- Name: chunks chunks_uuid_chunk_id_key; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.chunks
    ADD CONSTRAINT chunks_uuid_chunk_id_key UNIQUE (uuid, chunk_id);


--
-- Name: face_clusters face_clusters_cluster_id_key; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.face_clusters
    ADD CONSTRAINT face_clusters_cluster_id_key UNIQUE (cluster_id);


--
-- Name: face_clusters face_clusters_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.face_clusters
    ADD CONSTRAINT face_clusters_pkey PRIMARY KEY (id);


--
-- Name: face_detections face_detections_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.face_detections
    ADD CONSTRAINT face_detections_pkey PRIMARY KEY (id);


--
-- Name: face_identities face_identities_face_id_key; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.face_identities
    ADD CONSTRAINT face_identities_face_id_key UNIQUE (face_id);


--
-- Name: face_identities face_identities_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.face_identities
    ADD CONSTRAINT face_identities_pkey PRIMARY KEY (id);


--
-- Name: face_recognition_results face_recognition_results_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.face_recognition_results
    ADD CONSTRAINT face_recognition_results_pkey PRIMARY KEY (id);


--
-- Name: face_recognition_results face_recognition_results_video_uuid_key; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.face_recognition_results
    ADD CONSTRAINT face_recognition_results_video_uuid_key UNIQUE (video_uuid);


--
-- Name: file_lifecycle file_lifecycle_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.file_lifecycle
    ADD CONSTRAINT file_lifecycle_pkey PRIMARY KEY (id);


--
-- Name: file_registry file_registry_file_path_hash_key; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.file_registry
    ADD CONSTRAINT file_registry_file_path_hash_key UNIQUE (file_path_hash);


--
-- Name: file_registry file_registry_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.file_registry
    ADD CONSTRAINT file_registry_pkey PRIMARY KEY (file_uuid);


--
-- Name: frames frames_file_id_frame_number_key; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.frames
    ADD CONSTRAINT frames_file_id_frame_number_key UNIQUE (file_id, frame_number);


--
-- Name: frames frames_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.frames
    ADD CONSTRAINT frames_pkey PRIMARY KEY (id);


--
-- Name: gitea_tokens gitea_tokens_gitea_user_token_name_key; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.gitea_tokens
    ADD CONSTRAINT gitea_tokens_gitea_user_token_name_key UNIQUE (gitea_user, token_name);


--
-- Name: gitea_tokens gitea_tokens_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.gitea_tokens
    ADD CONSTRAINT gitea_tokens_pkey PRIMARY KEY (id);


--
-- Name: identities identities_name_key; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.identities
    ADD CONSTRAINT identities_name_key UNIQUE (name);


--
-- Name: identities identities_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.identities
    ADD CONSTRAINT identities_pkey PRIMARY KEY (id);


--
-- Name: identity_bindings identity_bindings_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.identity_bindings
    ADD CONSTRAINT identity_bindings_pkey PRIMARY KEY (id);


--
-- Name: identity_bindings identity_bindings_uuid_binding_type_binding_value_key; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.identity_bindings
    ADD CONSTRAINT identity_bindings_uuid_binding_type_binding_value_key UNIQUE (uuid, binding_type, binding_value);


--
-- Name: merge_history merge_history_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.merge_history
    ADD CONSTRAINT merge_history_pkey PRIMARY KEY (id);


--
-- Name: monitor_anomalies monitor_anomalies_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.monitor_anomalies
    ADD CONSTRAINT monitor_anomalies_pkey PRIMARY KEY (id);


--
-- Name: monitor_config monitor_config_config_key_key; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.monitor_config
    ADD CONSTRAINT monitor_config_config_key_key UNIQUE (config_key);


--
-- Name: monitor_config monitor_config_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.monitor_config
    ADD CONSTRAINT monitor_config_pkey PRIMARY KEY (id);


--
-- Name: monitor_databases monitor_databases_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.monitor_databases
    ADD CONSTRAINT monitor_databases_pkey PRIMARY KEY (id);


--
-- Name: monitor_external monitor_external_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.monitor_external
    ADD CONSTRAINT monitor_external_pkey PRIMARY KEY (id);


--
-- Name: monitor_jobs monitor_jobs_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.monitor_jobs
    ADD CONSTRAINT monitor_jobs_pkey PRIMARY KEY (id);


--
-- Name: monitor_logins monitor_logins_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.monitor_logins
    ADD CONSTRAINT monitor_logins_pkey PRIMARY KEY (id);


--
-- Name: monitor_pg_schema_changes monitor_pg_schema_changes_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.monitor_pg_schema_changes
    ADD CONSTRAINT monitor_pg_schema_changes_pkey PRIMARY KEY (id);


--
-- Name: monitor_pg_tables monitor_pg_tables_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.monitor_pg_tables
    ADD CONSTRAINT monitor_pg_tables_pkey PRIMARY KEY (id);


--
-- Name: monitor_portal_pages monitor_portal_pages_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.monitor_portal_pages
    ADD CONSTRAINT monitor_portal_pages_pkey PRIMARY KEY (id);


--
-- Name: monitor_portal_users monitor_portal_users_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.monitor_portal_users
    ADD CONSTRAINT monitor_portal_users_pkey PRIMARY KEY (id);


--
-- Name: monitor_qdrant_collections monitor_qdrant_collections_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.monitor_qdrant_collections
    ADD CONSTRAINT monitor_qdrant_collections_pkey PRIMARY KEY (id);


--
-- Name: monitor_resource_usage monitor_resource_usage_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.monitor_resource_usage
    ADD CONSTRAINT monitor_resource_usage_pkey PRIMARY KEY (id);


--
-- Name: monitor_services monitor_services_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.monitor_services
    ADD CONSTRAINT monitor_services_pkey PRIMARY KEY (id);


--
-- Name: monitor_sessions monitor_sessions_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.monitor_sessions
    ADD CONSTRAINT monitor_sessions_pkey PRIMARY KEY (id);


--
-- Name: monitor_sudo_history monitor_sudo_history_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.monitor_sudo_history
    ADD CONSTRAINT monitor_sudo_history_pkey PRIMARY KEY (id);


--
-- Name: monitor_workflows monitor_workflows_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.monitor_workflows
    ADD CONSTRAINT monitor_workflows_pkey PRIMARY KEY (id);


--
-- Name: n8n_api_keys n8n_api_keys_n8n_key_id_key; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.n8n_api_keys
    ADD CONSTRAINT n8n_api_keys_n8n_key_id_key UNIQUE (n8n_key_id);


--
-- Name: n8n_api_keys n8n_api_keys_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.n8n_api_keys
    ADD CONSTRAINT n8n_api_keys_pkey PRIMARY KEY (id);


--
-- Name: node_process_tracking node_process_tracking_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.node_process_tracking
    ADD CONSTRAINT node_process_tracking_pkey PRIMARY KEY (id);


--
-- Name: node_version_baseline node_version_baseline_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.node_version_baseline
    ADD CONSTRAINT node_version_baseline_pkey PRIMARY KEY (id);


--
-- Name: parent_chunks parent_chunks_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.parent_chunks
    ADD CONSTRAINT parent_chunks_pkey PRIMARY KEY (id);


--
-- Name: parent_chunks_poc parent_chunks_poc_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.parent_chunks_poc
    ADD CONSTRAINT parent_chunks_poc_pkey PRIMARY KEY (id);


--
-- Name: person_appearances person_appearances_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.person_appearances
    ADD CONSTRAINT person_appearances_pkey PRIMARY KEY (id);


--
-- Name: person_identities person_identities_person_id_key; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.person_identities
    ADD CONSTRAINT person_identities_person_id_key UNIQUE (person_id);


--
-- Name: person_identities person_identities_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.person_identities
    ADD CONSTRAINT person_identities_pkey PRIMARY KEY (id);


--
-- Name: processor_results processor_results_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.processor_results
    ADD CONSTRAINT processor_results_pkey PRIMARY KEY (id);


--
-- Name: python_script_tracking python_script_tracking_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.python_script_tracking
    ADD CONSTRAINT python_script_tracking_pkey PRIMARY KEY (id);


--
-- Name: python_version_baseline python_version_baseline_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.python_version_baseline
    ADD CONSTRAINT python_version_baseline_pkey PRIMARY KEY (id);


--
-- Name: storage_access_logs storage_access_logs_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.storage_access_logs
    ADD CONSTRAINT storage_access_logs_pkey PRIMARY KEY (id);


--
-- Name: storage_usage_stats storage_usage_stats_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.storage_usage_stats
    ADD CONSTRAINT storage_usage_stats_pkey PRIMARY KEY (id);


--
-- Name: face_detections unique_detection_per_frame; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.face_detections
    ADD CONSTRAINT unique_detection_per_frame UNIQUE (video_uuid, frame_number, x, y, width, height);


--
-- Name: processor_results unique_job_processor; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.processor_results
    ADD CONSTRAINT unique_job_processor UNIQUE (job_id, processor);


--
-- Name: person_identities unique_person_identity; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.person_identities
    ADD CONSTRAINT unique_person_identity UNIQUE (video_uuid, face_identity_id, speaker_id);


--
-- Name: video_events video_events_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.video_events
    ADD CONSTRAINT video_events_pkey PRIMARY KEY (id);


--
-- Name: video_identities video_identities_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.video_identities
    ADD CONSTRAINT video_identities_pkey PRIMARY KEY (id);


--
-- Name: videos videos_pkey; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.videos
    ADD CONSTRAINT videos_pkey PRIMARY KEY (id);


--
-- Name: videos videos_uuid_key; Type: CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.videos
    ADD CONSTRAINT videos_uuid_key UNIQUE (file_uuid);


--
-- Name: idx_anomalies_key_id; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_anomalies_key_id ON public.api_key_anomalies USING btree (key_id);


--
-- Name: idx_anomalies_resolved; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_anomalies_resolved ON public.api_key_anomalies USING btree (resolved);


--
-- Name: idx_api_keys_hash; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_api_keys_hash ON public.api_keys USING btree (key_hash);


--
-- Name: idx_api_keys_key_id; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_api_keys_key_id ON public.api_keys USING btree (key_id);


--
-- Name: idx_api_keys_status; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_api_keys_status ON public.api_keys USING btree (status);


--
-- Name: idx_api_keys_type; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_api_keys_type ON public.api_keys USING btree (key_type);


--
-- Name: idx_audit_action; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_audit_action ON public.api_key_audit_log USING btree (action);


--
-- Name: idx_audit_created_at; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_audit_created_at ON public.api_key_audit_log USING btree (created_at);


--
-- Name: idx_audit_key_id; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_audit_key_id ON public.api_key_audit_log USING btree (key_id);


--
-- Name: idx_backup_history_service; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_backup_history_service ON public.backup_history USING btree (service_name);


--
-- Name: idx_backup_history_time; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_backup_history_time ON public.backup_history USING btree (executed_at);


--
-- Name: idx_backup_registry_service; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_backup_registry_service ON public.backup_registry USING btree (service_name);


--
-- Name: idx_backup_registry_time; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_backup_registry_time ON public.backup_registry USING btree (created_at);


--
-- Name: idx_backup_storage_stats_tier; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_backup_storage_stats_tier ON public.backup_storage_stats USING btree (tier);


--
-- Name: idx_backup_storage_stats_time; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_backup_storage_stats_time ON public.backup_storage_stats USING btree (record_time);


--
-- Name: idx_bindings_identity; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_bindings_identity ON public.identity_bindings USING btree (identity_id);


--
-- Name: idx_bindings_lookup; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_bindings_lookup ON public.identity_bindings USING btree (uuid, binding_type, binding_value);


--
-- Name: idx_child_parent; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_child_parent ON public.child_chunks USING btree (parent_id);


--
-- Name: idx_chunk_vectors_chunk_id; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_chunk_vectors_chunk_id ON public.chunk_vectors USING btree (chunk_id);


--
-- Name: idx_chunk_vectors_embedding_hnsw; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_chunk_vectors_embedding_hnsw ON public.chunk_vectors USING hnsw (embedding_vector public.vector_cosine_ops);


--
-- Name: idx_chunk_vectors_file_id; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_chunk_vectors_file_id ON public.chunk_vectors USING btree (file_id);


--
-- Name: idx_chunk_vectors_uuid; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_chunk_vectors_uuid ON public.chunk_vectors USING btree (uuid);


--
-- Name: idx_chunks_content_gin; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_chunks_content_gin ON public.chunks USING gin (content);


--
-- Name: idx_chunks_file_id; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_chunks_file_id ON public.chunks USING btree (file_id);


--
-- Name: idx_chunks_search_vector; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_chunks_search_vector ON public.chunks USING gin (search_vector);


--
-- Name: idx_chunks_time; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_chunks_time ON public.chunks USING btree (start_time, end_time);


--
-- Name: idx_chunks_type; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_chunks_type ON public.chunks USING btree (chunk_type);


--
-- Name: idx_chunks_uuid; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_chunks_uuid ON public.chunks USING btree (uuid);


--
-- Name: idx_chunks_uuid_type; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_chunks_uuid_type ON public.chunks USING btree (uuid, chunk_type);


--
-- Name: idx_face_clusters_video_uuid; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_face_clusters_video_uuid ON public.face_clusters USING btree (video_uuid);


--
-- Name: idx_face_detections_cluster; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_face_detections_cluster ON public.face_detections USING btree (cluster_id);


--
-- Name: idx_face_detections_embedding; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_face_detections_embedding ON public.face_detections USING ivfflat (embedding public.vector_cosine_ops) WITH (lists='100');


--
-- Name: idx_face_detections_face_id; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_face_detections_face_id ON public.face_detections USING btree (face_id);


--
-- Name: idx_face_detections_frame; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_face_detections_frame ON public.face_detections USING btree (video_uuid, frame_number);


--
-- Name: idx_face_detections_identity; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_face_detections_identity ON public.face_detections USING btree (identity_id);


--
-- Name: idx_face_detections_video_uuid; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_face_detections_video_uuid ON public.face_detections USING btree (video_uuid);


--
-- Name: idx_face_identities_embedding; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_face_identities_embedding ON public.face_identities USING ivfflat (embedding public.vector_cosine_ops) WITH (lists='100');


--
-- Name: idx_face_recognition_results_created_at; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_face_recognition_results_created_at ON public.face_recognition_results USING btree (created_at);


--
-- Name: idx_file_registry_cluster; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_file_registry_cluster ON public.file_registry USING btree (user_cluster);


--
-- Name: idx_file_registry_status; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_file_registry_status ON public.file_registry USING btree (status);


--
-- Name: idx_file_registry_tier; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_file_registry_tier ON public.file_registry USING btree (storage_tier);


--
-- Name: idx_frames_face_gin; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_frames_face_gin ON public.frames USING gin (face_results);


--
-- Name: idx_frames_file_id; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_frames_file_id ON public.frames USING btree (file_id);


--
-- Name: idx_frames_frame; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_frames_frame ON public.frames USING btree (file_id, frame_number);


--
-- Name: idx_frames_ocr_gin; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_frames_ocr_gin ON public.frames USING gin (ocr_results);


--
-- Name: idx_frames_pose_gin; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_frames_pose_gin ON public.frames USING gin (pose_results);


--
-- Name: idx_frames_timestamp; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_frames_timestamp ON public.frames USING btree (file_id, "timestamp");


--
-- Name: idx_frames_yolo_gin; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_frames_yolo_gin ON public.frames USING gin (yolo_objects);


--
-- Name: idx_gitea_tokens_key_id; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_gitea_tokens_key_id ON public.gitea_tokens USING btree (api_key_id);


--
-- Name: idx_gitea_tokens_user; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_gitea_tokens_user ON public.gitea_tokens USING btree (gitea_user);


--
-- Name: idx_identities_face_embedding; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_identities_face_embedding ON public.identities USING ivfflat (face_embedding public.vector_cosine_ops) WITH (lists='100');


--
-- Name: idx_identities_identity_embedding; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_identities_identity_embedding ON public.identities USING ivfflat (identity_embedding public.vector_cosine_ops) WITH (lists='100');


--
-- Name: idx_identities_reference_data; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_identities_reference_data ON public.identities USING gin (reference_data);


--
-- Name: idx_identities_uuid; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_identities_uuid ON public.identities USING btree (uuid);


--
-- Name: idx_identities_voice_embedding; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_identities_voice_embedding ON public.identities USING ivfflat (voice_embedding public.vector_cosine_ops) WITH (lists='50');


--
-- Name: idx_monitor_anomalies_severity; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_monitor_anomalies_severity ON public.monitor_anomalies USING btree (severity);


--
-- Name: idx_monitor_anomalies_time; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_monitor_anomalies_time ON public.monitor_anomalies USING btree (detected_at);


--
-- Name: idx_monitor_anomalies_type; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_monitor_anomalies_type ON public.monitor_anomalies USING btree (anomaly_type);


--
-- Name: idx_monitor_databases_time; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_monitor_databases_time ON public.monitor_databases USING btree (checked_at);


--
-- Name: idx_monitor_databases_type; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_monitor_databases_type ON public.monitor_databases USING btree (db_type);


--
-- Name: idx_monitor_external_name; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_monitor_external_name ON public.monitor_external USING btree (target_name);


--
-- Name: idx_monitor_external_time; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_monitor_external_time ON public.monitor_external USING btree (checked_at);


--
-- Name: idx_monitor_jobs_created_at; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_monitor_jobs_created_at ON public.monitor_jobs USING btree (created_at);


--
-- Name: idx_monitor_jobs_processors; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_monitor_jobs_processors ON public.monitor_jobs USING gin (processors);


--
-- Name: idx_monitor_jobs_status; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_monitor_jobs_status ON public.monitor_jobs USING btree (status);


--
-- Name: idx_monitor_jobs_status_created; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_monitor_jobs_status_created ON public.monitor_jobs USING btree (status, created_at);


--
-- Name: idx_monitor_jobs_uuid; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_monitor_jobs_uuid ON public.monitor_jobs USING btree (uuid);


--
-- Name: idx_monitor_jobs_video_id; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_monitor_jobs_video_id ON public.monitor_jobs USING btree (video_id);


--
-- Name: idx_monitor_logins_time; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_monitor_logins_time ON public.monitor_logins USING btree (login_at);


--
-- Name: idx_monitor_logins_type; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_monitor_logins_type ON public.monitor_logins USING btree (user_type);


--
-- Name: idx_monitor_portal_pages_url; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_monitor_portal_pages_url ON public.monitor_portal_pages USING btree (page_url);


--
-- Name: idx_monitor_portal_users_username; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_monitor_portal_users_username ON public.monitor_portal_users USING btree (username);


--
-- Name: idx_monitor_services_name; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_monitor_services_name ON public.monitor_services USING btree (service_name);


--
-- Name: idx_monitor_services_time; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_monitor_services_time ON public.monitor_services USING btree (checked_at);


--
-- Name: idx_monitor_sessions_type; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_monitor_sessions_type ON public.monitor_sessions USING btree (session_type);


--
-- Name: idx_monitor_sessions_username; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_monitor_sessions_username ON public.monitor_sessions USING btree (username);


--
-- Name: idx_monitor_workflows_active; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_monitor_workflows_active ON public.monitor_workflows USING btree (is_active);


--
-- Name: idx_monitor_workflows_id; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_monitor_workflows_id ON public.monitor_workflows USING btree (workflow_id);


--
-- Name: idx_monitor_workflows_idle; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_monitor_workflows_idle ON public.monitor_workflows USING btree (idle_days);


--
-- Name: idx_n8n_api_keys_key_id; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_n8n_api_keys_key_id ON public.n8n_api_keys USING btree (momentry_api_key_id);


--
-- Name: idx_n8n_api_keys_label; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_n8n_api_keys_label ON public.n8n_api_keys USING btree (label);


--
-- Name: idx_node_process_name; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_node_process_name ON public.node_process_tracking USING btree (process_name);


--
-- Name: idx_node_version_name; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_node_version_name ON public.node_version_baseline USING btree (runtime_name);


--
-- Name: idx_person_appearances_face; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_person_appearances_face ON public.person_appearances USING btree (face_detection_id) WHERE (face_detection_id IS NOT NULL);


--
-- Name: idx_person_appearances_person; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_person_appearances_person ON public.person_appearances USING btree (person_id);


--
-- Name: idx_person_appearances_time; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_person_appearances_time ON public.person_appearances USING btree (video_uuid, start_time, end_time);


--
-- Name: idx_person_appearances_video; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_person_appearances_video ON public.person_appearances USING btree (video_uuid);


--
-- Name: idx_person_identities_confirmed; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_person_identities_confirmed ON public.person_identities USING btree (is_confirmed) WHERE (is_confirmed = true);


--
-- Name: idx_person_identities_face; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_person_identities_face ON public.person_identities USING btree (face_identity_id) WHERE (face_identity_id IS NOT NULL);


--
-- Name: idx_person_identities_name; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_person_identities_name ON public.person_identities USING btree (name) WHERE (name IS NOT NULL);


--
-- Name: idx_person_identities_speaker; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_person_identities_speaker ON public.person_identities USING btree (speaker_id) WHERE (speaker_id IS NOT NULL);


--
-- Name: idx_person_identities_video_uuid; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_person_identities_video_uuid ON public.person_identities USING btree (video_uuid);


--
-- Name: idx_processor_results_job; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_processor_results_job ON public.processor_results USING btree (job_id);


--
-- Name: idx_processor_results_output_data; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_processor_results_output_data ON public.processor_results USING gin (output_data);


--
-- Name: idx_processor_results_status; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_processor_results_status ON public.processor_results USING btree (status);


--
-- Name: idx_processor_results_video; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_processor_results_video ON public.processor_results USING btree (video_id);


--
-- Name: idx_python_script_path; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_python_script_path ON public.python_script_tracking USING btree (script_path);


--
-- Name: idx_python_version_name; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_python_version_name ON public.python_version_baseline USING btree (runtime_name);


--
-- Name: idx_storage_usage_cluster; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_storage_usage_cluster ON public.storage_usage_stats USING btree (user_cluster);


--
-- Name: idx_storage_usage_time; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_storage_usage_time ON public.storage_usage_stats USING btree (record_time);


--
-- Name: idx_video_events_type; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_video_events_type ON public.video_events USING btree (event_type);


--
-- Name: idx_video_events_uuid; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_video_events_uuid ON public.video_events USING btree (uuid);


--
-- Name: idx_video_identities_uuid; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_video_identities_uuid ON public.video_identities USING btree (uuid);


--
-- Name: idx_videos_file_uuid; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_videos_file_uuid ON public.videos USING btree (file_uuid);


--
-- Name: idx_videos_job_id; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_videos_job_id ON public.videos USING btree (job_id);


--
-- Name: idx_videos_status; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_videos_status ON public.videos USING btree (status);


--
-- Name: idx_videos_user_id; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_videos_user_id ON public.videos USING btree (user_id);


--
-- Name: idx_videos_uuid; Type: INDEX; Schema: public; Owner: accusys
--

CREATE INDEX idx_videos_uuid ON public.videos USING btree (file_uuid);


--
-- Name: chunks chunks_search_vector_trigger; Type: TRIGGER; Schema: public; Owner: accusys
--

CREATE TRIGGER chunks_search_vector_trigger BEFORE INSERT OR UPDATE ON public.chunks FOR EACH ROW EXECUTE FUNCTION public.update_search_vector();


--
-- Name: person_appearances trigger_update_person_appearance_stats; Type: TRIGGER; Schema: public; Owner: accusys
--

CREATE TRIGGER trigger_update_person_appearance_stats AFTER INSERT OR DELETE OR UPDATE ON public.person_appearances FOR EACH ROW EXECUTE FUNCTION public.trigger_update_person_stats();


--
-- Name: face_identities update_face_identities_updated_at; Type: TRIGGER; Schema: public; Owner: accusys
--

CREATE TRIGGER update_face_identities_updated_at BEFORE UPDATE ON public.face_identities FOR EACH ROW EXECUTE FUNCTION public.update_updated_at_column();


--
-- Name: face_recognition_results update_face_recognition_results_updated_at; Type: TRIGGER; Schema: public; Owner: accusys
--

CREATE TRIGGER update_face_recognition_results_updated_at BEFORE UPDATE ON public.face_recognition_results FOR EACH ROW EXECUTE FUNCTION public.update_updated_at_column();


--
-- Name: monitor_jobs update_monitor_jobs_updated_at; Type: TRIGGER; Schema: public; Owner: accusys
--

CREATE TRIGGER update_monitor_jobs_updated_at BEFORE UPDATE ON public.monitor_jobs FOR EACH ROW EXECUTE FUNCTION public.update_updated_at_column();


--
-- Name: person_identities update_person_identities_updated_at; Type: TRIGGER; Schema: public; Owner: accusys
--

CREATE TRIGGER update_person_identities_updated_at BEFORE UPDATE ON public.person_identities FOR EACH ROW EXECUTE FUNCTION public.update_updated_at_column();


--
-- Name: processor_results update_processor_results_updated_at; Type: TRIGGER; Schema: public; Owner: accusys
--

CREATE TRIGGER update_processor_results_updated_at BEFORE UPDATE ON public.processor_results FOR EACH ROW EXECUTE FUNCTION public.update_updated_at_column();


--
-- Name: videos update_videos_updated_at; Type: TRIGGER; Schema: public; Owner: accusys
--

CREATE TRIGGER update_videos_updated_at BEFORE UPDATE ON public.videos FOR EACH ROW EXECUTE FUNCTION public.update_updated_at_column();


--
-- Name: castings castings_character_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.castings
    ADD CONSTRAINT castings_character_id_fkey FOREIGN KEY (character_id) REFERENCES public.characters(id) ON DELETE CASCADE;


--
-- Name: child_chunks child_chunks_parent_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.child_chunks
    ADD CONSTRAINT child_chunks_parent_id_fkey FOREIGN KEY (parent_id) REFERENCES public.parent_chunks(id) ON DELETE CASCADE;


--
-- Name: chunk_vectors chunk_vectors_file_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.chunk_vectors
    ADD CONSTRAINT chunk_vectors_file_id_fkey FOREIGN KEY (file_id) REFERENCES public.videos(id);


--
-- Name: chunks chunks_file_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.chunks
    ADD CONSTRAINT chunks_file_id_fkey FOREIGN KEY (file_id) REFERENCES public.videos(id);


--
-- Name: face_detections face_detections_identity_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.face_detections
    ADD CONSTRAINT face_detections_identity_id_fkey FOREIGN KEY (identity_id) REFERENCES public.face_identities(id) ON DELETE SET NULL;


--
-- Name: file_lifecycle file_lifecycle_file_uuid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.file_lifecycle
    ADD CONSTRAINT file_lifecycle_file_uuid_fkey FOREIGN KEY (file_uuid) REFERENCES public.file_registry(file_uuid);


--
-- Name: monitor_jobs fk_monitor_jobs_video_id; Type: FK CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.monitor_jobs
    ADD CONSTRAINT fk_monitor_jobs_video_id FOREIGN KEY (video_id) REFERENCES public.videos(id) ON DELETE CASCADE;


--
-- Name: videos fk_videos_job_id; Type: FK CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.videos
    ADD CONSTRAINT fk_videos_job_id FOREIGN KEY (job_id) REFERENCES public.monitor_jobs(id) ON DELETE SET NULL;


--
-- Name: frames frames_file_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.frames
    ADD CONSTRAINT frames_file_id_fkey FOREIGN KEY (file_id) REFERENCES public.videos(id);


--
-- Name: identity_bindings identity_bindings_identity_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.identity_bindings
    ADD CONSTRAINT identity_bindings_identity_id_fkey FOREIGN KEY (identity_id) REFERENCES public.video_identities(id) ON DELETE CASCADE;


--
-- Name: person_appearances person_appearances_face_detection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.person_appearances
    ADD CONSTRAINT person_appearances_face_detection_id_fkey FOREIGN KEY (face_detection_id) REFERENCES public.face_detections(id) ON DELETE SET NULL;


--
-- Name: person_appearances person_appearances_person_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.person_appearances
    ADD CONSTRAINT person_appearances_person_id_fkey FOREIGN KEY (person_id) REFERENCES public.person_identities(person_id) ON DELETE CASCADE;


--
-- Name: person_identities person_identities_face_identity_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.person_identities
    ADD CONSTRAINT person_identities_face_identity_id_fkey FOREIGN KEY (face_identity_id) REFERENCES public.face_identities(id) ON DELETE SET NULL;


--
-- Name: processor_results processor_results_job_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.processor_results
    ADD CONSTRAINT processor_results_job_id_fkey FOREIGN KEY (job_id) REFERENCES public.monitor_jobs(id) ON DELETE CASCADE;


--
-- Name: processor_results processor_results_video_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: accusys
--

ALTER TABLE ONLY public.processor_results
    ADD CONSTRAINT processor_results_video_id_fkey FOREIGN KEY (video_id) REFERENCES public.videos(id) ON DELETE CASCADE;


--
-- PostgreSQL database dump complete
--

\unrestrict hRi4nBNv2E5FXxBTf47fTk0vxfJNiXtnegSYFeraY46zaCyMMlYNanEdl70C1E7

