fix(reaction-roles): PUT panel edit deletes mappings by cuid not snowflake (#1675)
Fixes #1675.
Problem
PUT /api/guilds/:guildId/reaction-roles/:messageId always 400s:
Unique constraint failed on the fields: (`messageId`)
updateReactionRoleMessage cleared old mappings with:
prisma.reactionRoleMapping.deleteMany({ where: { messageId } }) // messageId = Discord snowflake
But ReactionRoleMapping.messageId is a FK to ReactionRoleMessage.id (a cuid), with @@unique([messageId, roleId]). The snowflake matched zero rows, so the nested mappings.create re-inserted existing (messageId, roleId) pairs and violated the unique constraint. Every edit failed; only delete+recreate worked (which changes the Discord messageId and re-orders panels).
Fix
Delete old mappings by message.id (the cuid, already loaded) in both the update transaction and the rollback transaction. Add a regression test asserting deleteMany is called with the message cuid, not the snowflake.
Verified
packages/sharedtests: 98 passed (incl. new #1675 guard).- Typecheck clean across all workspaces.
- The create path was already correct and untouched.
Summary by cubic
Fixes reaction‑role panel edits by deleting old mappings using the message cuid (DB id) instead of the Discord snowflake in both update and rollback paths. This prevents unique constraint errors, including when the Discord PATCH fails.
- Bug Fixes
- Delete old mappings by
message.id(cuid) inreactionRoleMapping.deleteManyfor both update and rollback transactions. - Add regression tests for both paths to assert deletion by cuid (#1675).
- Delete old mappings by
Summary by CodeRabbit
- Bug Fixes
- Fixed reaction-role cleanup so related mappings are deleted using the correct internal message identifier, preventing mismatched deletions when a message update fails.
- Tests
- Expanded and adjusted regression coverage for reaction-role message updates, including rollback behavior and updated mocked responses for existing scenarios.