Skip to content

fix(schema): add unique guild+thread constraint to guildforumthread - #1603

Closed
LucasSantana-Dev wants to merge 1 commit into
mainfrom
fix/deletereactionrolemessage-db-error
Closed

LucasSantana-Dev wants to merge 1 commit into
mainfrom
fix/deletereactionrolemessage-db-error

Conversation

@LucasSantana-Dev

@LucasSantana-Dev LucasSantana-Dev commented Jun 25, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds a unique index on (guildId, threadId) to prevent duplicate rows for the same thread in the GuildForumThread model.

The existing @@unique([guildId, slug]) constraint only enforced slug uniqueness within a guild, not thread uniqueness. This left the schema vulnerable to duplicate entries for the same thread.

Closes #1534


Summary by cubic

Add a unique (guildId, threadId) constraint to GuildForumThread to prevent duplicate threads, and fix reaction-role deletion to return proper errors and show a clear bot message on failures.

  • Bug Fixes

    • DELETE /api/guilds/:guildId/reaction-roles/:messageId now returns 500 for DB errors and 404 only when not found.
    • Bot handleDelete wraps deletion in try/catch and replies with an ephemeral error embed on failures.
  • Migration

    • Run prisma migrate deploy.
    • If it fails, remove duplicate (guildId, threadId) rows from guild_forum_threads and rerun.

Written for commit 8bb8542. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling when deleting reaction-role messages, so unexpected failures now return a clear generic error instead of breaking the request.
    • Preserved the existing “not found” response when a reaction-role message doesn’t exist.
    • Updated bot responses to show a more helpful failure message when deletion can’t be completed.
  • Tests

    • Added coverage for API and bot deletion failures to verify the new error behavior.

@coderabbitai

coderabbitai Bot commented Jun 25, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2830febd-d0bf-4b42-88bb-cd710b88ebfa

📥 Commits

Reviewing files that changed from the base of the PR and between ad4b7ed and 8bb8542.

📒 Files selected for processing (4)
  • packages/backend/src/routes/roles.ts
  • packages/backend/tests/integration/routes/roles.test.ts
  • packages/bot/src/functions/general/handlers/reactionroleHandlers.spec.ts
  • packages/bot/src/functions/general/handlers/reactionroleHandlers.ts

📝 Walkthrough

Walkthrough

The reaction-role delete flow now catches service failures in both the backend API route and the bot handler. New tests cover service rejection cases for each path.

Changes

Reaction-role delete error handling

Layer / File(s) Summary
Backend delete route error mapping
packages/backend/src/routes/roles.ts, packages/backend/tests/integration/routes/roles.test.ts
DELETE /api/guilds/:guildId/reaction-roles/:messageId now catches service errors, preserves AppError responses, maps other failures to HTTP 500, and the integration test covers the service-rejection case.
Bot delete handler fallback
packages/bot/src/functions/general/handlers/reactionroleHandlers.ts, packages/bot/src/functions/general/handlers/reactionroleHandlers.spec.ts
handleDelete now catches delete-service exceptions and sends a generic ephemeral error embed, and the spec covers the rejection path.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Possibly related PRs

Suggested labels

backend, database

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/deletereactionrolemessage-db-error

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

Failed to generate code suggestions for PR

The DELETE reaction-roles endpoint was treating database errors the same as
"record not found" cases, returning 404 instead of 500. The service method
already throws non-P2025 errors correctly; the route handler now catches and
properly escalates these errors.

Updated bot handler to wrap the call in try-catch to gracefully handle DB
errors and provide appropriate user feedback instead of crashing.

Fixes: #1536
@LucasSantana-Dev

Copy link
Copy Markdown
Owner Author

Closing - this was an incorrect merge. Will create a new PR for the correct changes.

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
B Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(schema): add @@unique([guildId, threadId]) to GuildForumThread to enforce 1:1 mapping

1 participant