package index import "fmt" // CreateDatabaseSQL creates the index database if absent. func CreateDatabaseSQL(database string) string { return fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s", database) } // CreateTableSQL returns the DDL for the archive index table. One row is written // per archived S3 object. In-cluster the argocd bootstrap Job owns table // creation (like the logging stack's clickhouse-schema PostSync hook); this DDL // is also shipped as schema/archive_index.sql and applied by `logarchiver // init-schema`. // // PARTITION BY month of min_ts keeps partitions coarse (few objects/day). // ORDER BY (subject, min_ts) matches the primary search axes. A bloom_filter // skip index on hosts accelerates host lookups without a per-host column. func CreateTableSQL(database, table string) string { return fmt.Sprintf(`CREATE TABLE IF NOT EXISTS %s.%s ( object_key String, bucket LowCardinality(String), subject LowCardinality(String), hosts Array(LowCardinality(String)), min_ts DateTime64(3), max_ts DateTime64(3), event_count UInt64, raw_bytes UInt64, stored_bytes UInt64, compression LowCardinality(String), cipher LowCardinality(String), container_format LowCardinality(String), key_name LowCardinality(String), key_fingerprint String, created_at DateTime64(3) DEFAULT now64(3), INDEX idx_hosts hosts TYPE bloom_filter GRANULARITY 1 ) ENGINE = MergeTree PARTITION BY toYYYYMM(min_ts) ORDER BY (subject, min_ts, object_key)`, database, table) }