

--
-- Name: vector; Type: EXTENSION; Schema: -; Owner: -
--

CREATE EXTENSION IF NOT EXISTS vector WITH SCHEMA public;


--
-- Name: EXTENSION vector; Type: COMMENT; Schema: -; Owner: 
--

COMMENT ON EXTENSION vector IS 'vector data type and ivfflat and hnsw access methods';




--
-- Name: active_queue_sessions; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.active_queue_sessions (
    last_updated timestamp with time zone DEFAULT now() NOT NULL,
    id text NOT NULL,
    work_unit_key text NOT NULL
);


ALTER TABLE public.active_queue_sessions OWNER TO postgres;

--
-- Name: alembic_version; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.alembic_version (
    version_num character varying(32) NOT NULL
);


ALTER TABLE public.alembic_version OWNER TO postgres;

--
-- Name: collections; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.collections (
    id text NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    metadata jsonb DEFAULT '{}'::jsonb NOT NULL,
    workspace_name text NOT NULL,
    internal_metadata jsonb DEFAULT '{}'::jsonb NOT NULL,
    observer text NOT NULL,
    observed text NOT NULL,
    CONSTRAINT ck_collections_id_format CHECK ((id ~ '^[A-Za-z0-9_-]+$'::text)),
    CONSTRAINT ck_collections_id_length CHECK ((length(id) = 21)),
    CONSTRAINT ck_collections_public_id_format CHECK ((id ~ '^[A-Za-z0-9_-]+$'::text)),
    CONSTRAINT ck_collections_public_id_length CHECK ((length(id) = 21))
);


ALTER TABLE public.collections OWNER TO postgres;

--
-- Name: documents; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.documents (
    id text NOT NULL,
    internal_metadata jsonb DEFAULT '{}'::jsonb NOT NULL,
    content text NOT NULL,
    embedding public.vector(1536),
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    workspace_name text NOT NULL,
    session_name text,
    observer text NOT NULL,
    observed text NOT NULL,
    level text DEFAULT 'explicit'::text NOT NULL,
    times_derived integer DEFAULT 1 NOT NULL,
    source_ids jsonb,
    deleted_at timestamp with time zone,
    sync_state text DEFAULT 'pending'::text NOT NULL,
    last_sync_at timestamp with time zone,
    sync_attempts integer DEFAULT 0 NOT NULL,
    CONSTRAINT ck_documents_content_length CHECK ((length(content) <= 65535)),
    CONSTRAINT ck_documents_id_format CHECK ((id ~ '^[A-Za-z0-9_-]+$'::text)),
    CONSTRAINT ck_documents_id_length CHECK ((length(id) = 21)),
    CONSTRAINT ck_documents_public_id_format CHECK ((id ~ '^[A-Za-z0-9_-]+$'::text)),
    CONSTRAINT ck_documents_public_id_length CHECK ((length(id) = 21))
);


ALTER TABLE public.documents OWNER TO postgres;

--
-- Name: message_embeddings; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.message_embeddings (
    id bigint NOT NULL,
    content text NOT NULL,
    embedding public.vector(1536),
    message_id text NOT NULL,
    workspace_name text NOT NULL,
    session_name text NOT NULL,
    peer_name text NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    sync_state text DEFAULT 'pending'::text NOT NULL,
    last_sync_at timestamp with time zone,
    sync_attempts integer DEFAULT 0 NOT NULL
);


ALTER TABLE public.message_embeddings OWNER TO postgres;

--
-- Name: message_embeddings_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

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


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

CREATE TABLE public.messages (
    id bigint NOT NULL,
    public_id text NOT NULL,
    content text NOT NULL,
    metadata jsonb DEFAULT '{}'::jsonb NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    peer_name text NOT NULL,
    workspace_name text NOT NULL,
    session_name text NOT NULL,
    token_count integer DEFAULT 0 NOT NULL,
    internal_metadata jsonb DEFAULT '{}'::jsonb NOT NULL,
    seq_in_session bigint NOT NULL,
    CONSTRAINT ck_messages_content_length CHECK ((length(content) <= 65535)),
    CONSTRAINT ck_messages_public_id_format CHECK ((public_id ~ '^[A-Za-z0-9_-]+$'::text)),
    CONSTRAINT ck_messages_public_id_length CHECK ((length(public_id) = 21))
);


ALTER TABLE public.messages OWNER TO postgres;

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

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


--
-- Name: peers; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.peers (
    id text NOT NULL,
    name text NOT NULL,
    metadata jsonb DEFAULT '{}'::jsonb NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    configuration jsonb DEFAULT '{}'::jsonb NOT NULL,
    internal_metadata jsonb DEFAULT '{}'::jsonb NOT NULL,
    workspace_name text NOT NULL,
    CONSTRAINT ck_peers_id_format CHECK ((id ~ '^[A-Za-z0-9_-]+$'::text)),
    CONSTRAINT ck_peers_id_length CHECK ((length(id) = 21)),
    CONSTRAINT ck_users_name_length CHECK ((length(name) <= 512)),
    CONSTRAINT ck_users_public_id_format CHECK ((id ~ '^[A-Za-z0-9_-]+$'::text)),
    CONSTRAINT ck_users_public_id_length CHECK ((length(id) = 21))
);


ALTER TABLE public.peers OWNER TO postgres;


--
-- Name: session_peers; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.session_peers (
    workspace_name text NOT NULL,
    session_name text NOT NULL,
    peer_name text NOT NULL,
    configuration jsonb DEFAULT '{}'::jsonb NOT NULL,
    internal_metadata jsonb DEFAULT '{}'::jsonb NOT NULL,
    joined_at timestamp with time zone DEFAULT now() NOT NULL,
    left_at timestamp with time zone
);


ALTER TABLE public.session_peers OWNER TO postgres;

--
-- Name: sessions; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.sessions (
    id text NOT NULL,
    is_active boolean DEFAULT true NOT NULL,
    metadata jsonb DEFAULT '{}'::jsonb NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    configuration jsonb DEFAULT '{}'::jsonb NOT NULL,
    internal_metadata jsonb DEFAULT '{}'::jsonb NOT NULL,
    workspace_name text NOT NULL,
    name text NOT NULL,
    CONSTRAINT ck_sessions_id_format CHECK ((id ~ '^[A-Za-z0-9_-]+$'::text)),
    CONSTRAINT ck_sessions_id_length CHECK ((length(id) = 21)),
    CONSTRAINT ck_sessions_name_length CHECK ((length(name) <= 512)),
    CONSTRAINT ck_sessions_public_id_format CHECK ((id ~ '^[A-Za-z0-9_-]+$'::text)),
    CONSTRAINT ck_sessions_public_id_length CHECK ((length(id) = 21))
);


ALTER TABLE public.sessions OWNER TO postgres;

--
-- Name: webhook_endpoints; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.webhook_endpoints (
    id text NOT NULL,
    workspace_name text NOT NULL,
    url text NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    CONSTRAINT ck_webhook_endpoints_webhook_endpoint_url_length CHECK ((length(url) <= 2048))
);


ALTER TABLE public.webhook_endpoints OWNER TO postgres;

--
-- Name: workspaces; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.workspaces (
    id text NOT NULL,
    name text NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    metadata jsonb DEFAULT '{}'::jsonb NOT NULL,
    configuration jsonb DEFAULT '{}'::jsonb NOT NULL,
    internal_metadata jsonb DEFAULT '{}'::jsonb NOT NULL,
    CONSTRAINT ck_apps_name_length CHECK ((length(name) <= 512)),
    CONSTRAINT ck_apps_public_id_format CHECK ((id ~ '^[A-Za-z0-9_-]+$'::text)),
    CONSTRAINT ck_apps_public_id_length CHECK ((length(id) = 21)),
    CONSTRAINT ck_workspaces_id_format CHECK ((id ~ '^[A-Za-z0-9_-]+$'::text)),
    CONSTRAINT ck_workspaces_id_length CHECK ((length(id) = 21))
);


ALTER TABLE public.workspaces OWNER TO postgres;

--
-- Data for Name: active_queue_sessions; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.active_queue_sessions (last_updated, id, work_unit_key) FROM stdin;
\.


--
-- Data for Name: alembic_version; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.alembic_version (version_num) FROM stdin;
e4eba9cfaa6f
\.


--
-- Data for Name: collections; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.collections (id, created_at, metadata, workspace_name, internal_metadata, observer, observed) FROM stdin;
\.


--
-- Data for Name: documents; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.documents (id, internal_metadata, content, embedding, created_at, workspace_name, session_name, observer, observed, level, times_derived, source_ids, deleted_at, sync_state, last_sync_at, sync_attempts) FROM stdin;
\.


--
-- Data for Name: message_embeddings; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.message_embeddings (id, content, embedding, message_id, workspace_name, session_name, peer_name, created_at, sync_state, last_sync_at, sync_attempts) FROM stdin;
\.


--
-- Data for Name: messages; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.messages (id, public_id, content, metadata, created_at, peer_name, workspace_name, session_name, token_count, internal_metadata, seq_in_session) FROM stdin;
1	VNC7pbf68rmFSiVJuF_Qr	Ahmed Zeyd Aytac lives in Wien (Vienna), Austria. He calls his AI assistant Kiwi.	{}	2026-05-21 08:49:48.704881+00	ahmed-zeyd-aytac	hermes-ahmed	knowledge-bootstrap	22	{}	1
2	GPmp-bPDdNaXzQCpeWf2l	Ahmed prefers to be addressed as Boss or Chef. Never call him Ahmed. If using his name, use Zeyd only.	{}	2026-05-21 08:49:48.704881+00	ahmed-zeyd-aytac	hermes-ahmed	knowledge-bootstrap	25	{}	2
3	G_-XaQxWZgLjOeM2myr-p	Ahmed prefers responses without any header or separator lines. Clean, direct messages only.	{}	2026-05-21 08:49:48.704881+00	ahmed-zeyd-aytac	hermes-ahmed	knowledge-bootstrap	16	{}	3
4	5bBcUghnjSXlbFg3evnl0	Ahmed wants YOLO mode permanently on - never ask for command approval, just execute. Does not override reboot/shutdown blocklist.	{}	2026-05-21 08:49:48.704881+00	ahmed-zeyd-aytac	hermes-ahmed	knowledge-bootstrap	26	{}	4
5	loysaDx9jJlya4rha23dM	Ahmed does not want end-of-session skill reviews. When he says Stop saving he means stop immediately.	{}	2026-05-21 08:49:48.704881+00	ahmed-zeyd-aytac	hermes-ahmed	knowledge-bootstrap	20	{}	5
6	FOLV64NLosfKqvdiuIMMg	Ahmed uses a ZimaOS server (ZimaCube) as his main infrastructure. It runs Docker containers and AI workloads.	{}	2026-05-21 08:49:48.704881+00	ahmed-zeyd-aytac	hermes-ahmed	knowledge-bootstrap	25	{}	6
7	QVi-n-1Bd58axp1MvIpKq	Ahmed has self-hosted services: PrintVault on port 3001, DocMaster on port 3000, Immich, Plex, Audiobookshelf, Kiwi Browser.	{}	2026-05-21 08:49:48.704881+00	ahmed-zeyd-aytac	hermes-ahmed	knowledge-bootstrap	35	{}	7
8	I2JcUwFejlnsttclquMrT	Ahmed built PrintVault - a document management system at /media/HDD_1TB/PrintVault/.	{}	2026-05-21 08:49:48.704881+00	ahmed-zeyd-aytac	hermes-ahmed	knowledge-bootstrap	21	{}	8
9	k25SnvH9eY6-2nlKpkZNK	Ahmed uses Ollama Cloud Pro for 20 dollars per month, not local Ollama. Base URL is https://ollama.com/v1.	{}	2026-05-21 08:49:48.704881+00	ahmed-zeyd-aytac	hermes-ahmed	knowledge-bootstrap	29	{}	9
10	3z5lyhcLY1AbBFhhyXoc5	Model setup: deepseek-v4-pro for main chat, kimi-k2.6 for auxiliary and coding, gemma3 colon 4b for vision. 3 concurrent model limit.	{}	2026-05-21 08:49:48.704881+00	ahmed-zeyd-aytac	hermes-ahmed	knowledge-bootstrap	38	{}	10
11	_K6p3mSNbL1p92rtGwAzT	Ahmed uses Honcho for conversational memory, self-hosted on his ZimaOS server with PostgreSQL and Redis.	{}	2026-05-21 08:49:48.704881+00	ahmed-zeyd-aytac	hermes-ahmed	knowledge-bootstrap	23	{}	11
12	eMS8hgrizzQoA7O9N600r	Ahmed does 3D printing and CAD design. Uses headless trimesh plus manifold3d pipeline. CadQuery fails due to missing libGL.	{}	2026-05-21 08:49:48.704881+00	ahmed-zeyd-aytac	hermes-ahmed	knowledge-bootstrap	30	{}	12
13	QtZvn4qD4qacEi1Fx3yG0	Ahmed prefers concise technical CAD reports: STL path, dimensions, volume, PNG preview, watertight status only. No print recommendations.	{}	2026-05-21 08:49:48.704881+00	ahmed-zeyd-aytac	hermes-ahmed	knowledge-bootstrap	27	{}	13
14	R7qtasDxQ--AQ6r66iNs6	CAD output directory: /DATA/AppData/hermes/projects/3d/. Uses np.ptp instead of arr.ptp for trimesh vertex arrays.	{}	2026-05-21 08:49:48.704881+00	ahmed-zeyd-aytac	hermes-ahmed	knowledge-bootstrap	30	{}	14
15	wt7n1LqrKFWEbbyy_pZPu	Ahmed actively iterates on code and skill design. He prefers code he can tweak himself.	{}	2026-05-21 08:49:48.704881+00	ahmed-zeyd-aytac	hermes-ahmed	knowledge-bootstrap	18	{}	15
16	1FVANTDKvtVOwD_0Ss0Eu	Projects stored in /DATA/AppData/hermes/projects/ and /DATA/AppData/hermes/work/.	{}	2026-05-21 08:49:48.704881+00	ahmed-zeyd-aytac	hermes-ahmed	knowledge-bootstrap	20	{}	16
17	8SrXCU2kCSIPDo_3C4oqy	When reviewing files, Ahmed prefers top-level overview files first - not full detailed breakdowns.	{}	2026-05-21 08:49:48.704881+00	ahmed-zeyd-aytac	hermes-ahmed	knowledge-bootstrap	18	{}	17
18	vObNqKYEih75ohbVd2MHZ	Email: ahmed.aytac at gmail dot com. Google Workspace OAuth configured with all scopes granted.	{}	2026-05-21 08:49:48.704881+00	ahmed-zeyd-aytac	hermes-ahmed	knowledge-bootstrap	22	{}	18
19	qQX06N52TY9HyNlcLr58I	Kiwis avatar is a wizard kiwi bird: green wizard hat with gold star, round spectacles, emerald staff, SCHEDULE book, kiwi emblem on cloak.	{}	2026-05-21 08:49:48.704881+00	ahmed-zeyd-aytac	hermes-ahmed	knowledge-bootstrap	32	{}	19
20	6UigI4Td0a7llZ0fq0hEE	Ahmeds assistant Kiwi created the wizard kiwi avatar with his help on ZimaOS.	{}	2026-05-21 08:49:48.704881+00	ahmed-zeyd-aytac	hermes-ahmed	knowledge-bootstrap	17	{}	20
\.


--
-- Data for Name: peers; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.peers (id, name, metadata, created_at, configuration, internal_metadata, workspace_name) FROM stdin;
puEeKdYHRhci1RFJuaCd6	ahmed-zeyd-aytac	{}	2026-05-21 08:48:58.021462+00	{}	{}	hermes-ahmed
\.


--
-- Data for Name: session_peers; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.session_peers (workspace_name, session_name, peer_name, configuration, internal_metadata, joined_at, left_at) FROM stdin;
hermes-ahmed	knowledge-bootstrap	ahmed-zeyd-aytac	{"observe_me": null, "observe_others": null}	{}	2026-05-21 08:49:48.697089+00	\N
\.


--
-- Data for Name: sessions; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.sessions (id, is_active, metadata, created_at, configuration, internal_metadata, workspace_name, name) FROM stdin;
QHyp8tyUUGUEO6JXAP3oL	t	{}	2026-05-21 08:48:58.286247+00	{}	{}	hermes-ahmed	knowledge-bootstrap
\.


--
-- Data for Name: webhook_endpoints; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.webhook_endpoints (id, workspace_name, url, created_at) FROM stdin;
\.


--
-- Data for Name: workspaces; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.workspaces (id, name, created_at, metadata, configuration, internal_metadata) FROM stdin;
7drS_Z3w8xUm73eWOFN0n	hermes-test	2026-05-21 08:44:56.892589+00	{}	{}	{}
5Cc9Datm9-9EWvilCFs9c	hermes-ahmed	2026-05-21 08:48:40.829337+00	{}	{}	{}
\.



--
-- Name: alembic_version alembic_version_pkc; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.alembic_version
    ADD CONSTRAINT alembic_version_pkc PRIMARY KEY (version_num);


--
-- Name: active_queue_sessions pk_active_queue_sessions; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.active_queue_sessions
    ADD CONSTRAINT pk_active_queue_sessions PRIMARY KEY (id);


--
-- Name: collections pk_collections; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.collections
    ADD CONSTRAINT pk_collections PRIMARY KEY (id);


--
-- Name: documents pk_documents; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.documents
    ADD CONSTRAINT pk_documents PRIMARY KEY (id);


--
-- Name: message_embeddings pk_message_embeddings; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.message_embeddings
    ADD CONSTRAINT pk_message_embeddings PRIMARY KEY (id);


--
-- Name: messages pk_messages; Type: CONSTRAINT; Schema: public; Owner: postgres
--

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


--
-- Name: peers pk_peers; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.peers
    ADD CONSTRAINT pk_peers PRIMARY KEY (id);


--
-- Name: session_peers pk_session_peers; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.session_peers
    ADD CONSTRAINT pk_session_peers PRIMARY KEY (workspace_name, session_name, peer_name);


--
-- Name: sessions pk_sessions; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.sessions
    ADD CONSTRAINT pk_sessions PRIMARY KEY (id);


--
-- Name: webhook_endpoints pk_webhook_endpoints; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.webhook_endpoints
    ADD CONSTRAINT pk_webhook_endpoints PRIMARY KEY (id);


--
-- Name: workspaces pk_workspaces; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.workspaces
    ADD CONSTRAINT pk_workspaces PRIMARY KEY (id);


--
-- Name: active_queue_sessions uq_active_queue_sessions_work_unit_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.active_queue_sessions
    ADD CONSTRAINT uq_active_queue_sessions_work_unit_key UNIQUE (work_unit_key);


--
-- Name: collections uq_collections_observer_observed_workspace_name; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.collections
    ADD CONSTRAINT uq_collections_observer_observed_workspace_name UNIQUE (observer, observed, workspace_name);


--
-- Name: messages uq_messages_public_id; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.messages
    ADD CONSTRAINT uq_messages_public_id UNIQUE (public_id);


--
-- Name: messages uq_messages_workspace_name_session_name_seq_in_session; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.messages
    ADD CONSTRAINT uq_messages_workspace_name_session_name_seq_in_session UNIQUE (workspace_name, session_name, seq_in_session);


--
-- Name: peers uq_peers_name_workspace_name; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.peers
    ADD CONSTRAINT uq_peers_name_workspace_name UNIQUE (name, workspace_name);


--
-- Name: sessions uq_sessions_name_workspace_name; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.sessions
    ADD CONSTRAINT uq_sessions_name_workspace_name UNIQUE (name, workspace_name);


--
-- Name: workspaces uq_workspaces_name; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.workspaces
    ADD CONSTRAINT uq_workspaces_name UNIQUE (name);


--
-- Name: ix_collections_created_at; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX ix_collections_created_at ON public.collections USING btree (created_at);


--
-- Name: ix_collections_observed; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX ix_collections_observed ON public.collections USING btree (observed);


--
-- Name: ix_collections_observer; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX ix_collections_observer ON public.collections USING btree (observer);


--
-- Name: ix_collections_workspace_name; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX ix_collections_workspace_name ON public.collections USING btree (workspace_name);


--
-- Name: ix_documents_created_at; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX ix_documents_created_at ON public.documents USING btree (created_at);


--
-- Name: ix_documents_deleted_at; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX ix_documents_deleted_at ON public.documents USING btree (deleted_at) WHERE (deleted_at IS NOT NULL);


--
-- Name: ix_documents_embedding_hnsw; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX ix_documents_embedding_hnsw ON public.documents USING hnsw (embedding public.vector_cosine_ops) WITH (m='16', ef_construction='64');


--
-- Name: ix_documents_observed; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX ix_documents_observed ON public.documents USING btree (observed);


--
-- Name: ix_documents_observer; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX ix_documents_observer ON public.documents USING btree (observer);


--
-- Name: ix_documents_session_name; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX ix_documents_session_name ON public.documents USING btree (session_name);


--
-- Name: ix_documents_source_ids_gin; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX ix_documents_source_ids_gin ON public.documents USING gin (source_ids);


--
-- Name: ix_documents_sync_state; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX ix_documents_sync_state ON public.documents USING btree (sync_state);


--
-- Name: ix_documents_sync_state_last_sync_at; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX ix_documents_sync_state_last_sync_at ON public.documents USING btree (sync_state, last_sync_at);


--
-- Name: ix_documents_workspace_name; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX ix_documents_workspace_name ON public.documents USING btree (workspace_name);


--
-- Name: ix_message_embeddings_created_at; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX ix_message_embeddings_created_at ON public.message_embeddings USING btree (created_at);


--
-- Name: ix_message_embeddings_embedding_hnsw; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX ix_message_embeddings_embedding_hnsw ON public.message_embeddings USING hnsw (embedding public.vector_cosine_ops) WITH (m='16', ef_construction='64');


--
-- Name: ix_message_embeddings_message_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX ix_message_embeddings_message_id ON public.message_embeddings USING btree (message_id);


--
-- Name: ix_message_embeddings_peer_name; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX ix_message_embeddings_peer_name ON public.message_embeddings USING btree (peer_name);


--
-- Name: ix_message_embeddings_session_name; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX ix_message_embeddings_session_name ON public.message_embeddings USING btree (session_name);


--
-- Name: ix_message_embeddings_sync_state; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX ix_message_embeddings_sync_state ON public.message_embeddings USING btree (sync_state);


--
-- Name: ix_message_embeddings_sync_state_last_sync_at; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX ix_message_embeddings_sync_state_last_sync_at ON public.message_embeddings USING btree (sync_state, last_sync_at);


--
-- Name: ix_message_embeddings_workspace_name; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX ix_message_embeddings_workspace_name ON public.message_embeddings USING btree (workspace_name);


--
-- Name: ix_messages_content_gin; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX ix_messages_content_gin ON public.messages USING gin (to_tsvector('english'::regconfig, content));


--
-- Name: ix_messages_created_at; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX ix_messages_created_at ON public.messages USING btree (created_at);


--
-- Name: ix_messages_peer_name; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX ix_messages_peer_name ON public.messages USING btree (peer_name);


--
-- Name: ix_messages_session_lookup; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX ix_messages_session_lookup ON public.messages USING btree (session_name, id) INCLUDE (id, created_at);


--
-- Name: ix_messages_workspace_name; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX ix_messages_workspace_name ON public.messages USING btree (workspace_name);


--
-- Name: ix_peers_created_at; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX ix_peers_created_at ON public.peers USING btree (created_at);


--
-- Name: ix_peers_workspace_name; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX ix_peers_workspace_name ON public.peers USING btree (workspace_name);


--
-- Name: ix_sessions_created_at; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX ix_sessions_created_at ON public.sessions USING btree (created_at);


--
-- Name: ix_sessions_workspace_name; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX ix_sessions_workspace_name ON public.sessions USING btree (workspace_name);


--
-- Name: ix_webhook_endpoints_workspace_name; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX ix_webhook_endpoints_workspace_name ON public.webhook_endpoints USING btree (workspace_name);


--
-- Name: ix_workspaces_created_at; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX ix_workspaces_created_at ON public.workspaces USING btree (created_at);


--
-- Name: collections fk_collections_observed_workspace_name_peers; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.collections
    ADD CONSTRAINT fk_collections_observed_workspace_name_peers FOREIGN KEY (observed, workspace_name) REFERENCES public.peers(name, workspace_name);


--
-- Name: collections fk_collections_observer_workspace_name_peers; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.collections
    ADD CONSTRAINT fk_collections_observer_workspace_name_peers FOREIGN KEY (observer, workspace_name) REFERENCES public.peers(name, workspace_name);


--
-- Name: collections fk_collections_workspace_name_workspaces; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.collections
    ADD CONSTRAINT fk_collections_workspace_name_workspaces FOREIGN KEY (workspace_name) REFERENCES public.workspaces(name);


--
-- Name: documents fk_documents_observed_workspace_name_peers; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.documents
    ADD CONSTRAINT fk_documents_observed_workspace_name_peers FOREIGN KEY (observed, workspace_name) REFERENCES public.peers(name, workspace_name);


--
-- Name: documents fk_documents_observer_observed_workspace_name_collections; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.documents
    ADD CONSTRAINT fk_documents_observer_observed_workspace_name_collections FOREIGN KEY (observer, observed, workspace_name) REFERENCES public.collections(observer, observed, workspace_name);


--
-- Name: documents fk_documents_observer_workspace_name_peers; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.documents
    ADD CONSTRAINT fk_documents_observer_workspace_name_peers FOREIGN KEY (observer, workspace_name) REFERENCES public.peers(name, workspace_name);


--
-- Name: documents fk_documents_session_workspace; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.documents
    ADD CONSTRAINT fk_documents_session_workspace FOREIGN KEY (session_name, workspace_name) REFERENCES public.sessions(name, workspace_name);


--
-- Name: documents fk_documents_workspace_name_workspaces; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.documents
    ADD CONSTRAINT fk_documents_workspace_name_workspaces FOREIGN KEY (workspace_name) REFERENCES public.workspaces(name);


--
-- Name: message_embeddings fk_message_embeddings_message_id_messages; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.message_embeddings
    ADD CONSTRAINT fk_message_embeddings_message_id_messages FOREIGN KEY (message_id) REFERENCES public.messages(public_id) ON DELETE CASCADE;


--
-- Name: message_embeddings fk_message_embeddings_peer_name_workspace_name_peers; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.message_embeddings
    ADD CONSTRAINT fk_message_embeddings_peer_name_workspace_name_peers FOREIGN KEY (peer_name, workspace_name) REFERENCES public.peers(name, workspace_name);


--
-- Name: message_embeddings fk_message_embeddings_session_name_workspace_name_sessions; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.message_embeddings
    ADD CONSTRAINT fk_message_embeddings_session_name_workspace_name_sessions FOREIGN KEY (session_name, workspace_name) REFERENCES public.sessions(name, workspace_name);


--
-- Name: message_embeddings fk_message_embeddings_workspace_name_workspaces; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.message_embeddings
    ADD CONSTRAINT fk_message_embeddings_workspace_name_workspaces FOREIGN KEY (workspace_name) REFERENCES public.workspaces(name);


--
-- Name: messages fk_messages_peer_name_peers; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.messages
    ADD CONSTRAINT fk_messages_peer_name_peers FOREIGN KEY (peer_name, workspace_name) REFERENCES public.peers(name, workspace_name);


--
-- Name: messages fk_messages_session_name_sessions; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.messages
    ADD CONSTRAINT fk_messages_session_name_sessions FOREIGN KEY (session_name, workspace_name) REFERENCES public.sessions(name, workspace_name);


--
-- Name: peers fk_peers_workspace_name_workspaces; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.peers
    ADD CONSTRAINT fk_peers_workspace_name_workspaces FOREIGN KEY (workspace_name) REFERENCES public.workspaces(name);


--
-- Name: session_peers fk_session_peers_peer_name_workspace_name_peers; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.session_peers
    ADD CONSTRAINT fk_session_peers_peer_name_workspace_name_peers FOREIGN KEY (peer_name, workspace_name) REFERENCES public.peers(name, workspace_name);


--
-- Name: session_peers fk_session_peers_session_name_workspace_name_sessions; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.session_peers
    ADD CONSTRAINT fk_session_peers_session_name_workspace_name_sessions FOREIGN KEY (session_name, workspace_name) REFERENCES public.sessions(name, workspace_name);


--
-- Name: session_peers fk_session_peers_workspace_name; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.session_peers
    ADD CONSTRAINT fk_session_peers_workspace_name FOREIGN KEY (workspace_name) REFERENCES public.workspaces(name);


--
-- Name: sessions fk_sessions_workspace_name_workspaces; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.sessions
    ADD CONSTRAINT fk_sessions_workspace_name_workspaces FOREIGN KEY (workspace_name) REFERENCES public.workspaces(name);


--
-- Name: webhook_endpoints fk_webhook_endpoints_workspace_name_workspaces; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.webhook_endpoints
    ADD CONSTRAINT fk_webhook_endpoints_workspace_name_workspaces FOREIGN KEY (workspace_name) REFERENCES public.workspaces(name);


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

GRANT ALL ON SCHEMA public TO postgres;