3.3 KiB
Plan: Support Multiple Images/Videos per Post
Overview
Currently, the application treats every image or video as an independent entity (a picture or linked video). We want to introduce a higher-level concept of a Post which can contain one or more media items (images or videos).
This allows:
- Grouping related photos (e.g., a photo dump, or variations).
- A unified description and comment section for the group.
- Preserving individual interactions (likes/comments) on specific images within the post if desired (as per requirements).
Database Schema Changes
We will introduce a new posts table and link existing pictures to it.
1. New Table: posts
This table will hold the content for the "container".
| Column | Type | Notes |
|Ref|---|---|
| id | uuid | Primary Key, default gen_random_uuid() |
| user_id | uuid | FK to auth.users (or profiles) |
| title | text | Main title of the post |
| description | text | Description/Caption for the whole post |
| created_at | timestamptz | default now() |
| updated_at | timestamptz | |
| metadata | jsonb | Flexible field for extra data |
2. Update Table: pictures
We link media items to the post.
- Add column
post_id:uuid, FK toposts(id). - Add column
position:integer, default 0. To order images within a post.
Note
: Videos are stored in the
picturestable withtype='mux-video', so this change covers both images and videos. The separatevideostable in Supabase appears unused by the current frontend.
3. Update Table: comments and likes
Currently, comments and likes reference picture_id.
- Requirement: "we might have also comments, and descriptions for the parent 'post'".
- Approach:
- Add
post_idtocommentsandlikestables (nullable). - Or create
post_comments/post_likestables if cleaner. - Decision: We will start with a simple structure where
postshave their owndescription(already in table). For comments, we might need a unified comment system later or link comments to posts. For now, let's focus onpostscontainingpictures.
- Add
Migration Strategy (SQL)
According to user feedback, no backfill is required. Old pictures will simply not be displayed in the new "Post" feed which will rely on the posts table.
- Create
poststable. - Alter
picturestable: Addpost_idcolumn.
UI/UX Updates
Feed (PhotoGrid.tsx)
- Query
postsinstead ofpictures. - Fetch the first linked picture for the thumbnail.
Post Detail (Post.tsx)
- Route
/post/:idwill now accept a Post ID. - Fetch Post metadata.
- Fetch associated Media Items (
select * from pictures where post_id = :id order by position).
Creation Wizard
- Allow granular updates: "Select Multiple Files".
- Create Post -> Upload all files -> Create Picture records linked to Post.
Step-by-Step Implementation
- Supabase Migration: Create tables, run backfill script.
- Codebase - Types: Update
types.ts(re-run codegen). - Codebase - API: Update any fetch functions to use
posts. - UI - Feed: Switch
PhotoGridto useposts. - UI - Detail: Rewrite
Post.tsxto handlePost+Media[]. - UI - Create: Update upload logic.