Skip to content

Add uniqueness constraint to EventSponsor model #928

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

DiegoPisa2003
Copy link
Contributor

Implements Option 2 from [GitHub Issue #905] to prevent duplicate event-sponsor associations while maintaining flexibility for sponsors with different tiers at the same event.

Problem

Currently, the application allows creating duplicate associations between the same Event and Sponsor in the event_sponsors table, which can lead to:

  • Data Integrity Issues: Duplicate associations create inconsistent data representation
  • UI Problems: Frontend may display the same sponsor multiple times for an event

Solution

Added flexible uniqueness constraint that:

  • Prevents true duplicates: Same event + sponsor + tier combinations
  • Allows flexibility: Same sponsor can have multiple tiers at the same event
  • Maintains data integrity: Both database and model-level validations

- Add unique index on [event_id, sponsor_id, tier] combination
- Prevents duplicate sponsor associations for same event and tier
- Validates sponsor_id uniqueness scoped to event_id and tier
- Normalizes empty tier strings to nil for consistent validation
- Tests same sponsor with different tiers (allowed)
- Tests duplicate sponsor/event/tier combinations (prevented)
- Tests cross-event scenarios (allowed)
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.

1 participant