Skip to main content

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

ColumnTypeNullableDefaultDescription
iduuidNogen_random_uuid()Primary key
user_iduuidNo--User with admin role (unique)
roletextNo--Role: admin or moderator
granted_byuuidYes--Admin who granted this role
granted_attimestamptzNoNOW()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()
));

Last updated: 2026-02-07