admin_roles
Overview
The admin_roles table assigns administrative roles to users. Roles include 'admin' (full access) and 'moderator' (limited moderation access). This table gates access to the admin panel and moderation functions.
Schema
-- From 20260202_admin_system.sql
CREATE TABLE admin_roles (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_id UUID NOT NULL REFERENCES auth.users(id) ON DELETE CASCADE UNIQUE,
role TEXT NOT NULL CHECK (role IN ('admin', 'moderator')),
granted_by UUID REFERENCES auth.users(id),
granted_at TIMESTAMPTZ DEFAULT NOW()
);
Columns
| Column | Type | Nullable | Default | Description |
|---|---|---|---|---|
id | uuid | No | gen_random_uuid() | Primary key |
user_id | uuid | No | -- | User with admin role (unique) |
role | text | No | -- | Role: admin or moderator |
granted_by | uuid | Yes | -- | Admin who granted this role |
granted_at | timestamptz | No | NOW() | When role was granted |
RLS Policies
-- SELECT: Admins can view all admin roles
CREATE POLICY "Admins can view admin roles"
ON admin_roles FOR SELECT
USING (EXISTS (
SELECT 1 FROM admin_roles ar WHERE ar.user_id = auth.uid()
));
Related
- reports -- Reports handled by admins
- admin_audit_log -- Audit trail of admin actions
- profiles -- Admin user
Last updated: 2026-02-07