-
Notifications
You must be signed in to change notification settings - Fork 48
fix:update sql schema and docs #101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
""" WalkthroughA 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
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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:
- The buckets are marked “public” or you create signed-URL logic in the backend.
- 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 forchat_messages
→chat_list
.When a chat is deleted, its orphaned messages remain and must be manually cleaned.
AddON DELETE CASCADE
to thechat_list_id
FK.
165-190
:collaboration_messages.sender_id
must beuuid
+ advise enum.Same varchar/uuid mismatch.
Additionally, plainVARCHAR(50)
with a CHECK for styles is brittle; a PostgresENUM
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, indexingstatus
is good but consider a partial index on unread/pending rows for faster dashboard queries.
248-259
:notifications.id
usesuuid_generate_v4()
but other tables usegen_random_uuid()
.
uuid_generate_v4()
requires theuuid-ossp
extension, whereasgen_random_uuid()
comes frompgcrypto
(already implied bygen_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
⛔ 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.
There was a problem hiding this 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 ascharacter varying(255)
but should beuuid
to match theusers.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 bothsender_id
andreceiver_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 ascharacter varying(255)
but should beuuid
to match theusers.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 usesextensions.uuid_generate_v4()
while all other tables usegen_random_uuid()
. Consider usinggen_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
📒 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 asuuid
type, matching theusers.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 asuuid
type, matching theusers.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 asuuid
type, matching theusers.id
foreign key reference. This addresses the previous review concern.
There was a problem hiding this 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 varcharBoth columns in
collaboration_requests
must beuuid
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
status
accepts arbitrary strings; add a CHECK (sent|delivered|read
) or use anENUM
.sender_id
/receiver_id
are not validated against the parentchat_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
📒 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 indexNo issues spotted in
ai_insights_cache
.
📝 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
CREATE TABLE
statements for all missing tables:ai_insights_cache
brands
collaboration_analytics
collaboration_deliverables
collaboration_messages
collaboration_requests
collaboration_updates
notifications
social_profiles
sql.txt
to reflect the new table count.brand-logos
andprofile-pictures
buckets in Supabase for media storage.📷 Screenshots or Visual Changes (if applicable)
✅ Checklist
Summary by CodeRabbit