Skip to content

Conversation

Saahi30
Copy link
Collaborator

@Saahi30 Saahi30 commented Jul 16, 2025

📝 Description

This pull request updates and synchronizes the SQL schema for the project.
It ensures that all tables used in the backend and visible in the Supabase dashboard are fully documented and reproducible for future developers.
The README is also updated to include instructions for creating required Supabase storage buckets.

🔧 Changes Made

  • Added CREATE TABLE statements for all missing tables:
    • ai_insights_cache
    • brands
    • collaboration_analytics
    • collaboration_deliverables
    • collaboration_messages
    • collaboration_requests
    • collaboration_updates
    • notifications
    • social_profiles
  • Added relevant indexes for performance.
  • Updated the top-of-file summary in sql.txt to reflect the new table count.
  • Updated the README to instruct users to create brand-logos and profile-pictures buckets in Supabase for media storage.

📷 Screenshots or Visual Changes (if applicable)

Screenshot 2025-07-16 at 10 34 32 PM

✅ Checklist

  • I have read the contributing guidelines.

Summary by CodeRabbit

  • New Features
    • Introduced new database tables supporting chat, trending niches, AI insights caching, brand profiles, collaboration management, notifications, and social media profiles.
    • Added a new AI-related frontend dependency.
  • Documentation
    • Updated the README with instructions for creating Supabase storage buckets required for media uploads.

Copy link
Contributor

coderabbitai bot commented Jul 16, 2025

"""

Walkthrough

A significant schema expansion was made to the backend SQL, introducing multiple new tables for chat, brands, collaborations, analytics, notifications, and social profiles, each with relevant constraints and indexes. The frontend added the "ai" package dependency, and the README now includes instructions for creating Supabase storage buckets for media uploads. Additionally, chat service logic was refined to standardize user ID ordering for chat threads.

Changes

File(s) Change Summary
Backend/sql.txt Added new tables for chat, trending niches, AI insights cache, brands, collaborations, analytics, notifications, and social profiles, with constraints and indexes.
Backend/app/services/chat_services.py Added get_canonical_user_pair method to standardize user ID ordering in chat queries and creation; simplified chat message creation logic.
Frontend/package.json Added the "ai" dependency (version ^4.3.17).
README.md Added instructions for creating "brand-logos" and "profile-pictures" Supabase storage buckets.

Poem

In the warren, tables bloom anew,
Chats and brands in columns true.
Analytics, socials, all in place,
With storage buckets for media's grace.
A new AI friend hops in with cheer—
The rabbit’s code is crystal clear!
🐇✨
"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9f6a9f8 and 43efe5b.

📒 Files selected for processing (1)
  • Backend/sql.txt (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Backend/sql.txt

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Nitpick comments (5)
README.md (1)

181-196: Spell out bucket access & RLS; doc is incomplete for a working setup.

Creating the two buckets is necessary but not sufficient—objects will 404 unless:

  1. The buckets are marked “public” or you create signed-URL logic in the backend.
  2. Storage RLS policies allow anon read access (typical for public avatars/logos).

Add a short note or SQL snippet so new contributors don’t hit invisible-image bugs.

Backend/sql.txt (4)

52-61: Consider ON DELETE CASCADE for chat_messageschat_list.

When a chat is deleted, its orphaned messages remain and must be manually cleaned.
Add ON DELETE CASCADE to the chat_list_id FK.


165-190: collaboration_messages.sender_id must be uuid + advise enum.

Same varchar/uuid mismatch.
Additionally, plain VARCHAR(50) with a CHECK for styles is brittle; a Postgres ENUM gives stronger guarantees and smaller storage.


197-225: collaboration_requests.sender_id/receiver_id – wrong type & missing status index default.

Both IDs should be uuid. Also, indexing status is good but consider a partial index on unread/pending rows for faster dashboard queries.


248-259: notifications.id uses uuid_generate_v4() but other tables use gen_random_uuid().

uuid_generate_v4() requires the uuid-ossp extension, whereas gen_random_uuid() comes from pgcrypto (already implied by gen_random_uuid() calls elsewhere). Use one provider consistently to avoid extension-dependency drift.

-  id uuid not null default extensions.uuid_generate_v4 (),
+  id uuid not null default gen_random_uuid (),
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a3be437 and 72beeb6.

⛔ Files ignored due to path filters (1)
  • Frontend/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • Backend/sql.txt (1 hunks)
  • Frontend/package.json (1 hunks)
  • README.md (1 hunks)
🔇 Additional comments (1)
Frontend/package.json (1)

12-30: ai@4.3.17 supports React 19 – no changes needed
npm view ai@4.3.17 peerDependencies confirms:

  • react: ^18 || ^19 || ^19.0.0-rc

Your React 19 setup is fully compatible with ai@4.3.17. You can safely merge without pinning or workarounds.

@Saahi30 Saahi30 changed the title update sql schema and docs fix:update sql schema and docs Jul 16, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (2)
Backend/sql.txt (2)

175-175: Critical: Type mismatch in collaboration_messages.sender_id.

The sender_id field is defined as character varying(255) but should be uuid to match the users.id foreign key reference. This will cause schema creation to fail.

- sender_id character varying(255) null,
+ sender_id uuid null,

The same issue exists in collaboration_requests table for both sender_id and receiver_id fields on lines 207-208.

Also applies to: 207-208


143-143: Critical: Type mismatch in collaboration_deliverables.assigned_to.

The assigned_to field is defined as character varying(255) but should be uuid to match the users.id foreign key reference.

- assigned_to uuid null,
+ assigned_to uuid null,

Wait, this appears to already be correctly defined as uuid. Let me verify the foreign key reference is correct.

🧹 Nitpick comments (2)
Backend/sql.txt (2)

59-68: Clean chat_messages table structure.

The table structure is well-designed with proper foreign key relationships and appropriate data types. The status field could benefit from a check constraint for validation.

Consider adding a check constraint for the status field:

  status VARCHAR(20) DEFAULT 'sent',
+ CONSTRAINT chat_messages_status_check CHECK (status IN ('sent', 'delivered', 'seen')),

255-255: Inconsistent UUID generation function.

The notifications table uses extensions.uuid_generate_v4() while all other tables use gen_random_uuid(). Consider using gen_random_uuid() for consistency.

- id uuid not null default extensions.uuid_generate_v4 (),
+ id uuid not null default gen_random_uuid(),
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 72beeb6 and d93de99.

📒 Files selected for processing (2)
  • Backend/app/services/chat_services.py (3 hunks)
  • Backend/sql.txt (1 hunks)
🔇 Additional comments (7)
Backend/app/services/chat_services.py (3)

62-64: LGTM! Clean implementation of canonical user ordering.

This helper method correctly implements the canonical ordering logic to ensure consistent user pair representation in the database, aligning perfectly with the schema's unique constraint design.


83-84: Good integration of canonical ordering in send_message.

The method correctly uses the canonical user pair for both querying existing chat lists and creating new ones, ensuring consistency with the database schema's unique constraint.

Also applies to: 89-89, 97-97


415-416: Proper implementation of canonical ordering in create_new_chat_message.

The canonical ordering is correctly applied, and the explicit .scalar_one_or_none() call on line 423 is a good practice for clarity.

Also applies to: 420-420, 423-423

Backend/sql.txt (4)

43-57: Excellent implementation of canonical ordering constraint.

The combination of the application-level note, unique constraint, and the symmetric unique index properly prevents duplicate chat threads regardless of user order. This aligns perfectly with the service layer implementation.


242-242: Good: collaboration_updates.author_id type is correct.

The author_id field is properly defined as uuid type, matching the users.id foreign key reference. This addresses the previous review concern.


95-95: Good: brands.user_id type is correct.

The user_id field is properly defined as uuid type, matching the users.id foreign key reference. This addresses the previous review concern.


271-271: Good: social_profiles.user_id type is correct.

The user_id field is properly defined as uuid type, matching the users.id foreign key reference. This addresses the previous review concern.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

♻️ Duplicate comments (1)
Backend/sql.txt (1)

207-210: Ditto: sender_id / receiver_id columns still varchar

Both columns in collaboration_requests must be uuid for the FK to succeed.

-  sender_id character varying(255) null,
-  receiver_id character varying(255) null,
+  sender_id uuid null,
+  receiver_id uuid null,
🧹 Nitpick comments (1)
Backend/sql.txt (1)

62-68: Missing status domain / FK back-reference

  1. status accepts arbitrary strings; add a CHECK (sent|delivered|read) or use an ENUM.
  2. sender_id / receiver_id are not validated against the parent chat_list_id, so a user can inject a message into an unrelated chat. A composite FK (sender_id, receiver_id, chat_list_id) or a trigger can enforce consistency.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d93de99 and 9f6a9f8.

📒 Files selected for processing (1)
  • Backend/sql.txt (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
Backend/sql.txt (1)
Learnt from: Saahi30
PR: AOSSIE-Org/InPactAI#91
File: Backend/app/models/models.py:177-177
Timestamp: 2025-07-08T21:54:56.095Z
Learning: In the Backend/app/models/models.py file, the Notification model intentionally uses datetime.utcnow for the created_at field instead of timezone-aware datetime for easier debugging and error tracking, as preferred by the user for notification timestamp handling.
🔇 Additional comments (1)
Backend/sql.txt (1)

80-90: Looks good – proper PK, UNIQUE cache key, expiry index

No issues spotted in ai_insights_cache.

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