Skip to content

Add direct messages - #2

Merged
Amsozzer1 merged 2 commits into
mainfrom
demo/direct-messages
Oct 13, 2026
Merged

Amsozzer1 merged 2 commits into
mainfrom
demo/direct-messages

Conversation

@Amsozzer1

@Amsozzer1 Amsozzer1 commented Sep 28, 2026 •

Copy link
Copy Markdown
Owner

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:

  • Add private one-to-one direct messaging between authenticated users.
  • Provide seed data covering conversations between sample users.

@sourcery-ai

sourcery-ai Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Introduces 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 persistence

erDiagram
    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
Loading

File-Level Changes

Change Details Files
Add the database schema and seed records for private one-to-one messages.
  • Create a direct_messages table with sender, recipient, body, and timestamp fields.
  • Reference authenticated users and add sender/recipient lookup indexes.
  • Seed a sample two-user conversation with sensitive-looking message content.
demo/supabase/migrations/20260920000000_direct_messages.sql
demo/supabase/seed.sql
Update existing message seed data.
  • Add a duplicate row to the existing room-message seed block; verify this is intentional and that the SQL statement separation remains valid.
demo/supabase/seed.sql

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread demo/supabase/seed.sql Resolved
@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

✅ Lintel: no new findings

base@​ca65ab7 → head@​28a80d9 · static findings from Supabase advisors, proofs from Lintel probes

✅ 2 fixed in this PR · 1 unchanged

Fixed in this PR
  • P001 on public.direct_messages
  • rls_disabled_in_public on public.direct_messages

Run it locally: lintel migrations check · lintel explain <rule>

@Amsozzer1
Amsozzer1 force-pushed the demo/direct-messages branch from b319e50 to 6948727 Compare October 13, 2026 22:03
@Amsozzer1
Amsozzer1 merged commit fee854b into main Oct 13, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant