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
Replace unique constraint with deferrable check constraint
Oliver Güntherec257b2c2db4
diff --git a/modules/meeting/app/services/recurring_meetings/update_service.rb b/modules/meeting/app/services/recurring_meetings/update_service.rbindex b40a0d6f629..29ea3416ff6 100644--- a/modules/meeting/app/services/recurring_meetings/update_service.rb+++ b/modules/meeting/app/services/recurring_meetings/update_service.rb@@ -107,11 +107,12 @@ module RecurringMeetingsnext_occurrences = recurring_meeting.scheduled_occurrences(limit: future_meetings.count)# Update each meeting's timing to match the new schedule- future_meetings.each_with_index do |scheduled, index|- next_time = next_occurrences[index]&.to_time+ # Wrap in transaction to allow deferrable unique constraint to work+ Meeting.transaction do+ future_meetings.each_with_index do |scheduled, index|+ next_time = next_occurrences[index]&.to_time- if next_time- Meeting.transaction do+ if next_timescheduled.update_column(:start_time, next_time)scheduled.meeting.update_column(:start_time, next_time)enddiff --git a/modules/meeting/db/migrate/20250227140619_change_unique_constraint_on_scheduled_meetings.rb b/modules/meeting/db/migrate/20250227140619_change_unique_constraint_on_scheduled_meetings.rbnew file mode 100644index 00000000000..b1d9b77055d--- /dev/null+++ b/modules/meeting/db/migrate/20250227140619_change_unique_constraint_on_scheduled_meetings.rb@@ -0,0 +1,53 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#+++class ChangeUniqueConstraintOnScheduledMeetings < ActiveRecord::Migration[6.0]+ def up+ remove_index :scheduled_meetings,+ %i[recurring_meeting_id start_time],+ unique: true++ execute <<~SQL.squish+ ALTER TABLE scheduled_meetings+ ADD CONSTRAINT unique_recurring_meeting_start_time+ UNIQUE (recurring_meeting_id, start_time) DEFERRABLE INITIALLY DEFERRED;+ SQL+ end++ def down+ execute <<~SQL.squish+ ALTER TABLE scheduled_meetings+ DROP CONSTRAINT unique_recurring_meeting_start_time;+ SQL++ add_index :scheduled_meetings,+ %i[recurring_meeting_id start_time],+ unique: true+ end+enddiff --git a/modules/meeting/spec/services/recurring_meetings/update_service_integration_spec.rb b/modules/meeting/spec/services/recurring_meetings/update_service_integration_spec.rbindex fc943d5f185..83a1ef83bd6 100644--- a/modules/meeting/spec/services/recurring_meetings/update_service_integration_spec.rb+++ b/modules/meeting/spec/services/recurring_meetings/update_service_integration_spec.rb@@ -230,6 +230,24 @@ RSpec.describe RecurringMeetings::UpdateService, "integration", type: :model doendend+ context "when changing interval to 2, so that previous occurrences overlap" do+ let(:params) do+ {+ interval: 2+ }+ end++ it "succeeds" do+ expect(service_result).to be_success++ # Verify each scheduled meeting is moved to weekly intervals+ scheduled_meetings.each_with_index do |meeting, index|+ meeting.reload+ expect(meeting.start_time).to eq(Time.zone.today + ((index + 1) * 2).days + 10.hours)+ end+ end+ end+context "when changing end_date to before the last scheduled meeting" dolet(:params) do{