Repository navigation
Add direct messages - #2
Merged
Merged
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideIntroduces a Supabase migration for persisted private 1:1 messages, including user foreign keys and query indexes, and adds direct-message seed data. The seed file also contains an apparent duplicate existing message row that reviewers should validate. ER diagram for direct message persistenceerDiagram
AUTH_USERS {
uuid id PK
}
DIRECT_MESSAGES {
bigint id PK
uuid sender_id FK
uuid recipient_id FK
text body
timestamptz created_at
}
AUTH_USERS ||--o{ DIRECT_MESSAGES : sends
AUTH_USERS ||--o{ DIRECT_MESSAGES : receives
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Amsozzer1
force-pushed
the
demo/direct-messages
branch
from
September 28, 2026 22:43
4e81082 to
7b8dcc1
Compare
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="demo/supabase/seed.sql" line_range="23" />
<code_context>
insert into public.messages (room_id, author_id, body) values
(1, '11111111-1111-1111-1111-111111111111', 'hey bob, the launch code is 0000'),
(1, '22222222-2222-2222-2222-222222222222', 'ha, very funny');
+ (1, '22222222-2222-2222-2222-222222222222', 'ha, very funny');
+
</code_context>
<issue_to_address>
**issue (bug_risk):** The seed script contains a standalone duplicate `messages` value tuple after the preceding `INSERT` has already been terminated with a semicolon. PostgreSQL raises a syntax error at this tuple, so the seed script does not complete and the direct-message seed rows are never inserted.
**Suggested fix:** Remove the added duplicate tuple, or include it in the preceding `INSERT` before its terminating semicolon.
</issue_to_address>
### Comment 2
<location path="demo/supabase/migrations/20260920000000_direct_messages.sql" line_range="8" />
<code_context>
+-- Private 1:1 messages between users.
+create table public.direct_messages (
+ id bigint generated always as identity primary key,
+ sender_id uuid not null references auth.users (id),
+ recipient_id uuid not null references auth.users (id),
+ body text not null,
+ created_at timestamptz not null default now()
+);
+create index direct_messages_sender_idx on public.direct_messages (sender_id);
+create index direct_messages_recipient_idx on public.direct_messages (recipient_id);
</code_context>
<issue_to_address>
**🚨 issue (security):** The `direct_messages` table is created without enabling row-level security or defining policies. Because it is in the exposed `public` schema, clients are not restricted to messages where they are the sender or recipient, so unauthenticated or unrelated users can read and write private messages according to the schema's API grants.
**Triggers:** When the Supabase Data API is used with the default public-schema grants.
**Suggested fix:** Enable RLS and add policies that restrict reads to rows whose `sender_id` or `recipient_id` equals `auth.uid()`, and restrict inserts so the authenticated sender matches `sender_id`.
```suggestion
);
alter table public.direct_messages enable row level security;
create policy "users read their direct messages"
on public.direct_messages for select to authenticated
using (
sender_id = (select auth.uid()) or recipient_id = (select auth.uid())
);
create policy "users send their own direct messages"
on public.direct_messages for insert to authenticated
with check (sender_id = (select auth.uid()));
```
</issue_to_address>
✅ Lintel: no new findingsbase@ca65ab7 → head@28a80d9 · static findings from Supabase advisors, proofs from Lintel probes ✅ 2 fixed in this PR · 1 unchanged Fixed in this PR
Run it locally: |
Amsozzer1
force-pushed
the
demo/direct-messages
branch
from
September 28, 2026 23:08
df182ba to
7b8dcc1
Compare
Amsozzer1
force-pushed
the
demo/direct-messages
branch
from
October 13, 2026 22:03
b319e50 to
6948727
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds private 1:1 messages between users, plus seed data.
Summary by Sourcery
Add private direct messages with participant-only access and representative seed conversations.
New Features: