Skip to content

style(rubocop): resolve Rails/UniqueValidationWithoutIndex with DB indexes - #2771

Merged
mroderick merged 1 commit into
masterfrom
fix/unique-validation-index
Aug 4, 2026
Merged

style(rubocop): resolve Rails/UniqueValidationWithoutIndex with DB indexes#2771
mroderick merged 1 commit into
masterfrom
fix/unique-validation-index

Conversation

@mroderick

Copy link
Copy Markdown
Collaborator

Summary

Resolves Rails/UniqueValidationWithoutIndex by adding unique database indexes that back existing uniqueness validations.

Changes

Model Validation New Index
AuthService uid scoped to provider [uid, provider] unique
Chapter name unique name unique
Chapter email unique email unique
FeedbackRequest member_id scoped to workshop [member_id, workshop_id] unique
FeedbackRequest token unique token unique
Invitation member_id scoped to [event_id, role] [member_id, event_id, role] unique
MeetingInvitation member_id scoped to meeting_id [member_id, meeting_id] unique
WorkshopInvitation member_id scoped to [workshop_id, role] [member_id, workshop_id, role] unique
WorkshopSponsor sponsor_id scoped to workshop_id [sponsor_id, workshop_id] unique

Also fixed AuthService's validation syntax: constraint: :provider (non-standard, ignored by Rails) → scope: :provider.

Verification

Migrated cleanly against development and test databases with no duplicate-key errors. All model and controller specs pass.

@mroderick
mroderick force-pushed the fix/unique-validation-index branch from e70ae4c to 78f0b2e Compare August 4, 2026 09:21
@mroderick
mroderick requested a review from olleolleolle August 4, 2026 09:55
@mroderick

Copy link
Copy Markdown
Collaborator Author

This PR made me realise that we didn't have any protections against making silly mistakes with adding indexes during migrations, which caused me to create #2774, which added the strong migrations gem.

Now that it has been merged, I've updated this PR to create indexes using disable_ddl_transaction! and algorithm: :concurrently.

It's ready for review!

@mroderick
mroderick marked this pull request as ready for review August 4, 2026 09:57

@olleolleolle olleolleolle left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@mroderick
mroderick merged commit 552d519 into master Aug 4, 2026
10 checks passed
@mroderick
mroderick deleted the fix/unique-validation-index branch August 4, 2026 10:52
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.

3 participants