create index if not exists idx_asset_access_events_tenant_created
  on public.content_asset_access_events(tenant_id, created_at desc);

create index if not exists idx_asset_access_events_watermark_trace
  on public.content_asset_access_events(tenant_id, (upper(metadata #>> '{watermark,traceId}')), created_at desc)
  where metadata #>> '{watermark,traceId}' is not null;

create index if not exists idx_video_play_events_tenant_created
  on public.video_play_events(tenant_id, created_at desc);

create index if not exists idx_video_play_events_mode_status
  on public.video_play_events(tenant_id, access_mode, status, created_at desc);

create index if not exists idx_video_play_events_watermark_trace
  on public.video_play_events(tenant_id, (upper(metadata #>> '{watermark,traceId}')), created_at desc)
  where metadata #>> '{watermark,traceId}' is not null;
