post_images
Overview
The post_images table supports multiple image attachments per post. This replaced the earlier single image_url column on the posts table. Images are ordered by position and store both the storage URL and optional alt text.
Schema
-- Pre-existing table (inferred from frontend code)
CREATE TABLE post_images (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
post_id UUID REFERENCES posts(id) ON DELETE CASCADE NOT NULL,
image_url TEXT NOT NULL,
position INTEGER DEFAULT 0,
alt_text TEXT,
created_at TIMESTAMPTZ DEFAULT NOW()
);
Columns
| Column | Type | Nullable | Default | Description |
|---|---|---|---|---|
id | uuid | No | uuid_generate_v4() | Primary key |
post_id | uuid | No | -- | Parent post, cascades on delete |
image_url | text | No | -- | URL to image in Supabase storage |
position | integer | No | 0 | Display order (0-based) |
alt_text | text | Yes | -- | Accessibility description |
created_at | timestamptz | No | NOW() | Upload timestamp |
RLS Policies
-- SELECT: Same visibility as parent post
CREATE POLICY "Users can view images on accessible posts"
ON post_images FOR SELECT
USING (EXISTS (
SELECT 1 FROM posts WHERE posts.id = post_images.post_id
AND can_view_post(auth.uid(), posts.id)
));
-- INSERT: Post author can add images
CREATE POLICY "Users can add images to own posts"
ON post_images FOR INSERT
WITH CHECK (EXISTS (
SELECT 1 FROM posts WHERE posts.id = post_images.post_id
AND posts.user_id = auth.uid()
));
-- DELETE: Post author can remove images
CREATE POLICY "Users can delete images from own posts"
ON post_images FOR DELETE
USING (EXISTS (
SELECT 1 FROM posts WHERE posts.id = post_images.post_id
AND posts.user_id = auth.uid()
));
Related
- posts -- Parent post
Last updated: 2026-02-07