Skip to main content

guestbook_entries

Overview

The guestbook_entries table stores messages left by visitors on a user's HomeRoom. Entries go through a moderation workflow -- they start as pending and must be approved by the room owner before being visible to other visitors. Room owners can also pin entries.

Relevant Invariants

  • Invariant #14: "Privacy Is Infrastructure" -- Owner controls what appears on their room
  • Invariant #1: "Participation Is Always Voluntary" -- Room owner moderates at their own pace

Schema

-- From 20260202_guestbook.sql
CREATE TABLE guestbook_entries (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
room_owner_id UUID NOT NULL REFERENCES auth.users(id) ON DELETE CASCADE,
author_id UUID NOT NULL REFERENCES auth.users(id) ON DELETE CASCADE,
content TEXT NOT NULL,
status TEXT DEFAULT 'pending' CHECK (status IN ('pending', 'approved', 'hidden')),
is_pinned BOOLEAN DEFAULT FALSE,
created_at TIMESTAMPTZ DEFAULT NOW(),
moderated_at TIMESTAMPTZ
);

Columns

ColumnTypeNullableDefaultDescription
iduuidNogen_random_uuid()Primary key
room_owner_iduuidNo--HomeRoom owner who receives the entry
author_iduuidNo--Visitor who wrote the entry
contenttextNo--Guestbook message text
statustextNo'pending'Moderation status: pending, approved, hidden
is_pinnedbooleanNoFALSEWhether entry is pinned to top
created_attimestamptzNoNOW()When entry was submitted
moderated_attimestamptzYes--When owner moderated the entry

RLS Policies

-- SELECT: Approved entries visible to all; pending visible to owner and author
CREATE POLICY "Approved entries are public, pending visible to owner/author"
ON guestbook_entries FOR SELECT
USING (
status = 'approved' OR
auth.uid() = room_owner_id OR
auth.uid() = author_id
);

-- INSERT: Friends can write guestbook entries
CREATE POLICY "Friends can write guestbook entries"
ON guestbook_entries FOR INSERT
WITH CHECK (auth.uid() = author_id);

-- UPDATE: Room owner can moderate entries
CREATE POLICY "Room owner can moderate entries"
ON guestbook_entries FOR UPDATE
USING (auth.uid() = room_owner_id);

Last updated: 2026-02-07