fix(invitations): remove overly restrictive unique constraint on invitation log entries#2560
Merged
mroderick merged 2 commits intocodebar:masterfrom Apr 10, 2026
Conversation
Collaborator
Author
|
Fixes #2561 |
…tation log entries
5187740 to
7b4b96f
Compare
till
reviewed
Apr 10, 2026
db/schema.rb
Outdated
| t.datetime "processed_at" | ||
| t.string "status", default: "success", null: false | ||
| t.datetime "updated_at", null: false | ||
| t.index ["invitation_log_id", "invitation_type", "invitation_id"], name: "index_invitation_log_entries_on_batch_and_invitation" |
Collaborator
There was a problem hiding this comment.
I think this should not be here anymore. We are investigating.
till
reviewed
Apr 10, 2026
db/migrate/20260410174346_remove_global_unique_constraint_from_invitation_log_entries.rb
Show resolved
Hide resolved
The batch_and_invitation index was manually added to schema.rb without a corresponding migration. Running rails db:drop db:create db:migrate confirmed this index is not created by any migration.
till
approved these changes
Apr 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Invitation batch #28 for Berlin chapter students is stuck in
runningstatus with only 5 of 431 students processed. The batch crashed with:Root Cause
The database has a global unique constraint on
invitation_log_entries(invitation_type, invitation_id)that prevents the same invitation from being logged in multiple batches. This constraint is more restrictive than the model validation.When a batch tries to create a log entry for an invitation that already has an entry from a previous batch, the INSERT fails. The unsaved entry remains in
@log.entries. Whenfail_batchtries to save the log, Rails validates all entries including the invalid one.Why the Constraint Was Wrong
students,coaches,everyone) may process overlapping member listsfind_or_create_by(member: member, invitation: invitation)+processed_atcheckChanges
invitation_log_entriesNote: The non-unique index on
invitation_log_entries(invitation_type, invitation_id)remains for queries by invitation.Testing
All tests pass:
spec/services/invitation_logger_spec.rb(13 examples)spec/models/invitation_log_entry_spec.rb(4 examples)Deployment Notes
After deploying:
UPDATE invitation_logs SET status = 'failed' WHERE id IN (22, 28);Fixes #2561