From 7b4b96f552e3727247f385f717d8b12a5a406e2b Mon Sep 17 00:00:00 2001 From: Morgan Roderick Date: Fri, 10 Apr 2026 20:06:32 +0200 Subject: [PATCH 1/2] fix(invitations): remove overly restrictive unique constraint on invitation log entries --- app/models/invitation_log_entry.rb | 2 -- ...unique_constraint_from_invitation_log_entries.rb | 13 +++++++++++++ db/schema.rb | 4 ++-- spec/models/invitation_log_entry_spec.rb | 8 -------- 4 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 db/migrate/20260410174346_remove_global_unique_constraint_from_invitation_log_entries.rb diff --git a/app/models/invitation_log_entry.rb b/app/models/invitation_log_entry.rb index 552ee424d..4385b28d3 100644 --- a/app/models/invitation_log_entry.rb +++ b/app/models/invitation_log_entry.rb @@ -4,6 +4,4 @@ class InvitationLogEntry < ApplicationRecord belongs_to :invitation_log belongs_to :member belongs_to :invitation, polymorphic: true, optional: true - - validates :member_id, uniqueness: { scope: %i[invitation_type invitation_id] }, allow_nil: true end diff --git a/db/migrate/20260410174346_remove_global_unique_constraint_from_invitation_log_entries.rb b/db/migrate/20260410174346_remove_global_unique_constraint_from_invitation_log_entries.rb new file mode 100644 index 000000000..e261edeb6 --- /dev/null +++ b/db/migrate/20260410174346_remove_global_unique_constraint_from_invitation_log_entries.rb @@ -0,0 +1,13 @@ +class RemoveGlobalUniqueConstraintFromInvitationLogEntries < ActiveRecord::Migration[8.1] + def up + remove_index :invitation_log_entries, + name: 'idx_on_invitation_type_invitation_id_6d6ef495e6' + end + + def down + add_index :invitation_log_entries, + %i[invitation_type invitation_id], + name: 'idx_on_invitation_type_invitation_id_6d6ef495e6', + unique: true + end +end diff --git a/db/schema.rb b/db/schema.rb index c9369956d..e0a959f50 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.1].define(version: 2026_04_08_220120) do +ActiveRecord::Schema[8.1].define(version: 2026_04_10_174346) do # These are extensions that must be enabled in order to support this database enable_extension "pg_catalog.plpgsql" @@ -297,9 +297,9 @@ 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" t.index ["invitation_log_id", "status"], name: "index_invitation_log_entries_on_invitation_log_id_and_status" t.index ["invitation_log_id"], name: "index_invitation_log_entries_on_invitation_log_id" - t.index ["invitation_type", "invitation_id"], name: "idx_on_invitation_type_invitation_id_6d6ef495e6", unique: true t.index ["invitation_type", "invitation_id"], name: "index_invitation_log_entries_on_invitation" t.index ["member_id", "processed_at"], name: "index_invitation_log_entries_on_member_id_and_processed_at" t.index ["member_id"], name: "index_invitation_log_entries_on_member_id" diff --git a/spec/models/invitation_log_entry_spec.rb b/spec/models/invitation_log_entry_spec.rb index 0c626b1e6..7ddad269e 100644 --- a/spec/models/invitation_log_entry_spec.rb +++ b/spec/models/invitation_log_entry_spec.rb @@ -16,12 +16,4 @@ }) end end - - describe 'validations' do - it 'validates uniqueness of member_id scoped to invitation' do - entry = Fabricate(:invitation_log_entry) - expect(entry).to validate_uniqueness_of(:member_id) - .scoped_to(:invitation_type, :invitation_id) - end - end end From 69b7c1a56786b0bf8627aa4ea6b85a0c33927a3b Mon Sep 17 00:00:00 2001 From: Morgan Roderick Date: Fri, 10 Apr 2026 22:12:42 +0200 Subject: [PATCH 2/2] fix(invitations): remove spurious index from schema.rb 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. --- db/schema.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/db/schema.rb b/db/schema.rb index e0a959f50..1fc00de44 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -297,7 +297,6 @@ 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" t.index ["invitation_log_id", "status"], name: "index_invitation_log_entries_on_invitation_log_id_and_status" t.index ["invitation_log_id"], name: "index_invitation_log_entries_on_invitation_log_id" t.index ["invitation_type", "invitation_id"], name: "index_invitation_log_entries_on_invitation"