Skip to content

Make room name unique for user#52

Open
aissshah wants to merge 7 commits intoTandemCreativeDev:mainfrom
aissshah:feat/room-name-uniqueness-constraint-issue-11
Open

Make room name unique for user#52
aissshah wants to merge 7 commits intoTandemCreativeDev:mainfrom
aissshah:feat/room-name-uniqueness-constraint-issue-11

Conversation

@aissshah
Copy link

@aissshah aissshah commented Jul 9, 2025

Description

This PR addresses the bug raised where a user can create rooms with the same title. Room names are not unique between users.

Note, the room name is case insensitive.

Closes #11

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Screenshots

image
image

Changes Made

Backend

  • Database: Added @@unique([title, userId]) constraint to Chatroom model
  • API: Created /api/rooms/check-name endpoint for real-time name availability checking

Frontend

  • Real-time validation: Added debounced name checking with 500ms delay
  • Visual feedback: Green/red input borders and inline status messages
  • UX improvements: Submit button disabled when name unavailable or validating
  • Error handling: Clean inline validation replacing popup alerts

Technical Implementation

  • Hybrid approach: Frontend validation for UX + database constraint for data integrity

Test Plan

  • ESLint passing
  • TypeScript compilation successful
  • Build process completed
  • Database migration needs to be applied in target environment

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
    - [ ] I have made corresponding changes to the documentation (no documentation changes required)
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

aissshah and others added 6 commits July 9, 2025 14:23
- Add /api/rooms/check-name endpoint for real-time name availability checking
- Update room creation API to validate duplicate titles per user
- Return 409 status code with user-friendly error message for duplicates

Refs TandemCreativeDev#11.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Create roomNameValidation helper for API calls
- Add debounced validation to RoomCreationForm component
- Show real-time feedback with visual indicators (green/red borders)
- Disable submit button when name is unavailable or validating
- Display validation messages for better user experience

Refs TandemCreativeDev#11.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Update roomApi to parse and return specific error messages from API
- Enhance dashboard error handling to show user-friendly messages
- Replace generic "Failed to create room" with specific error details
- Better user experience when duplicate room names are detected

Refs TandemCreativeDev#11.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Remove duplicate validation check from API since frontend handles it
- Remove popup alert from dashboard since inline validation shows errors
- Cleaner user experience with single error display method

Refs TandemCreativeDev#11.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add @@unique([title, userId]) constraint to Chatroom model to enforce
room name uniqueness per user at the database level. This provides
a safety net alongside frontend validation.

Refs TandemCreativeDev#11.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Remove unused error variables to fix ESLint warnings.

Refs TandemCreativeDev#11.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@aissshah
Copy link
Author

aissshah commented Jul 9, 2025

Update: Changes have been pushed. Will see if I can create a migration file like we have in the repo
Looks like if we want to fix the drift we will need to reset the database... which I do think might be too disruptive mid-workshop 🙃

Steps: (Documentation)
npx prisma db pull
npx prisma migrate dev --name fix-drift
The command above will prompt dropping the dev database using prisma migrate reset

The drift error message:

Drift detected: Your database schema is not in sync with your migration history.

     The following is a summary of the differences between the expected database schema given your migrations files, and the actual schema of the 
     database.

     It should be understood as the set of changes to get from the expected schema to the actual schema.

     [+] Added tables
       - accounts
       - link_previews
       - sessions
       - users
       - verification_tokens

     [*] Changed the `accounts` table
       [+] Added unique index on columns (provider, providerAccountId)
       [+] Added foreign key on columns (userId)

     [*] Changed the `chatrooms` table
       [+] Added column `roomUrl`
       [+] Added column `userId`
       [+] Added unique index on columns (roomUrl)
       [+] Added foreign key on columns (userId)

     [*] Changed the `link_previews` table
       [+] Added foreign key on columns (messageId)

     [*] Changed the `sessions` table
       [+] Added unique index on columns (sessionToken)
       [+] Added foreign key on columns (userId)

     [*] Changed the `users` table
       [+] Added unique index on columns (email)

     [*] Changed the `verification_tokens` table
       [+] Added unique index on columns (identifier, token)
       [+] Added unique index on columns (token)

     We need to reset the "public" schema at "157.90.162.222:5434"

     You may use prisma migrate reset to drop the development database.
     All data will be lost.

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.

Facilitators can create multiple rooms with the same name

1 participant