CREATE DATABASE IF NOT EXISTS ory;

CREATE TABLE IF NOT EXISTS ory.oathkeeper_access_logs (
  timestamp DateTime64(3) DEFAULT now64(3),
  request_id String DEFAULT '',
  method String DEFAULT '',
  path String DEFAULT '',
  status UInt16 DEFAULT 0,
  latency_ms UInt32 DEFAULT 0,
  rp String DEFAULT '',
  action String DEFAULT '',
  target String DEFAULT '',
  subject String DEFAULT '',
  client_ip String DEFAULT '',
  user_agent String DEFAULT '',
  decision String DEFAULT '',
  trace_id String DEFAULT '',
  span_id String DEFAULT '',
  raw String DEFAULT ''
) ENGINE = MergeTree()
ORDER BY (timestamp, request_id)
TTL timestamp + INTERVAL 30 DAY;
