Files
momentry_core/schema/schema.sql
T

3811 lines
98 KiB
PL/PgSQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- ============================================================
-- momentry schema.sql — 單一來源
-- 產出日期: 2026-10-05
-- 來源: M5Max128 既有正式 DB (momentry) 的 public schema
-- 對應 commit: 7c7cf60a (方案 A — 移除 hardcoded DDL)
-- 表 46 / 索引 98 / FK+UNIQUE 99 / 序列 42 / 觸發 4
--
-- 用法:
-- psql "$DATABASE_URL" -v ON_ERROR_STOP=1 -f schema.sql
--
-- 前置條件:
-- 1. CREATE EXTENSION vector 權限(pgvector,需 superuser 或預先授權)
-- 2. 目標 schema 必須為 public
--
-- 已知缺口(見文末補丁區塊):
-- videos 表缺 face_settings / asr_status / completed_at / vlm_description_localized
-- ============================================================
CREATE EXTENSION IF NOT EXISTS vector;
CREATE TABLE IF NOT EXISTS public.schema_version (
version integer PRIMARY KEY,
applied_at timestamptz NOT NULL DEFAULT NOW(),
description text
);
SET search_path = public, pg_catalog;
--
--
\restrict 69eeeC6OaRWFr7t5EhEOrDvyYCPR5Wpp3pGRA4hWMP2BS0dfesj1Fv1fqpMYNEW
-- Dumped from database version 18.3
-- Dumped by pg_dump version 18.6
--
-- Name: public; Type: SCHEMA; Schema: -; Owner: -
--
CREATE SCHEMA IF NOT EXISTS public;
--
-- Name: SCHEMA public; Type: COMMENT; Schema: -; Owner: -
--
COMMENT ON SCHEMA public IS 'standard public schema';
--
-- Name: auto_match_face_speaker(character varying, double precision); Type: FUNCTION; Schema: public; Owner: -
--
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;
$$;
--
-- Name: FUNCTION auto_match_face_speaker(p_video_uuid character varying, p_threshold double precision); Type: COMMENT; Schema: public; Owner: -
--
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: -
--
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;
$$;
--
-- 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: -
--
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: -
--
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;
$$;
--
-- Name: FUNCTION find_persons_at_time(p_video_uuid character varying, p_time double precision, p_tolerance double precision); Type: COMMENT; Schema: public; Owner: -
--
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: -
--
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;
$$;
--
-- 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: -
--
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: -
--
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;
$$;
--
-- Name: FUNCTION find_similar_faces(query_embedding public.vector, similarity_threshold double precision, limit_count integer); Type: COMMENT; Schema: public; Owner: -
--
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: jsonb_deep_merge(jsonb, jsonb); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.jsonb_deep_merge(base jsonb, override jsonb) RETURNS jsonb
LANGUAGE plpgsql IMMUTABLE
AS $$
DECLARE
result jsonb := COALESCE(base, '{}'::jsonb);
key text;
val jsonb;
BEGIN
FOR key, val IN SELECT * FROM jsonb_each(override)
LOOP
IF jsonb_typeof(val) = 'object' AND jsonb_typeof(result -> key) = 'object' THEN
result := jsonb_set(result, ARRAY[key], jsonb_deep_merge(result -> key, val));
ELSE
result := jsonb_set(result, ARRAY[key], val);
END IF;
END LOOP;
RETURN result;
END;
$$;
--
-- Name: merge_person_identities(character varying, character varying[]); Type: FUNCTION; Schema: public; Owner: -
--
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;
$$;
--
-- Name: FUNCTION merge_person_identities(p_target_person_id character varying, p_source_person_ids character varying[]); Type: COMMENT; Schema: public; Owner: -
--
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: -
--
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;
$$;
--
-- Name: update_cluster_centroid(character varying); Type: FUNCTION; Schema: public; Owner: -
--
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;
$$;
--
-- Name: FUNCTION update_cluster_centroid(cluster_uuid character varying); Type: COMMENT; Schema: public; Owner: -
--
COMMENT ON FUNCTION public.update_cluster_centroid(cluster_uuid character varying) IS 'Updates cluster centroid from member embeddings';
--
-- Name: update_mac_allocations_updated_at(); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.update_mac_allocations_updated_at() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
NEW.updated_at = NOW();
RETURN NEW;
END;
$$;
--
-- Name: update_person_appearance_stats(character varying); Type: FUNCTION; Schema: public; Owner: -
--
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;
$$;
--
-- Name: FUNCTION update_person_appearance_stats(p_person_id character varying); Type: COMMENT; Schema: public; Owner: -
--
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: -
--
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;
$$;
--
-- Name: update_updated_at_column(); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.update_updated_at_column() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
NEW.updated_at = CURRENT_TIMESTAMP;
RETURN NEW;
END;
$$;
--
-- Name: api_key_anomalies; Type: TABLE; Schema: public; Owner: -
--
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
);
--
-- Name: api_key_anomalies_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.api_key_anomalies_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: api_key_anomalies_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
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: -
--
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
);
--
-- Name: api_key_audit_log_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.api_key_audit_log_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: api_key_audit_log_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
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: -
--
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
);
--
-- Name: api_keys_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.api_keys_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: api_keys_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.api_keys_id_seq OWNED BY public.api_keys.id;
--
-- Name: billing_periods; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.billing_periods (
id integer NOT NULL,
key_id character varying(48),
period_month character varying(7) NOT NULL,
total_input_tokens bigint DEFAULT 0,
total_output_tokens bigint DEFAULT 0,
total_tokens bigint DEFAULT 0,
request_count bigint DEFAULT 0,
error_count bigint DEFAULT 0,
service_breakdown jsonb DEFAULT '{}'::jsonb,
model_breakdown jsonb DEFAULT '{}'::jsonb,
avg_duration_ms integer,
total_duration_ms bigint,
period_start date NOT NULL,
period_end date NOT NULL,
updated_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP
);
--
-- Name: billing_periods_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.billing_periods_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: billing_periods_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.billing_periods_id_seq OWNED BY public.billing_periods.id;
--
-- Name: castings; Type: TABLE; Schema: public; Owner: -
--
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
);
--
-- Name: TABLE castings; Type: COMMENT; Schema: public; Owner: -
--
COMMENT ON TABLE public.castings IS 'Talent 與 Character 的飾演關係';
--
-- Name: castings_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.castings_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: castings_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.castings_id_seq OWNED BY public.castings.id;
--
-- Name: characters; Type: TABLE; Schema: public; Owner: -
--
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
);
--
-- Name: TABLE characters; Type: COMMENT; Schema: public; Owner: -
--
COMMENT ON TABLE public.characters IS '視頻中的劇中角色';
--
-- Name: characters_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.characters_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: characters_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.characters_id_seq OWNED BY public.characters.id;
--
-- Name: chunk; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.chunk (
id integer NOT NULL,
file_uuid character varying(32) NOT NULL,
chunk_type character varying(32) NOT NULL,
start_time double precision,
end_time double precision,
content jsonb NOT NULL,
vector_id character varying(64),
created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
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,
fps double precision DEFAULT 24.0,
start_frame bigint DEFAULT 0,
end_frame bigint DEFAULT 0,
metadata jsonb,
updated_at timestamp with time zone DEFAULT now(),
visual_stats jsonb,
summary_text text,
chunk_id character varying(128) NOT NULL,
embedding public.vector,
old_chunk_id character varying(128),
chunk_index integer DEFAULT 0,
unique_key character varying
);
--
-- Name: chunk_vectors; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.chunk_vectors (
id integer NOT NULL,
chunk_id character varying(64) NOT NULL,
uuid character varying(64) NOT NULL,
chunk_type character varying(32) DEFAULT 'sentence'::character varying NOT NULL,
embedding jsonb,
created_at timestamp with time zone DEFAULT now()
);
--
-- Name: chunk_vectors_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.chunk_vectors_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: chunk_vectors_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.chunk_vectors_id_seq OWNED BY public.chunk_vectors.id;
--
-- Name: chunks_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.chunks_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: chunks_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.chunks_id_seq OWNED BY public.chunk.id;
--
-- Name: chunks_rule1; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.chunks_rule1 (
id bigint NOT NULL,
uuid character varying(255) NOT NULL,
chunk_id character varying(100) NOT NULL,
chunk_index integer NOT NULL,
start_time double precision,
end_time double precision,
start_frame bigint,
end_frame bigint,
fps double precision,
content jsonb,
metadata jsonb,
created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP
);
--
-- Name: chunks_rule1_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.chunks_rule1_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: chunks_rule1_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.chunks_rule1_id_seq OWNED BY public.chunks_rule1.id;
--
-- Name: command_queue; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.command_queue (
id integer NOT NULL,
command_id character varying(36) DEFAULT replace((gen_random_uuid())::text, '-'::text, ''::text) NOT NULL,
job_type character varying(20) NOT NULL,
file_path character varying(512),
file_uuid character varying(32),
user_id bigint,
payload jsonb DEFAULT '{}'::jsonb,
status character varying(20) DEFAULT 'pending'::character varying NOT NULL,
priority integer DEFAULT 0,
error_count integer DEFAULT 0,
last_error text,
retry_count integer DEFAULT 0,
started_at timestamp with time zone,
completed_at timestamp with time zone,
updated_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP
);
--
-- Name: command_queue_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.command_queue_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: command_queue_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.command_queue_id_seq OWNED BY public.command_queue.id;
--
-- Name: cuts; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.cuts (
id integer NOT NULL,
file_uuid character varying(32) NOT NULL,
cut_number integer NOT NULL,
start_frame bigint NOT NULL,
end_frame bigint NOT NULL,
start_time double precision,
end_time double precision,
fps double precision,
metadata jsonb DEFAULT '{}'::jsonb,
created_at timestamp with time zone DEFAULT now()
);
--
-- Name: cuts_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.cuts_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: cuts_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.cuts_id_seq OWNED BY public.cuts.id;
--
-- Name: face_clusters; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.face_clusters (
id integer NOT NULL,
cluster_id character varying(255) NOT NULL,
file_uuid character varying(255) CONSTRAINT face_clusters_video_uuid_not_null 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
);
--
-- Name: TABLE face_clusters; Type: COMMENT; Schema: public; Owner: -
--
COMMENT ON TABLE public.face_clusters IS 'Stores face clusters from video analysis';
--
-- Name: face_clusters_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.face_clusters_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: face_clusters_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.face_clusters_id_seq OWNED BY public.face_clusters.id;
--
-- Name: face_detections; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.face_detections (
id integer NOT NULL,
file_uuid character varying(32) NOT NULL,
frame_number integer NOT NULL,
x integer,
y integer,
width integer,
height integer,
confidence real,
embedding real[],
trace_id integer,
created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
timestamp_secs double precision,
stranger_id integer,
cut_id integer,
face_id character varying(50),
identity_id integer,
metadata jsonb DEFAULT '{}'::jsonb
);
--
-- Name: face_detections_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.face_detections_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: face_detections_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.face_detections_id_seq OWNED BY public.face_detections.id;
--
-- Name: face_identities; Type: TABLE; Schema: public; Owner: -
--
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
);
--
-- Name: TABLE face_identities; Type: COMMENT; Schema: public; Owner: -
--
COMMENT ON TABLE public.face_identities IS 'Stores registered face identities with embeddings';
--
-- Name: face_identities_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.face_identities_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: face_identities_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.face_identities_id_seq OWNED BY public.face_identities.id;
--
-- Name: face_recognition_results; Type: TABLE; Schema: public; Owner: -
--
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
);
--
-- Name: TABLE face_recognition_results; Type: COMMENT; Schema: public; Owner: -
--
COMMENT ON TABLE public.face_recognition_results IS 'Stores face recognition processing results';
--
-- Name: face_recognition_results_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.face_recognition_results_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: face_recognition_results_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.face_recognition_results_id_seq OWNED BY public.face_recognition_results.id;
--
-- Name: file_identities; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.file_identities (
id integer NOT NULL,
file_uuid character varying(255) NOT NULL,
identity_id integer NOT NULL,
confidence double precision DEFAULT 1.0,
metadata jsonb,
created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP
);
--
-- Name: file_identities_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.file_identities_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: file_identities_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.file_identities_id_seq OWNED BY public.file_identities.id;
--
-- Name: frames; Type: TABLE; Schema: public; Owner: -
--
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,
yolo_objects jsonb,
ocr_results jsonb,
face_results jsonb,
frame_path text,
created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP
);
--
-- Name: frames_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.frames_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: frames_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.frames_id_seq OWNED BY public.frames.id;
--
-- Name: gitea_tokens; Type: TABLE; Schema: public; Owner: -
--
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
);
--
-- Name: gitea_tokens_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.gitea_tokens_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: gitea_tokens_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.gitea_tokens_id_seq OWNED BY public.gitea_tokens.id;
--
-- Name: identities; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.identities (
id integer NOT NULL,
name text,
embedding public.vector(768),
metadata jsonb DEFAULT '{}'::jsonb,
created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
uuid uuid,
identity_type character varying(20),
source character varying(50),
status character varying(20) DEFAULT 'active'::character varying,
face_embedding public.vector(512),
voice_embedding public.vector(192),
identity_embedding public.vector(768),
reference_data jsonb,
tmdb_id integer,
tmdb_profile text,
tmdb_poster text,
file_uuid text,
updated_at timestamp with time zone DEFAULT now()
);
--
-- Name: identities_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.identities_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: identities_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.identities_id_seq OWNED BY public.identities.id;
--
-- Name: identity_bindings; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.identity_bindings (
id integer NOT NULL,
identity_id integer,
identity_type text NOT NULL,
identity_value text NOT NULL,
confidence double precision DEFAULT 1.0,
metadata jsonb DEFAULT '{}'::jsonb,
created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP
);
--
-- Name: identity_bindings_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.identity_bindings_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: identity_bindings_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.identity_bindings_id_seq OWNED BY public.identity_bindings.id;
--
-- Name: identity_history; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.identity_history (
id bigint NOT NULL,
identity_id integer NOT NULL,
operation character varying(20) NOT NULL,
before_snapshot jsonb,
after_snapshot jsonb,
is_undone boolean DEFAULT false,
undone_at timestamp with time zone,
user_id character varying(100),
user_source character varying(50),
created_at timestamp with time zone DEFAULT now()
);
--
-- Name: identity_history_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.identity_history_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: identity_history_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.identity_history_id_seq OWNED BY public.identity_history.id;
--
-- Name: jobs; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.jobs (
id uuid DEFAULT gen_random_uuid() NOT NULL,
asset_uuid character varying(255) NOT NULL,
rule character varying(100),
status character varying(50) DEFAULT 'QUEUED'::character varying,
assigned_processor_id uuid,
processed_frames bigint DEFAULT 0,
total_frames bigint DEFAULT 0,
created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
updated_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP
);
--
-- Name: jwt_blacklist; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.jwt_blacklist (
id integer NOT NULL,
jti character varying(64) NOT NULL,
reason character varying(20) DEFAULT 'logout'::character varying NOT NULL,
created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
expires_at timestamp with time zone NOT NULL,
CONSTRAINT jwt_blacklist_reason_check CHECK (((reason)::text = ANY (ARRAY[('logout'::character varying)::text, ('revoke'::character varying)::text, ('rotate'::character varying)::text])))
);
--
-- Name: jwt_blacklist_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.jwt_blacklist_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: jwt_blacklist_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.jwt_blacklist_id_seq OWNED BY public.jwt_blacklist.id;
--
-- Name: mac_allocations; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.mac_allocations (
mac_address character varying(17) NOT NULL,
machine_name character varying(100),
license_key character varying(64),
is_active boolean DEFAULT true,
created_at timestamp with time zone DEFAULT now(),
updated_at timestamp with time zone DEFAULT now()
);
--
-- Name: TABLE mac_allocations; Type: COMMENT; Schema: public; Owner: -
--
COMMENT ON TABLE public.mac_allocations IS 'MAC address resource allocation: license binding and machine identification';
--
-- Name: COLUMN mac_allocations.mac_address; Type: COMMENT; Schema: public; Owner: -
--
COMMENT ON COLUMN public.mac_allocations.mac_address IS 'Network interface MAC address (format: a1:b2:c3:d4:e5:f6)';
--
-- Name: COLUMN mac_allocations.machine_name; Type: COMMENT; Schema: public; Owner: -
--
COMMENT ON COLUMN public.mac_allocations.machine_name IS 'Human-readable machine name (e.g., MacBook-Pro)';
--
-- Name: COLUMN mac_allocations.license_key; Type: COMMENT; Schema: public; Owner: -
--
COMMENT ON COLUMN public.mac_allocations.license_key IS 'License key bound to this MAC address';
--
-- Name: COLUMN mac_allocations.is_active; Type: COMMENT; Schema: public; Owner: -
--
COMMENT ON COLUMN public.mac_allocations.is_active IS 'Whether this MAC is currently active';
--
-- Name: monitor_jobs; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.monitor_jobs (
id integer NOT NULL,
uuid character varying(32) 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 with time zone,
created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
video_id bigint,
user_id bigint,
processors text[],
completed_processors text[],
failed_processors text[]
);
--
-- Name: monitor_jobs_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.monitor_jobs_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: monitor_jobs_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.monitor_jobs_id_seq OWNED BY public.monitor_jobs.id;
--
-- Name: n8n_api_keys; Type: TABLE; Schema: public; Owner: -
--
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
);
--
-- Name: n8n_api_keys_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.n8n_api_keys_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: n8n_api_keys_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.n8n_api_keys_id_seq OWNED BY public.n8n_api_keys.id;
--
-- Name: parent_chunks; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.parent_chunks (
id integer NOT NULL,
uuid character varying(32) NOT NULL,
chunk_id character varying(64),
summary_text text,
summary_tsvector tsvector,
metadata jsonb DEFAULT '{}'::jsonb
);
--
-- Name: parent_chunks_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.parent_chunks_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: parent_chunks_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.parent_chunks_id_seq OWNED BY public.parent_chunks.id;
--
-- Name: pre_chunks; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.pre_chunks (
id integer NOT NULL,
file_id integer,
source_type character varying(32),
source_file text,
chunk_type character varying(32),
start_time double precision,
end_time double precision,
start_frame bigint,
end_frame bigint,
fps double precision,
data jsonb,
text_content text,
processed boolean,
chunk_id character varying(64),
created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
file_uuid character varying(32),
processor_type character varying(32) NOT NULL,
coordinate_type character varying(20) DEFAULT 'frame'::character varying,
coordinate_index bigint DEFAULT 0
);
--
-- Name: pre_chunks_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.pre_chunks_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: pre_chunks_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.pre_chunks_id_seq OWNED BY public.pre_chunks.id;
--
-- Name: processor_alerts; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.processor_alerts (
id integer NOT NULL,
file_uuid character varying(32),
processor_type character varying(32) NOT NULL,
alert_type character varying(32) NOT NULL,
message text,
created_at timestamp with time zone DEFAULT now()
);
--
-- Name: processor_alerts_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.processor_alerts_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: processor_alerts_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.processor_alerts_id_seq OWNED BY public.processor_alerts.id;
--
-- Name: processor_results; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.processor_results (
id integer NOT NULL,
job_id integer,
video_id bigint,
processor character varying(20),
status character varying(20) DEFAULT 'pending'::character varying NOT NULL,
output_path text,
started_at timestamp with time zone,
completed_at timestamp with time zone,
error_message text,
progress_total integer DEFAULT 0,
progress_current integer DEFAULT 0,
last_checkpoint jsonb,
created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
updated_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
duration_secs double precision,
chunks_produced integer DEFAULT 0,
frames_processed integer DEFAULT 0,
output_size_bytes bigint DEFAULT 0,
file_uuid character varying(32),
result jsonb,
output_data jsonb,
retry_count integer DEFAULT 0,
processor_type character varying(64),
uuid character varying(255)
);
--
-- Name: processor_results_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.processor_results_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: processor_results_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.processor_results_id_seq OWNED BY public.processor_results.id;
--
-- Name: processor_versions; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.processor_versions (
processor character varying(64) NOT NULL,
model_version character varying(128) NOT NULL,
processor_type character varying(32) DEFAULT 'processor'::character varying NOT NULL,
dependencies text[] DEFAULT '{}'::text[],
updated_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
file_uuid character varying(64)
);
--
-- Name: resources; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.resources (
resource_id character varying(64) NOT NULL,
resource_type character varying(20) NOT NULL,
category character varying(50),
capabilities jsonb DEFAULT '{}'::jsonb,
config jsonb DEFAULT '{}'::jsonb,
metadata jsonb DEFAULT '{}'::jsonb,
status character varying(20) DEFAULT 'offline'::character varying,
last_heartbeat timestamp with time zone,
created_at timestamp with time zone DEFAULT now()
);
--
-- Name: TABLE resources; Type: COMMENT; Schema: public; Owner: -
--
COMMENT ON TABLE public.resources IS 'Registry for Processors, Agents, and Services. Used for monitoring and discovery.';
--
-- Name: scenes; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.scenes (
id bigint NOT NULL,
file_uuid character varying(32) NOT NULL,
scene_index integer NOT NULL,
timestamp_sec double precision NOT NULL,
frame_number bigint NOT NULL,
filename character varying(255) NOT NULL,
selection_reason character varying(50),
quality_score double precision,
quality_source character varying(100),
vlm_status character varying(20) DEFAULT 'pending'::character varying,
vlm_description text,
vlm_scene_type character varying(100),
vlm_location character varying(255),
vlm_objects jsonb DEFAULT '[]'::jsonb,
vlm_tags jsonb DEFAULT '[]'::jsonb,
vlm_attributes jsonb,
face_count integer DEFAULT 0,
person_traces jsonb DEFAULT '[]'::jsonb,
has_cut boolean DEFAULT false,
cut_count integer DEFAULT 0,
scene_info jsonb,
embedding_status character varying(20) DEFAULT 'pending'::character varying,
embedding_point_id character varying(64),
created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
updated_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP
);
--
-- Name: scenes_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.scenes_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: scenes_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.scenes_id_seq OWNED BY public.scenes.id;
--
-- Name: schema_migrations; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.schema_migrations (
id integer NOT NULL,
filename text NOT NULL,
checksum text NOT NULL,
applied_at timestamp with time zone DEFAULT now() NOT NULL,
duration_ms integer DEFAULT 0
);
--
-- Name: schema_migrations_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.schema_migrations_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: schema_migrations_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.schema_migrations_id_seq OWNED BY public.schema_migrations.id;
--
-- Name: sessions; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.sessions (
id integer NOT NULL,
session_id character varying(64) NOT NULL,
user_id integer NOT NULL,
api_key_id character varying(48) NOT NULL,
created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
expires_at timestamp with time zone NOT NULL,
last_accessed_at timestamp with time zone,
ip_address text,
user_agent text,
source text
);
--
-- Name: sessions_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.sessions_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: sessions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.sessions_id_seq OWNED BY public.sessions.id;
--
-- Name: speaker_detections; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.speaker_detections (
id integer NOT NULL,
file_uuid character varying(32) NOT NULL,
identity_id integer,
speaker_id character varying(32),
start_time double precision,
end_time double precision,
text_content text,
chunk_id character varying(128),
confidence real,
metadata jsonb DEFAULT '{}'::jsonb,
created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP
);
--
-- Name: speaker_detections_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.speaker_detections_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: speaker_detections_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.speaker_detections_id_seq OWNED BY public.speaker_detections.id;
--
-- Name: strangers; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.strangers (
id integer NOT NULL,
file_uuid text,
trace_id integer,
metadata jsonb DEFAULT '{}'::jsonb,
created_at timestamp with time zone DEFAULT now()
);
--
-- Name: strangers_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.strangers_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: strangers_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.strangers_id_seq OWNED BY public.strangers.id;
--
-- Name: talents; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.talents (
id bigint CONSTRAINT talents_id_not_null1 NOT NULL,
real_name text CONSTRAINT talents_real_name_not_null1 NOT NULL,
actor_name text,
voice_embedding public.vector(192),
face_embedding public.vector(512),
metadata jsonb DEFAULT '{}'::jsonb,
created_at timestamp with time zone DEFAULT now()
);
--
-- Name: TABLE talents; Type: COMMENT; Schema: public; Owner: -
--
COMMENT ON TABLE public.talents IS '真實人物/演員/配音員資訊庫';
--
-- Name: talents_id_seq1; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.talents_id_seq1
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: talents_id_seq1; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.talents_id_seq1 OWNED BY public.talents.id;
--
-- Name: tkg_edges; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.tkg_edges (
id bigint NOT NULL,
edge_type character varying(64) NOT NULL,
source_node_id bigint NOT NULL,
target_node_id bigint NOT NULL,
file_uuid character varying(64) NOT NULL,
properties jsonb DEFAULT '{}'::jsonb NOT NULL,
created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP
);
--
-- Name: tkg_edges_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.tkg_edges_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: tkg_edges_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.tkg_edges_id_seq OWNED BY public.tkg_edges.id;
--
-- Name: tkg_nodes; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.tkg_nodes (
id bigint NOT NULL,
node_type character varying(64) NOT NULL,
external_id character varying(256) NOT NULL,
file_uuid character varying(64) NOT NULL,
label character varying(512),
properties jsonb DEFAULT '{}'::jsonb NOT NULL,
created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP
);
--
-- Name: tkg_nodes_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.tkg_nodes_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: tkg_nodes_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.tkg_nodes_id_seq OWNED BY public.tkg_nodes.id;
--
-- Name: tkg_operation_log; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.tkg_operation_log (
id bigint NOT NULL,
file_uuid character varying(32) NOT NULL,
operation character varying(20) NOT NULL,
node_type character varying(50),
edge_type character varying(50),
nodes_created integer DEFAULT 0,
nodes_updated integer DEFAULT 0,
nodes_deleted integer DEFAULT 0,
edges_created integer DEFAULT 0,
edges_updated integer DEFAULT 0,
edges_deleted integer DEFAULT 0,
status character varying(20) DEFAULT 'pending'::character varying,
error_message text,
started_at timestamp with time zone DEFAULT now(),
completed_at timestamp with time zone,
properties jsonb
);
--
-- Name: tkg_operation_log_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.tkg_operation_log_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: tkg_operation_log_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.tkg_operation_log_id_seq OWNED BY public.tkg_operation_log.id;
--
-- Name: token_usage_logs; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.token_usage_logs (
id bigint NOT NULL,
request_id character varying(36) NOT NULL,
key_id character varying(48),
service character varying(32) NOT NULL,
model character varying(64),
endpoint character varying(255),
input_tokens integer DEFAULT 0,
output_tokens integer DEFAULT 0,
total_tokens integer DEFAULT 0,
duration_ms integer,
status_code integer DEFAULT 200,
error_message text,
created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP
);
--
-- Name: token_usage_logs_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.token_usage_logs_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: token_usage_logs_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.token_usage_logs_id_seq OWNED BY public.token_usage_logs.id;
--
-- Name: trace_operation_history; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.trace_operation_history (
id bigint NOT NULL,
file_uuid character varying(32) NOT NULL,
operation character varying(30) NOT NULL,
before_snapshot jsonb NOT NULL,
after_snapshot jsonb,
is_undone boolean DEFAULT false,
undone_at timestamp with time zone,
user_id character varying(100),
created_at timestamp with time zone DEFAULT now()
);
--
-- Name: trace_operation_history_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.trace_operation_history_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: trace_operation_history_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.trace_operation_history_id_seq OWNED BY public.trace_operation_history.id;
--
-- Name: trace_profiles; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.trace_profiles (
id integer NOT NULL,
file_uuid character varying(32) NOT NULL,
trace_id integer NOT NULL,
name character varying(255),
start_frame bigint,
end_frame bigint,
frame_count integer,
key_frame character varying(255),
key_face character varying(255),
status character varying(50) DEFAULT 'pending'::character varying,
avg_confidence double precision,
best_confidence double precision,
avg_capture_quality double precision,
best_capture_quality double precision,
avg_bbox jsonb,
best_bbox jsonb,
vlm_description text,
vlm_clothing text,
vlm_tags text[],
vlm_location character varying(255),
vlm_setting character varying(255),
vlm_lighting character varying(100),
vlm_weather character varying(100),
vlm_hand_objects text,
vlm_has_plants boolean,
vlm_has_animals boolean,
vlm_background text,
vlm_bg_tags text[],
vlm_model character varying(64),
vlm_embedding jsonb,
vlm_point_id character varying(32),
metadata jsonb DEFAULT '{}'::jsonb,
created_at timestamp with time zone DEFAULT now(),
updated_at timestamp with time zone DEFAULT now()
);
--
-- Name: trace_profiles_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.trace_profiles_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: trace_profiles_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.trace_profiles_id_seq OWNED BY public.trace_profiles.id;
--
-- Name: users; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.users (
id integer NOT NULL,
username character varying(64) NOT NULL,
password_hash character varying(256) NOT NULL,
role character varying(20) DEFAULT 'user'::character varying NOT NULL,
status character varying(20) DEFAULT 'active'::character varying NOT NULL,
created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
updated_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
last_login timestamp with time zone,
CONSTRAINT users_role_check CHECK (((role)::text = ANY (ARRAY[('admin'::character varying)::text, ('user'::character varying)::text, ('readonly'::character varying)::text]))),
CONSTRAINT users_status_check CHECK (((status)::text = ANY (ARRAY[('active'::character varying)::text, ('disabled'::character varying)::text])))
);
--
-- Name: users_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.users_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: users_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.users_id_seq OWNED BY public.users.id;
--
-- Name: videos; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.videos (
id integer NOT NULL,
file_uuid character varying(32) 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,
registration_time timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
file_type character varying(20),
processing_status jsonb DEFAULT '{}'::jsonb,
birth_registration jsonb,
total_frames bigint DEFAULT 0,
parent_uuid character varying(32),
cut_done boolean DEFAULT false,
scene_done boolean DEFAULT false,
audio_tracks jsonb DEFAULT '[]'::jsonb,
cut_count integer DEFAULT 0,
cut_max_duration double precision DEFAULT 0,
content_hash text,
proxy_path text,
audio_track text,
face_filter jsonb
);
--
-- Name: videos_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.videos_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: videos_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.videos_id_seq OWNED BY public.videos.id;
--
-- Name: api_key_anomalies id; Type: DEFAULT; Schema: public; Owner: -
--
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: -
--
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: -
--
ALTER TABLE ONLY public.api_keys ALTER COLUMN id SET DEFAULT nextval('public.api_keys_id_seq'::regclass);
--
-- Name: billing_periods id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.billing_periods ALTER COLUMN id SET DEFAULT nextval('public.billing_periods_id_seq'::regclass);
--
-- Name: castings id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.castings ALTER COLUMN id SET DEFAULT nextval('public.castings_id_seq'::regclass);
--
-- Name: characters id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.characters ALTER COLUMN id SET DEFAULT nextval('public.characters_id_seq'::regclass);
--
-- Name: chunk id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.chunk ALTER COLUMN id SET DEFAULT nextval('public.chunks_id_seq'::regclass);
--
-- Name: chunk_vectors id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.chunk_vectors ALTER COLUMN id SET DEFAULT nextval('public.chunk_vectors_id_seq'::regclass);
--
-- Name: chunks_rule1 id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.chunks_rule1 ALTER COLUMN id SET DEFAULT nextval('public.chunks_rule1_id_seq'::regclass);
--
-- Name: command_queue id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.command_queue ALTER COLUMN id SET DEFAULT nextval('public.command_queue_id_seq'::regclass);
--
-- Name: cuts id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.cuts ALTER COLUMN id SET DEFAULT nextval('public.cuts_id_seq'::regclass);
--
-- Name: face_clusters id; Type: DEFAULT; Schema: public; Owner: -
--
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: -
--
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: -
--
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: -
--
ALTER TABLE ONLY public.face_recognition_results ALTER COLUMN id SET DEFAULT nextval('public.face_recognition_results_id_seq'::regclass);
--
-- Name: file_identities id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.file_identities ALTER COLUMN id SET DEFAULT nextval('public.file_identities_id_seq'::regclass);
--
-- Name: frames id; Type: DEFAULT; Schema: public; Owner: -
--
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: -
--
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: -
--
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: -
--
ALTER TABLE ONLY public.identity_bindings ALTER COLUMN id SET DEFAULT nextval('public.identity_bindings_id_seq'::regclass);
--
-- Name: identity_history id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.identity_history ALTER COLUMN id SET DEFAULT nextval('public.identity_history_id_seq'::regclass);
--
-- Name: jwt_blacklist id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.jwt_blacklist ALTER COLUMN id SET DEFAULT nextval('public.jwt_blacklist_id_seq'::regclass);
--
-- Name: monitor_jobs id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.monitor_jobs ALTER COLUMN id SET DEFAULT nextval('public.monitor_jobs_id_seq'::regclass);
--
-- Name: n8n_api_keys id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.n8n_api_keys ALTER COLUMN id SET DEFAULT nextval('public.n8n_api_keys_id_seq'::regclass);
--
-- Name: parent_chunks id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.parent_chunks ALTER COLUMN id SET DEFAULT nextval('public.parent_chunks_id_seq'::regclass);
--
-- Name: pre_chunks id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.pre_chunks ALTER COLUMN id SET DEFAULT nextval('public.pre_chunks_id_seq'::regclass);
--
-- Name: processor_alerts id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.processor_alerts ALTER COLUMN id SET DEFAULT nextval('public.processor_alerts_id_seq'::regclass);
--
-- Name: processor_results id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.processor_results ALTER COLUMN id SET DEFAULT nextval('public.processor_results_id_seq'::regclass);
--
-- Name: scenes id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.scenes ALTER COLUMN id SET DEFAULT nextval('public.scenes_id_seq'::regclass);
--
-- Name: schema_migrations id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.schema_migrations ALTER COLUMN id SET DEFAULT nextval('public.schema_migrations_id_seq'::regclass);
--
-- Name: sessions id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.sessions ALTER COLUMN id SET DEFAULT nextval('public.sessions_id_seq'::regclass);
--
-- Name: speaker_detections id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.speaker_detections ALTER COLUMN id SET DEFAULT nextval('public.speaker_detections_id_seq'::regclass);
--
-- Name: strangers id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.strangers ALTER COLUMN id SET DEFAULT nextval('public.strangers_id_seq'::regclass);
--
-- Name: talents id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.talents ALTER COLUMN id SET DEFAULT nextval('public.talents_id_seq1'::regclass);
--
-- Name: tkg_edges id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.tkg_edges ALTER COLUMN id SET DEFAULT nextval('public.tkg_edges_id_seq'::regclass);
--
-- Name: tkg_nodes id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.tkg_nodes ALTER COLUMN id SET DEFAULT nextval('public.tkg_nodes_id_seq'::regclass);
--
-- Name: tkg_operation_log id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.tkg_operation_log ALTER COLUMN id SET DEFAULT nextval('public.tkg_operation_log_id_seq'::regclass);
--
-- Name: token_usage_logs id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.token_usage_logs ALTER COLUMN id SET DEFAULT nextval('public.token_usage_logs_id_seq'::regclass);
--
-- Name: trace_operation_history id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.trace_operation_history ALTER COLUMN id SET DEFAULT nextval('public.trace_operation_history_id_seq'::regclass);
--
-- Name: trace_profiles id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.trace_profiles ALTER COLUMN id SET DEFAULT nextval('public.trace_profiles_id_seq'::regclass);
--
-- Name: users id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.users ALTER COLUMN id SET DEFAULT nextval('public.users_id_seq'::regclass);
--
-- Name: videos id; Type: DEFAULT; Schema: public; Owner: -
--
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: -
--
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: -
--
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: -
--
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: -
--
ALTER TABLE ONLY public.api_keys
ADD CONSTRAINT api_keys_pkey PRIMARY KEY (id);
--
-- Name: billing_periods billing_periods_key_id_period_month_key; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.billing_periods
ADD CONSTRAINT billing_periods_key_id_period_month_key UNIQUE (key_id, period_month);
--
-- Name: billing_periods billing_periods_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.billing_periods
ADD CONSTRAINT billing_periods_pkey PRIMARY KEY (id);
--
-- Name: castings castings_character_id_talent_id_track_type_key; Type: CONSTRAINT; Schema: public; Owner: -
--
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: -
--
ALTER TABLE ONLY public.castings
ADD CONSTRAINT castings_pkey PRIMARY KEY (id);
--
-- Name: characters characters_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
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: -
--
ALTER TABLE ONLY public.characters
ADD CONSTRAINT characters_video_uuid_name_language_track_key UNIQUE (video_uuid, name, language_track);
--
-- Name: chunks_rule1 chunks_rule1_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.chunks_rule1
ADD CONSTRAINT chunks_rule1_pkey PRIMARY KEY (id);
--
-- Name: command_queue command_queue_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.command_queue
ADD CONSTRAINT command_queue_pkey PRIMARY KEY (id);
--
-- Name: face_clusters face_clusters_cluster_id_key; Type: CONSTRAINT; Schema: public; Owner: -
--
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: -
--
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: -
--
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: -
--
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: -
--
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: -
--
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: -
--
ALTER TABLE ONLY public.face_recognition_results
ADD CONSTRAINT face_recognition_results_video_uuid_key UNIQUE (video_uuid);
--
-- Name: file_identities file_identities_file_uuid_identity_id_key; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.file_identities
ADD CONSTRAINT file_identities_file_uuid_identity_id_key UNIQUE (file_uuid, identity_id);
--
-- Name: file_identities file_identities_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.file_identities
ADD CONSTRAINT file_identities_pkey PRIMARY KEY (id);
--
-- Name: gitea_tokens gitea_tokens_gitea_user_token_name_key; Type: CONSTRAINT; Schema: public; Owner: -
--
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: -
--
ALTER TABLE ONLY public.gitea_tokens
ADD CONSTRAINT gitea_tokens_pkey PRIMARY KEY (id);
--
-- Name: identities identities_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.identities
ADD CONSTRAINT identities_pkey PRIMARY KEY (id);
--
-- Name: identity_bindings identity_bindings_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.identity_bindings
ADD CONSTRAINT identity_bindings_pkey PRIMARY KEY (id);
--
-- Name: identity_history identity_history_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.identity_history
ADD CONSTRAINT identity_history_pkey PRIMARY KEY (id);
--
-- Name: jobs jobs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.jobs
ADD CONSTRAINT jobs_pkey PRIMARY KEY (id);
--
-- Name: jwt_blacklist jwt_blacklist_jti_key; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.jwt_blacklist
ADD CONSTRAINT jwt_blacklist_jti_key UNIQUE (jti);
--
-- Name: jwt_blacklist jwt_blacklist_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.jwt_blacklist
ADD CONSTRAINT jwt_blacklist_pkey PRIMARY KEY (id);
--
-- Name: mac_allocations mac_allocations_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.mac_allocations
ADD CONSTRAINT mac_allocations_pkey PRIMARY KEY (mac_address);
--
-- Name: n8n_api_keys n8n_api_keys_n8n_key_id_key; Type: CONSTRAINT; Schema: public; Owner: -
--
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: -
--
ALTER TABLE ONLY public.n8n_api_keys
ADD CONSTRAINT n8n_api_keys_pkey PRIMARY KEY (id);
--
-- Name: processor_alerts processor_alerts_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.processor_alerts
ADD CONSTRAINT processor_alerts_pkey PRIMARY KEY (id);
--
-- Name: resources resources_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.resources
ADD CONSTRAINT resources_pkey PRIMARY KEY (resource_id);
--
-- Name: scenes scenes_file_uuid_scene_index_key; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.scenes
ADD CONSTRAINT scenes_file_uuid_scene_index_key UNIQUE (file_uuid, scene_index);
--
-- Name: scenes scenes_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.scenes
ADD CONSTRAINT scenes_pkey PRIMARY KEY (id);
--
-- Name: schema_migrations schema_migrations_filename_key; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.schema_migrations
ADD CONSTRAINT schema_migrations_filename_key UNIQUE (filename);
--
-- Name: schema_migrations schema_migrations_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.schema_migrations
ADD CONSTRAINT schema_migrations_pkey PRIMARY KEY (id);
--
-- Name: sessions sessions_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.sessions
ADD CONSTRAINT sessions_pkey PRIMARY KEY (id);
--
-- Name: sessions sessions_session_id_key; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.sessions
ADD CONSTRAINT sessions_session_id_key UNIQUE (session_id);
--
-- Name: speaker_detections speaker_detections_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.speaker_detections
ADD CONSTRAINT speaker_detections_pkey PRIMARY KEY (id);
--
-- Name: strangers strangers_file_uuid_trace_id_key; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.strangers
ADD CONSTRAINT strangers_file_uuid_trace_id_key UNIQUE (file_uuid, trace_id);
--
-- Name: strangers strangers_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.strangers
ADD CONSTRAINT strangers_pkey PRIMARY KEY (id);
--
-- Name: talents talents_pkey1; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.talents
ADD CONSTRAINT talents_pkey1 PRIMARY KEY (id);
--
-- Name: talents talents_real_name_key1; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.talents
ADD CONSTRAINT talents_real_name_key1 UNIQUE (real_name);
--
-- Name: tkg_operation_log tkg_operation_log_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.tkg_operation_log
ADD CONSTRAINT tkg_operation_log_pkey PRIMARY KEY (id);
--
-- Name: token_usage_logs token_usage_logs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.token_usage_logs
ADD CONSTRAINT token_usage_logs_pkey PRIMARY KEY (id);
--
-- Name: trace_operation_history trace_operation_history_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.trace_operation_history
ADD CONSTRAINT trace_operation_history_pkey PRIMARY KEY (id);
--
-- Name: trace_profiles trace_profiles_file_uuid_trace_id_key; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.trace_profiles
ADD CONSTRAINT trace_profiles_file_uuid_trace_id_key UNIQUE (file_uuid, trace_id);
--
-- Name: trace_profiles trace_profiles_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.trace_profiles
ADD CONSTRAINT trace_profiles_pkey PRIMARY KEY (id);
--
-- Name: users users_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.users
ADD CONSTRAINT users_pkey PRIMARY KEY (id);
--
-- Name: users users_username_key; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.users
ADD CONSTRAINT users_username_key UNIQUE (username);
--
-- Name: idx_alerts_file_uuid; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_alerts_file_uuid ON public.processor_alerts USING btree (file_uuid);
--
-- Name: idx_alerts_processor_type; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_alerts_processor_type ON public.processor_alerts USING btree (processor_type);
--
-- Name: idx_anomalies_created_at; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_anomalies_created_at ON public.api_key_anomalies USING btree (created_at);
--
-- Name: idx_anomalies_key_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_anomalies_key_id ON public.api_key_anomalies USING btree (key_id);
--
-- Name: idx_anomalies_resolved; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_anomalies_resolved ON public.api_key_anomalies USING btree (resolved);
--
-- Name: idx_anomalies_severity; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_anomalies_severity ON public.api_key_anomalies USING btree (severity);
--
-- Name: idx_api_keys_hash; Type: INDEX; Schema: public; Owner: -
--
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: -
--
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: -
--
CREATE INDEX idx_api_keys_status ON public.api_keys USING btree (status);
--
-- Name: idx_api_keys_type; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_api_keys_type ON public.api_keys USING btree (key_type);
--
-- Name: idx_api_keys_user_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_api_keys_user_id ON public.api_keys USING btree (user_id);
--
-- Name: idx_audit_action; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_audit_action ON public.api_key_audit_log USING btree (action);
--
-- Name: idx_audit_created_at; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_audit_created_at ON public.api_key_audit_log USING btree (created_at);
--
-- Name: idx_audit_ip; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_audit_ip ON public.api_key_audit_log USING btree (ip_address);
--
-- Name: idx_audit_key_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_audit_key_id ON public.api_key_audit_log USING btree (key_id);
--
-- Name: idx_billing_periods_key; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_billing_periods_key ON public.billing_periods USING btree (key_id);
--
-- Name: idx_billing_periods_month; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_billing_periods_month ON public.billing_periods USING btree (period_month);
--
-- Name: idx_chunk_file; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_chunk_file ON public.chunk USING btree (file_uuid);
--
-- Name: idx_chunk_file_old_id; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX idx_chunk_file_old_id ON public.chunk USING btree (file_uuid, old_chunk_id) WHERE (old_chunk_id IS NOT NULL);
--
-- Name: idx_chunk_file_type; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_chunk_file_type ON public.chunk USING btree (file_uuid, chunk_type);
--
-- Name: idx_chunk_file_uuid; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_chunk_file_uuid ON public.chunk USING btree (file_uuid);
--
-- Name: idx_chunk_parent; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_chunk_parent ON public.chunk USING btree (parent_chunk_id);
--
-- Name: idx_chunk_type; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_chunk_type ON public.chunk USING btree (chunk_type);
--
-- Name: idx_chunk_vec_chunk; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_chunk_vec_chunk ON public.chunk_vectors USING btree (chunk_id);
--
-- Name: idx_chunk_vec_uuid; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_chunk_vec_uuid ON public.chunk_vectors USING btree (uuid);
--
-- Name: idx_chunks_rule1_uuid; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_chunks_rule1_uuid ON public.chunks_rule1 USING btree (uuid);
--
-- Name: idx_chunks_type; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_chunks_type ON public.chunk USING btree (chunk_type);
--
-- Name: idx_command_queue_command_id; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX idx_command_queue_command_id ON public.command_queue USING btree (command_id);
--
-- Name: idx_command_queue_status_created; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_command_queue_status_created ON public.command_queue USING btree (status, created_at);
--
-- Name: idx_cuts_file_uuid; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_cuts_file_uuid ON public.cuts USING btree (file_uuid);
--
-- Name: idx_face_clusters_file; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_face_clusters_file ON public.face_clusters USING btree (file_uuid);
--
-- Name: idx_face_clusters_file_uuid; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_face_clusters_file_uuid ON public.face_clusters USING btree (file_uuid);
--
-- Name: idx_face_detections_face_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_face_detections_face_id ON public.face_detections USING btree (face_id);
--
-- Name: idx_face_detections_file; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_face_detections_file ON public.face_detections USING btree (file_uuid);
--
-- Name: idx_face_detections_file_uuid; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_face_detections_file_uuid ON public.face_detections USING btree (file_uuid);
--
-- Name: idx_face_detections_frame; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_face_detections_frame ON public.face_detections USING btree (frame_number);
--
-- Name: idx_face_detections_identity; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_face_detections_identity ON public.face_detections USING btree (identity_id);
--
-- Name: idx_face_detections_stranger; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_face_detections_stranger ON public.face_detections USING btree (file_uuid, stranger_id) WHERE (stranger_id IS NOT NULL);
--
-- Name: idx_face_detections_trace; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_face_detections_trace ON public.face_detections USING btree (trace_id);
--
-- Name: idx_face_detections_trace_time; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_face_detections_trace_time ON public.face_detections USING btree (file_uuid, trace_id) WHERE (trace_id IS NOT NULL);
--
-- Name: idx_face_identities_embedding; Type: INDEX; Schema: public; Owner: -
--
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: -
--
CREATE INDEX idx_face_recognition_results_created_at ON public.face_recognition_results USING btree (created_at);
--
-- Name: idx_file_identities_file; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_file_identities_file ON public.file_identities USING btree (file_uuid);
--
-- Name: idx_file_identities_identity; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_file_identities_identity ON public.file_identities USING btree (identity_id);
--
-- Name: idx_frames_file_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_frames_file_id ON public.frames USING btree (file_id);
--
-- Name: idx_identities_name; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_identities_name ON public.identities USING btree (name);
--
-- Name: idx_identities_source; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_identities_source ON public.identities USING btree (source);
--
-- Name: idx_identities_tmdb_id; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX idx_identities_tmdb_id ON public.identities USING btree (tmdb_id) WHERE (tmdb_id IS NOT NULL);
--
-- Name: idx_identities_uuid; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_identities_uuid ON public.identities USING btree (uuid);
--
-- Name: idx_identity_bindings_identity; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_identity_bindings_identity ON public.identity_bindings USING btree (identity_id);
--
-- Name: idx_identity_history_identity_time; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_identity_history_identity_time ON public.identity_history USING btree (identity_id, created_at DESC);
--
-- Name: idx_identity_history_not_undone; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_identity_history_not_undone ON public.identity_history USING btree (identity_id, created_at DESC) WHERE (NOT is_undone);
--
-- Name: idx_jobs_asset; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_jobs_asset ON public.jobs USING btree (asset_uuid);
--
-- Name: idx_jobs_status; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_jobs_status ON public.jobs USING btree (status);
--
-- Name: idx_jwt_blacklist_expires; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_jwt_blacklist_expires ON public.jwt_blacklist USING btree (expires_at);
--
-- Name: idx_jwt_blacklist_jti; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_jwt_blacklist_jti ON public.jwt_blacklist USING btree (jti);
--
-- Name: idx_mac_allocations_active; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_mac_allocations_active ON public.mac_allocations USING btree (is_active);
--
-- Name: idx_mac_allocations_license; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_mac_allocations_license ON public.mac_allocations USING btree (license_key);
--
-- Name: idx_monitor_jobs_status; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_monitor_jobs_status ON public.monitor_jobs USING btree (status);
--
-- Name: idx_monitor_jobs_uuid; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX idx_monitor_jobs_uuid ON public.monitor_jobs USING btree (uuid);
--
-- Name: idx_parent_chunks_uuid; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_parent_chunks_uuid ON public.parent_chunks USING btree (uuid);
--
-- Name: idx_pr_job_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_pr_job_id ON public.processor_results USING btree (job_id);
--
-- Name: idx_pr_job_processor_type; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX idx_pr_job_processor_type ON public.processor_results USING btree (job_id, processor_type);
--
-- Name: idx_pr_uuid; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_pr_uuid ON public.processor_results USING btree (uuid);
--
-- Name: idx_pre_chunks_file_uuid; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_pre_chunks_file_uuid ON public.pre_chunks USING btree (file_uuid);
--
-- Name: idx_pre_chunks_processor; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_pre_chunks_processor ON public.pre_chunks USING btree (processor_type);
--
-- Name: idx_public_pre_chunks_file; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_public_pre_chunks_file ON public.pre_chunks USING btree (file_uuid);
--
-- Name: idx_public_pre_chunks_proc; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_public_pre_chunks_proc ON public.pre_chunks USING btree (processor_type);
--
-- Name: idx_resources_status; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_resources_status ON public.resources USING btree (status);
--
-- Name: idx_resources_type; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_resources_type ON public.resources USING btree (resource_type);
--
-- Name: idx_scenes_file_uuid; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_scenes_file_uuid ON public.scenes USING btree (file_uuid);
--
-- Name: idx_scenes_objects; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_scenes_objects ON public.scenes USING gin (vlm_objects);
--
-- Name: idx_scenes_tags; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_scenes_tags ON public.scenes USING gin (vlm_tags);
--
-- Name: idx_scenes_timestamp; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_scenes_timestamp ON public.scenes USING btree (timestamp_sec);
--
-- Name: idx_sessions_expires; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_sessions_expires ON public.sessions USING btree (expires_at);
--
-- Name: idx_sessions_session_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_sessions_session_id ON public.sessions USING btree (session_id);
--
-- Name: idx_sessions_user_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_sessions_user_id ON public.sessions USING btree (user_id);
--
-- Name: idx_speaker_detections_chunk; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_speaker_detections_chunk ON public.speaker_detections USING btree (chunk_id);
--
-- Name: idx_speaker_detections_file; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_speaker_detections_file ON public.speaker_detections USING btree (file_uuid);
--
-- Name: idx_speaker_detections_identity; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_speaker_detections_identity ON public.speaker_detections USING btree (identity_id);
--
-- Name: idx_speaker_detections_search; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_speaker_detections_search ON public.speaker_detections USING btree (file_uuid, identity_id);
--
-- Name: idx_talent_face; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_talent_face ON public.talents USING hnsw (face_embedding public.vector_cosine_ops);
--
-- Name: idx_tkg_edges_file; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_tkg_edges_file ON public.tkg_edges USING btree (file_uuid);
--
-- Name: idx_tkg_edges_file_uuid; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_tkg_edges_file_uuid ON public.tkg_edges USING btree (file_uuid);
--
-- Name: idx_tkg_edges_source; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_tkg_edges_source ON public.tkg_edges USING btree (source_node_id);
--
-- Name: idx_tkg_edges_type; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_tkg_edges_type ON public.tkg_edges USING btree (edge_type);
--
-- Name: idx_tkg_nodes_external; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_tkg_nodes_external ON public.tkg_nodes USING btree (external_id);
--
-- Name: idx_tkg_nodes_file; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_tkg_nodes_file ON public.tkg_nodes USING btree (file_uuid);
--
-- Name: idx_tkg_nodes_file_uuid; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_tkg_nodes_file_uuid ON public.tkg_nodes USING btree (file_uuid);
--
-- Name: idx_tkg_nodes_type; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_tkg_nodes_type ON public.tkg_nodes USING btree (node_type);
--
-- Name: idx_tkg_op_file_uuid; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_tkg_op_file_uuid ON public.tkg_operation_log USING btree (file_uuid);
--
-- Name: idx_token_usage_created; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_token_usage_created ON public.token_usage_logs USING btree (created_at);
--
-- Name: idx_token_usage_key_date; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_token_usage_key_date ON public.token_usage_logs USING btree (key_id, created_at);
--
-- Name: idx_token_usage_request; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_token_usage_request ON public.token_usage_logs USING btree (request_id);
--
-- Name: idx_token_usage_service; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_token_usage_service ON public.token_usage_logs USING btree (service, created_at);
--
-- Name: idx_trace_op_history_file_time; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_trace_op_history_file_time ON public.trace_operation_history USING btree (file_uuid, created_at DESC);
--
-- Name: idx_trace_op_history_not_undone; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_trace_op_history_not_undone ON public.trace_operation_history USING btree (file_uuid, created_at DESC) WHERE (NOT is_undone);
--
-- Name: idx_trace_profiles_file_uuid; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_trace_profiles_file_uuid ON public.trace_profiles USING btree (file_uuid);
--
-- Name: idx_trace_profiles_name; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_trace_profiles_name ON public.trace_profiles USING btree (name);
--
-- Name: idx_trace_profiles_tags; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_trace_profiles_tags ON public.trace_profiles USING gin (vlm_tags);
--
-- Name: idx_users_status; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_users_status ON public.users USING btree (status);
--
-- Name: idx_users_username; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_users_username ON public.users USING btree (username);
--
-- Name: idx_videos_content_hash; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_videos_content_hash ON public.videos USING btree (content_hash) WHERE (content_hash IS NOT NULL);
--
-- Name: idx_videos_file_uuid; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX idx_videos_file_uuid ON public.videos USING btree (file_uuid);
--
-- Name: chunk chunks_search_vector_trigger; Type: TRIGGER; Schema: public; Owner: -
--
CREATE TRIGGER chunks_search_vector_trigger BEFORE INSERT OR UPDATE ON public.chunk FOR EACH ROW EXECUTE FUNCTION public.update_search_vector();
--
-- Name: mac_allocations trigger_mac_allocations_updated_at; Type: TRIGGER; Schema: public; Owner: -
--
CREATE TRIGGER trigger_mac_allocations_updated_at BEFORE UPDATE ON public.mac_allocations FOR EACH ROW EXECUTE FUNCTION public.update_mac_allocations_updated_at();
--
-- Name: face_identities update_face_identities_updated_at; Type: TRIGGER; Schema: public; Owner: -
--
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: -
--
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: castings castings_character_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.castings
ADD CONSTRAINT castings_character_id_fkey FOREIGN KEY (character_id) REFERENCES public.characters(id) ON DELETE CASCADE;
--
-- Name: identity_bindings identity_bindings_identity_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.identity_bindings
ADD CONSTRAINT identity_bindings_identity_id_fkey FOREIGN KEY (identity_id) REFERENCES public.identities(id) ON DELETE CASCADE;
--
-- Name: sessions sessions_api_key_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.sessions
ADD CONSTRAINT sessions_api_key_id_fkey FOREIGN KEY (api_key_id) REFERENCES public.api_keys(key_id) ON DELETE CASCADE;
--
-- Name: sessions sessions_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.sessions
ADD CONSTRAINT sessions_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;
--
-- Name: speaker_detections speaker_detections_identity_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.speaker_detections
ADD CONSTRAINT speaker_detections_identity_id_fkey FOREIGN KEY (identity_id) REFERENCES public.identities(id) ON DELETE CASCADE;
--
--
\unrestrict 69eeeC6OaRWFr7t5EhEOrDvyYCPR5Wpp3pGRA4hWMP2BS0dfesj1Fv1fqpMYNEW
-- ============================================================
-- 補丁:videos 表缺少的 4 個欄位
-- 來源: migrations/039_add_missing_video_columns.sql
-- 正式 DB 尚未套用,worker 需要 videos.face_settings 才能啟動
-- ============================================================
ALTER TABLE public.videos ADD COLUMN IF NOT EXISTS face_settings jsonb;
ALTER TABLE public.videos ADD COLUMN IF NOT EXISTS asr_status varchar(20) DEFAULT 'pending';
ALTER TABLE public.videos ADD COLUMN IF NOT EXISTS completed_at timestamptz;
ALTER TABLE public.videos ADD COLUMN IF NOT EXISTS vlm_description_localized jsonb DEFAULT '{}'::jsonb;
CREATE INDEX IF NOT EXISTS idx_videos_asr_status ON public.videos(asr_status) WHERE asr_status IS NOT NULL;
CREATE INDEX IF NOT EXISTS idx_videos_completed_at ON public.videos(completed_at) WHERE completed_at IS NOT NULL;
INSERT INTO public.schema_version (version, description) VALUES (1, 'baseline from prod momentry public schema') ON CONFLICT (version) DO NOTHING;
-- ============================================================
-- 補丁 2:monitor_jobs.face_settings
-- 來源: migrations/040_add_monitor_jobs_face_settings.sql
-- 正式 DB 尚未套用,Worker 初始化需要此欄位
-- ============================================================
ALTER TABLE public.monitor_jobs ADD COLUMN IF NOT EXISTS face_settings jsonb;
COMMENT ON COLUMN public.monitor_jobs.face_settings IS 'Face detection settings (min_confidence, min_size)';
INSERT INTO public.schema_version (version, description) VALUES (2, 'add monitor_jobs.face_settings') ON CONFLICT (version) DO NOTHING;