Files
gongxue-base/supabase/migrations/202607120014_audit_log_capacity_indexes.sql
2026-07-12 19:26:57 +08:00

34 lines
1.4 KiB
SQL

create index if not exists idx_audit_logs_created
on public.audit_logs (created_at desc, id desc);
create index if not exists idx_audit_logs_tenant_created
on public.audit_logs (tenant_id, created_at desc, id desc)
where tenant_id is not null;
create index if not exists idx_audit_logs_tenant_actor_created
on public.audit_logs (tenant_id, actor_user_id, created_at desc, id desc)
where tenant_id is not null and actor_user_id is not null;
create index if not exists idx_audit_logs_tenant_target_created
on public.audit_logs (tenant_id, target_type, created_at desc, id desc)
where tenant_id is not null and target_type is not null;
create index if not exists idx_audit_logs_platform_created
on public.audit_logs (created_at, id)
where action like 'platform.%';
comment on index public.idx_audit_logs_created is
'Supports the bounded newest-first platform audit list and exports.';
comment on index public.idx_audit_logs_tenant_created is
'Supports newest-first tenant audit history without scanning other tenants.';
comment on index public.idx_audit_logs_tenant_actor_created is
'Supports tenant audit history filtered by actor.';
comment on index public.idx_audit_logs_tenant_target_created is
'Supports tenant audit history filtered by target type.';
comment on index public.idx_audit_logs_platform_created is
'Supports incremental platform audit alert scans over recent platform events.';