Skip to main content

comments

Overview

The comments table stores responses to posts. CommonPlace uses the term "respond" rather than "comment" in the UI to signal thoughtful engagement over reactive commenting. Comments support threading through the parent_comment_id self-reference.

Relevant Invariants

  • Invariant #5: "Repair Over Punishment" -- Editing responses is normal and encouraged
  • Invariant #6: "No Public Comparative Metrics" -- No like counts on responses

Schema

-- Pre-existing table (inferred from frontend code)
CREATE TABLE comments (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
post_id UUID REFERENCES posts(id) ON DELETE CASCADE NOT NULL,
user_id UUID REFERENCES auth.users(id) NOT NULL,
content TEXT NOT NULL,
parent_comment_id UUID REFERENCES comments(id),
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW()
);

Columns

ColumnTypeNullableDefaultDescription
iduuidNouuid_generate_v4()Primary key
post_iduuidNo--Parent post reference, cascades on delete
user_iduuidNo--Author of the response
contenttextNo--Response text content
parent_comment_iduuidYes--For threaded replies, references parent comment
created_attimestamptzNoNOW()Creation timestamp
updated_attimestamptzNoNOW()Last edit timestamp

RLS Policies

-- SELECT: Users can read comments on posts they can view
CREATE POLICY "Users can view comments on accessible posts"
ON comments FOR SELECT
USING (EXISTS (
SELECT 1 FROM posts WHERE posts.id = comments.post_id
AND can_view_post(auth.uid(), posts.id)
));

-- INSERT: Authenticated users can respond to accessible posts
CREATE POLICY "Users can create comments"
ON comments FOR INSERT
WITH CHECK (auth.uid() = user_id);

-- UPDATE: Users can edit their own responses
CREATE POLICY "Users can update own comments"
ON comments FOR UPDATE
USING (auth.uid() = user_id);

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

Last updated: 2026-02-07