Skip to main content

admin_audit_log

Overview

The admin_audit_log table records every administrative action taken on the platform. This provides a complete audit trail for accountability and review. All admin operations (resolving reports, changing user status, granting roles) are logged here.

Schema

-- From 20260202_admin_system.sql
CREATE TABLE admin_audit_log (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
admin_id UUID NOT NULL REFERENCES auth.users(id),
action TEXT NOT NULL,
target_type TEXT,
target_id UUID,
details JSONB DEFAULT '{}',
created_at TIMESTAMPTZ DEFAULT NOW()
);

Columns

ColumnTypeNullableDefaultDescription
iduuidNogen_random_uuid()Primary key
admin_iduuidNo--Admin who performed the action
actiontextNo--Action identifier (e.g., 'resolve_report')
target_typetextYes--Type of target (user, post, report, etc.)
target_iduuidYes--ID of the target entity
detailsjsonbNo'{}'Additional action details
created_attimestamptzNoNOW()When action was performed

RLS Policies

-- SELECT: Only admins can view the audit log
CREATE POLICY "Admins can view audit log"
ON admin_audit_log FOR SELECT
USING (EXISTS (SELECT 1 FROM admin_roles WHERE admin_roles.user_id = auth.uid()));

-- INSERT: System and admins can write audit entries
CREATE POLICY "Admins can write audit entries"
ON admin_audit_log FOR INSERT
WITH CHECK (auth.uid() = admin_id);

Last updated: 2026-02-07