-- Money Raise Knowledge Base
-- Run: docker exec <ch-container> clickhouse-client < schema.sql

CREATE DATABASE IF NOT EXISTS money_raise;

CREATE TABLE IF NOT EXISTS money_raise.knowledge_base
(
    id          UUID    DEFAULT generateUUIDv4(),
    category    LowCardinality(String),      -- template|standard|protocol|roadmap|investor|legal|metric|region
    subcategory LowCardinality(String),
    region      LowCardinality(String),      -- global|us|eu|dach|uk|ro|mena|apac
    stage       LowCardinality(String),      -- pre_seed|seed|series_a|series_b|growth|all
    title       String,
    content     String,
    format      LowCardinality(String),      -- markdown|checklist|json|template
    tags        Array(String),
    source      String,
    language    LowCardinality(String),      -- en|ro|de
    created_at  DateTime DEFAULT now()
)
ENGINE = MergeTree()
ORDER BY (category, subcategory, region, created_at)
PARTITION BY category
SETTINGS index_granularity = 8192;

-- Full-text search index
ALTER TABLE money_raise.knowledge_base
    ADD INDEX idx_content content TYPE tokenbf_v1(32768, 3, 0) GRANULARITY 1;
