Skip to main content

shelves

Overview

Shelves are user-created folders for organizing saved posts. Each shelf has a name and a position for custom ordering. Shelves are entirely private to the user.

Schema

-- Pre-existing table (inferred from frontend code)
CREATE TABLE shelves (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
user_id UUID REFERENCES auth.users(id) NOT NULL,
name TEXT NOT NULL,
position INTEGER DEFAULT 0,
created_at TIMESTAMPTZ DEFAULT NOW()
);

Columns

ColumnTypeNullableDefaultDescription
iduuidNouuid_generate_v4()Primary key
user_iduuidNo--Shelf owner
nametextNo--Shelf display name
positionintegerNo0Sort order among user shelves
created_attimestamptzNoNOW()Creation timestamp

RLS Policies

-- SELECT: Users can only see their own shelves
CREATE POLICY "Users can view own shelves"
ON shelves FOR SELECT
USING (auth.uid() = user_id);

-- INSERT: Users can create shelves
CREATE POLICY "Users can create shelves"
ON shelves FOR INSERT
WITH CHECK (auth.uid() = user_id);

-- UPDATE: Users can rename/reorder shelves
CREATE POLICY "Users can update own shelves"
ON shelves FOR UPDATE
USING (auth.uid() = user_id);

-- DELETE: Users can delete shelves
CREATE POLICY "Users can delete own shelves"
ON shelves FOR DELETE
USING (auth.uid() = user_id);

Last updated: 2026-02-07