OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Ensure notifications are unique to reminders
Kabiru Mwenja89bd340e93bb
diff --git a/app/models/notification.rb b/app/models/notification.rbindex 2b2fbc5c6e4..99407a2e29d 100644--- a/app/models/notification.rb+++ b/app/models/notification.rb@@ -51,6 +51,8 @@ class Notification < ApplicationRecordbelongs_to :journalbelongs_to :resource, polymorphic: true+ has_one :reminder, dependent: :nullify+include Scopes::Scopedscopes :unsent_reminders_before,:mail_reminder_unsent,diff --git a/db/migrate/20241119131205_create_reminders.rb b/db/migrate/20241119131205_create_reminders.rbindex e74d1601642..87e5e5d6fa4 100644--- a/db/migrate/20241119131205_create_reminders.rb+++ b/db/migrate/20241119131205_create_reminders.rb@@ -11,5 +11,10 @@ class CreateReminders < ActiveRecord::Migration[7.1]t.timestampsend++ add_index :reminders, :notification_id,+ unique: true,+ where: "notification_id IS NOT NULL",+ name: "index_reminders_on_notification_id_unique"endenddiff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rbindex e615c033932..b850207b6e3 100644--- a/spec/models/notification_spec.rb+++ b/spec/models/notification_spec.rb@@ -33,6 +33,8 @@ RSpec.describe Notification doit { is_expected.to belong_to(:resource) }it { is_expected.to belong_to(:actor).class_name("User") }it { is_expected.to belong_to(:recipient).class_name("User") }++ it { is_expected.to have_one(:reminder).dependent(:nullify) }enddescribe "Enums" dodiff --git a/spec/models/reminder_spec.rb b/spec/models/reminder_spec.rbindex a65bcfd8857..479a03fd39b 100644--- a/spec/models/reminder_spec.rb+++ b/spec/models/reminder_spec.rb@@ -42,4 +42,8 @@ RSpec.describe Reminder do.backed_by_column_of_type(:integer)endend++ describe "DB Indexes" do+ it { is_expected.to have_db_index(:notification_id).unique(true) }+ endend