-- Migration: 00018_add_admin_flag
-- Description: Add is_admin boolean to users table for moderation access
-- Author: Auto-generated
-- Date: 2025-12-22

-- ============================================
-- ADD ADMIN FLAG TO USERS
-- ============================================
-- Simple boolean flag to mark admin/moderator users.
-- Admin access is enforced via Edge Functions (service_role only).

ALTER TABLE users
ADD COLUMN is_admin BOOLEAN DEFAULT FALSE;

-- Index for quick admin lookups
CREATE INDEX idx_users_is_admin ON users(is_admin)
  WHERE is_admin = TRUE;

-- ============================================
-- COMMENTS
-- ============================================
COMMENT ON COLUMN users.is_admin IS 'Whether user has admin/moderator privileges';

-- ============================================
-- RLS NOTE
-- ============================================
-- The is_admin field is protected from user modification via the
-- existing RLS policies that only allow users to update their own
-- profile. Edge Functions with service_role can set this field.
-- Users cannot read other users is_admin status (RLS enforced).

