Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions supabase/migrations/20260615000000_add_user_follows.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- Add user follows table
CREATE TABLE follows (
follower_id UUID REFERENCES profiles(id) ON DELETE CASCADE,
following_id UUID REFERENCES profiles(id) ON DELETE CASCADE,
created_at TIMESTAMPTZ DEFAULT NOW(),
PRIMARY KEY (follower_id, following_id),
CHECK (follower_id != following_id)
);
Comment on lines +2 to +8

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P0 Duplicate table — migration will crash at runtime

The follows table was already created in supabase/migrations/20260201090000_follow_system.sql (line 5) using CREATE TABLE IF NOT EXISTS follows. This new migration uses a bare CREATE TABLE follows with no IF NOT EXISTS guard, so when Supabase applies migrations sequentially it will hit ERROR: relation "follows" already exists and abort, leaving the database in an inconsistent migration state. The PR description's premise that the table was missing is incorrect — it has existed since the Feb 1 migration.

Comment on lines +2 to +8

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Schema incompatible with existing table

The existing follows table in 20260201090000_follow_system.sql has a surrogate id UUID PRIMARY KEY DEFAULT gen_random_uuid() with a separate UNIQUE(follower_id, following_id) constraint, and both FK columns declared NOT NULL. This migration removes the id column entirely, promotes (follower_id, following_id) to the primary key, and drops the NOT NULL constraints — meaning any application code or FK reference relying on the id column, or the count-maintenance trigger (on_follow_change), would break.


CREATE INDEX idx_follows_follower ON follows(follower_id);
CREATE INDEX idx_follows_following ON follows(following_id);

ALTER TABLE follows ENABLE ROW LEVEL SECURITY;

CREATE POLICY "Follows are viewable by everyone" ON follows FOR SELECT USING (true);
CREATE POLICY "Users can manage their own follows" ON follows FOR ALL USING (auth.uid() = follower_id);
Comment on lines +15 to +16

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Duplicate RLS policy name will error; FOR ALL without WITH CHECK weakens insert safety

The policy "Follows are viewable by everyone" already exists on the follows table (created in 20260201090000_follow_system.sql), so CREATE POLICY will throw ERROR: policy "Follows are viewable by everyone" for table "follows" already exists. Additionally, the FOR ALL USING (auth.uid() = follower_id) policy omits an explicit WITH CHECK clause; PostgreSQL will fall back to using the USING expression for insert checks, but the intent is ambiguous and diverges from the existing pattern of separate FOR INSERT WITH CHECK and FOR DELETE USING policies that make the authorization contract explicit.

Loading