CREATE TABLE IF NOT EXISTS agent_events (
    tenant_id   LowCardinality(String) DEFAULT 'default',
    timestamp   DateTime64(3) DEFAULT now64(3),
    instance_id    LowCardinality(String),
    application_id LowCardinality(String),
    event_type  LowCardinality(String),
    detail      String DEFAULT ''
)
ENGINE = MergeTree()
PARTITION BY (tenant_id, toYYYYMM(timestamp))
ORDER BY (tenant_id, application_id, instance_id, timestamp)
TTL toDateTime(timestamp) + INTERVAL 365 DAY DELETE;
