-- Migration 009: Knowledge entities (FTS search for documentation)
-- Creates the knowledge_entities table for Phase 3 search/knowledge endpoints.

CREATE TABLE IF NOT EXISTS knowledge_entities (
    entity_id   UUID PRIMARY KEY REFERENCES entities(id),
    title       TEXT NOT NULL,
    content     TEXT NOT NULL,
    source      TEXT,
    tags        TEXT[],
    created_at  TIMESTAMPTZ NOT NULL DEFAULT now(),
    updated_at  TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE INDEX idx_knowledge_title ON knowledge_entities USING gin(to_tsvector('english', title));
CREATE INDEX idx_knowledge_content ON knowledge_entities USING gin(to_tsvector('english', content));