ALTER TABLE gateway_request_log
ADD COLUMN IF NOT EXISTS duration_ms bigint,
ADD COLUMN IF NOT EXISTS cache_lookup_outcome text,
ADD COLUMN IF NOT EXISTS cache_source text,
ADD COLUMN IF NOT EXISTS operation text,
ADD COLUMN IF NOT EXISTS table_name text;

ALTER TABLE gateway_operation_log
ADD COLUMN IF NOT EXISTS cache_lookup_outcome text,
ADD COLUMN IF NOT EXISTS cache_source text,
ADD COLUMN IF NOT EXISTS cached boolean;

ALTER TABLE client_statistics
ADD COLUMN IF NOT EXISTS avg_request_duration_ms double precision,
ADD COLUMN IF NOT EXISTS p50_request_duration_ms double precision,
ADD COLUMN IF NOT EXISTS p95_request_duration_ms double precision,
ADD COLUMN IF NOT EXISTS p99_request_duration_ms double precision,
ADD COLUMN IF NOT EXISTS cache_hit_ratio double precision;

ALTER TABLE client_table_statistics
ADD COLUMN IF NOT EXISTS avg_duration_ms double precision,
ADD COLUMN IF NOT EXISTS p50_duration_ms double precision,
ADD COLUMN IF NOT EXISTS p95_duration_ms double precision,
ADD COLUMN IF NOT EXISTS p99_duration_ms double precision,
ADD COLUMN IF NOT EXISTS total_cache_hits bigint NOT NULL DEFAULT 0,
ADD COLUMN IF NOT EXISTS total_cache_misses bigint NOT NULL DEFAULT 0,
ADD COLUMN IF NOT EXISTS cache_hit_ratio double precision;