Skip to main content

friendships

Overview

The friendships table manages bidirectional friend relationships. CommonPlace only supports mutual friendships -- there are no one-way "follows." A friendship begins as a request (status = 'pending') and becomes active when accepted. The requester/addressee distinction tracks who initiated.

Relevant Invariants

  • Invariant #1: "Participation Is Always Voluntary" -- Friend requests can be declined or ignored without consequence
  • Invariant #7: "Human-Scale Social Contexts" -- Mutual friendships enforce small, intentional networks

Schema

-- Pre-existing table (inferred from frontend code)
CREATE TABLE friendships (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
requester_id UUID REFERENCES auth.users(id) NOT NULL,
addressee_id UUID REFERENCES auth.users(id) NOT NULL,
status TEXT DEFAULT 'pending' CHECK (status IN ('pending', 'accepted', 'declined')),
responded_at TIMESTAMPTZ,
created_at TIMESTAMPTZ DEFAULT NOW(),
UNIQUE(requester_id, addressee_id)
);

Columns

ColumnTypeNullableDefaultDescription
iduuidNouuid_generate_v4()Primary key
requester_iduuidNo--User who sent the friend request
addressee_iduuidNo--User who received the request
statustextNo'pending'Request state: pending, accepted, declined
responded_attimestamptzYes--When request was accepted/declined
created_attimestamptzNoNOW()When request was sent

RLS Policies

-- SELECT: Users can see their own friendships
CREATE POLICY "Users can view own friendships"
ON friendships FOR SELECT
USING (auth.uid() = requester_id OR auth.uid() = addressee_id);

-- INSERT: Users can send friend requests
CREATE POLICY "Users can send friend requests"
ON friendships FOR INSERT
WITH CHECK (auth.uid() = requester_id);

-- UPDATE: Addressee can accept/decline requests
CREATE POLICY "Users can respond to friend requests"
ON friendships FOR UPDATE
USING (auth.uid() = addressee_id);

-- DELETE: Either party can remove friendship
CREATE POLICY "Users can remove friendships"
ON friendships FOR DELETE
USING (auth.uid() = requester_id OR auth.uid() = addressee_id);
  • profiles -- Both parties in the friendship
  • blocks -- Blocking removes friendships
  • circles -- Friends can be organized into circles
  • relationship_edges -- Custom relationship labels between friends

Last updated: 2026-02-07