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
| Column | Type | Nullable | Default | Description |
|---|---|---|---|---|
id | uuid | No | gen_random_uuid() | Primary key |
post_id | uuid | No | -- | Post reference, cascades on delete |
circle_id | uuid | No | -- | 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()
));
Related
Last updated: 2026-02-07