Enforce invitation identity at the database level with role-less unique indexes

オープン
#2,904 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
rails, ruby
領域
backend, databases

調査の方向性

db/schema.rb と Invitation および WorkshopInvitation モデルのバリデーションから始めて、現在のロールスコープ付きの識別情報を確認します。インデックスを変更する前に、過去の重複クリーンアップの前提条件と PR #2892 の token-index マイグレーションの順序を確認します。ロールなしの一意インデックスと対応するバリデーションが、競合する並行マイグレーションなしで配置されていれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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 role
  • workshop_invitations: unique index on (member_id, workshop_id, role) — same problem
  • Invitation and WorkshopInvitation model validations: uniqueness: { scope: [..., :role] }

Proposal

  1. Drop the role-inclusive unique indexes
  2. Add role-less unique indexes: (member_id, event_id) on invitations, (member_id, workshop_id) on workshop_invitations
  3. 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 invitations and meeting_invitations (different column, same tables) — coordinate migration ordering to avoid conflicting algorithm: :concurrently runs
主要言語
Ruby
スター
104
フォーク
205
平均マージ
1日 6時間
マージ済み PR(30日)
65

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

codebar/planner のほかの issue

codebar/planner の issue をすべて見る

似ている issue

Ruby の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。