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
| Column | Type | Nullable | Default | Description |
|---|---|---|---|---|
id | uuid | No | gen_random_uuid() | Primary key |
user_id | uuid | No | -- | Avatar owner |
image_url | text | No | -- | URL to avatar image |
label | text | Yes | -- | Optional label/name for the avatar |
is_active | boolean | No | FALSE | Whether this is the currently active avatar |
created_at | timestamptz | No | NOW() | 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);
Related
- profiles -- Avatar owner, active avatar reflected in avatar_url
Last updated: 2026-02-07