-- dolphin_violet DDL — consolidated from the LIVE dolphin_pink schema
-- (post-ALTER: includes maras_tp + provenance columns). Generated 2026-06-12.
-- Apply via apply_violet_ddl.py (one statement per HTTP POST).

CREATE TABLE IF NOT EXISTS dolphin_violet.anomaly_events
(
    `ts` DateTime64(6, 'UTC'),
    `ts_day` Date MATERIALIZED toDate(ts),
    `decision_id` String,
    `trade_id` String,
    `symbol` LowCardinality(String),
    `anomaly` LowCardinality(String),
    `origin` LowCardinality(String),
    `sensor` LowCardinality(String) DEFAULT '',
    `detail` String DEFAULT '',
    `rm_meta` Float32 DEFAULT 0
)
ENGINE = MergeTree
PARTITION BY toYYYYMM(ts)
ORDER BY (ts_day, trade_id, anomaly, ts)
TTL ts_day + toIntervalDay(180)
SETTINGS index_granularity = 8192;
