Enforce invitation identity at the database level with role-less unique indexes
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 104
- Forks
- 205
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 63
Description
Summary
PR #2867 enforces one invitation per member per event/workshop in application code (InvitationManager). The database still encodes the old identity, so nothing prevents a second row — and any future code path (like the one fixed in the review commit for WorkshopsController#find_or_create_invitation) can reintroduce duplicates.
Current state in db/schema.rb:
invitations: unique index on(member_id, event_id, role)— role-inclusive, so it permits one row per roleworkshop_invitations: unique index on(member_id, workshop_id, role)— same problemInvitationandWorkshopInvitationmodel validations:uniqueness: { scope: [..., :role] }
Proposal
- Drop the role-inclusive unique indexes
- Add role-less unique indexes:
(member_id, event_id)oninvitations,(member_id, workshop_id)onworkshop_invitations - Update the model uniqueness validations to match
These indexes also make create_or_find_by race-safe.
Prerequisites
- Historical duplicate rows must be deduped first (companion issue) or index creation fails
- The "which role survives" decision (companion issue) determines what the dedupe keeps
Related
- PR #2892 adds unique token indexes to
invitationsandmeeting_invitations(different column, same tables) — coordinate migration ordering to avoid conflictingalgorithm: :concurrentlyruns
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with db/schema.rb and the Invitation and WorkshopInvitation model validations to confirm the current role-scoped identity. Review the historical duplicate cleanup prerequisite and PR #2892's token-index migration ordering before changing indexes. Done means role-less unique indexes and matching validations are in place without conflicting concurrent migrations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rails, ruby
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100