Skip to main content

avatar_library

Overview

The avatar_library table stores a collection of avatar images for each user. Users can upload multiple avatars (up to 24) and select one as their active avatar. This supports expressive identity within the HomeRoom context.

Schema

-- From 20260130_avatar_library.sql
CREATE TABLE avatar_library (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_id UUID NOT NULL REFERENCES auth.users(id) ON DELETE CASCADE,
image_url TEXT NOT NULL,
label TEXT,
is_active BOOLEAN DEFAULT FALSE,
created_at TIMESTAMPTZ DEFAULT NOW(),
CONSTRAINT max_avatars CHECK (true)
);

-- Trigger enforces max 24 avatars per user

Columns

ColumnTypeNullableDefaultDescription
iduuidNogen_random_uuid()Primary key
user_iduuidNo--Avatar owner
image_urltextNo--URL to avatar image
labeltextYes--Optional label/name for the avatar
is_activebooleanNoFALSEWhether this is the currently active avatar
created_attimestamptzNoNOW()Upload timestamp

RLS Policies

-- SELECT: Anyone can view avatars (needed for profile display)
CREATE POLICY "Avatars are publicly viewable"
ON avatar_library FOR SELECT
USING (true);

-- INSERT/UPDATE/DELETE: Users manage their own avatars
CREATE POLICY "Users can manage own avatars"
ON avatar_library FOR ALL
USING (auth.uid() = user_id);
  • profiles -- Avatar owner, active avatar reflected in avatar_url

Last updated: 2026-02-07