Skip to main content

post_circles

Overview

The post_circles table is a junction table that links posts with audience='circle' to their target circles. A post can be shared to multiple circles simultaneously. This table is queried when determining post visibility.

Schema

-- From 20260131_circles_schema.sql
CREATE TABLE post_circles (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
post_id UUID NOT NULL REFERENCES posts(id) ON DELETE CASCADE,
circle_id UUID NOT NULL REFERENCES circles(id) ON DELETE CASCADE,
UNIQUE(post_id, circle_id)
);

Columns

ColumnTypeNullableDefaultDescription
iduuidNogen_random_uuid()Primary key
post_iduuidNo--Post reference, cascades on delete
circle_iduuidNo--Target circle, cascades on delete

RLS Policies

-- SELECT: Circle members can see post-circle associations
CREATE POLICY "Circle members can view post circles"
ON post_circles FOR SELECT
USING (is_circle_member(auth.uid(), circle_id));

-- INSERT: Post author can assign circles
CREATE POLICY "Post author can assign circles"
ON post_circles FOR INSERT
WITH CHECK (EXISTS (
SELECT 1 FROM posts WHERE posts.id = post_circles.post_id
AND posts.user_id = auth.uid()
));

Last updated: 2026-02-07