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
| Column | Type | Nullable | Default | Description |
|---|---|---|---|---|
id | uuid | No | gen_random_uuid() | Primary key |
admin_id | uuid | No | -- | Admin who performed the action |
action | text | No | -- | Action identifier (e.g., 'resolve_report') |
target_type | text | Yes | -- | Type of target (user, post, report, etc.) |
target_id | uuid | Yes | -- | ID of the target entity |
details | jsonb | No | '{}' | Additional action details |
created_at | timestamptz | No | NOW() | 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);
Related
- admin_roles -- Admin who performed the action
- reports -- Reports that triggered actions
Last updated: 2026-02-07