Commit fc6d3431 authored by Sean Arnold's avatar Sean Arnold

Update migration to add combination index

- Rename spec vars and tests
parent b0bf0012
# frozen_string_literal: true # frozen_string_literal: true
class AddRemovedAtToOncallParticipant < ActiveRecord::Migration[6.0] class AddIsRemovedToOncallParticipant < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers include Gitlab::Database::MigrationHelpers
DOWNTIME = false DOWNTIME = false
......
# frozen_string_literal: true # frozen_string_literal: true
class AddRemovedAtToOncallParticipantIndex < ActiveRecord::Migration[6.0] class AddIsRemovedIndexToOncallParticipant < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers include Gitlab::Database::MigrationHelpers
disable_ddl_transaction! disable_ddl_transaction!
DOWNTIME = false DOWNTIME = false
INDEX_NAME = 'index_incident_management_oncall_participants_is_removed' EXISTING_INDEX_NAME = 'index_inc_mgmnt_oncall_participants_on_oncall_rotation_id'
NEW_INDEX_NAME = 'index_inc_mgmnt_oncall_pcpnt_on_oncall_rotation_id_is_removed'
def up def up
add_concurrent_index :incident_management_oncall_participants, :is_removed, name: INDEX_NAME add_concurrent_index :incident_management_oncall_participants, [:oncall_rotation_id, :is_removed], name: NEW_INDEX_NAME
remove_concurrent_index_by_name(:incident_management_oncall_participants, EXISTING_INDEX_NAME)
end end
def down def down
remove_concurrent_index_by_name(:incident_management_oncall_participants, INDEX_NAME) add_concurrent_index :incident_management_oncall_participants, :oncall_rotation_id, name: EXISTING_INDEX_NAME
remove_concurrent_index_by_name(:incident_management_oncall_participants, NEW_INDEX_NAME)
end end
end end
...@@ -22448,18 +22448,16 @@ CREATE INDEX index_import_failures_on_project_id_not_null ON import_failures USI ...@@ -22448,18 +22448,16 @@ CREATE INDEX index_import_failures_on_project_id_not_null ON import_failures USI
CREATE INDEX index_imported_projects_on_import_type_creator_id_created_at ON projects USING btree (import_type, creator_id, created_at) WHERE (import_type IS NOT NULL); CREATE INDEX index_imported_projects_on_import_type_creator_id_created_at ON projects USING btree (import_type, creator_id, created_at) WHERE (import_type IS NOT NULL);
CREATE INDEX index_inc_mgmnt_oncall_participants_on_oncall_rotation_id ON incident_management_oncall_participants USING btree (oncall_rotation_id);
CREATE INDEX index_inc_mgmnt_oncall_participants_on_oncall_user_id ON incident_management_oncall_participants USING btree (user_id); CREATE INDEX index_inc_mgmnt_oncall_participants_on_oncall_user_id ON incident_management_oncall_participants USING btree (user_id);
CREATE UNIQUE INDEX index_inc_mgmnt_oncall_participants_on_user_id_and_rotation_id ON incident_management_oncall_participants USING btree (user_id, oncall_rotation_id); CREATE UNIQUE INDEX index_inc_mgmnt_oncall_participants_on_user_id_and_rotation_id ON incident_management_oncall_participants USING btree (user_id, oncall_rotation_id);
CREATE INDEX index_inc_mgmnt_oncall_pcpnt_on_oncall_rotation_id_is_removed ON incident_management_oncall_participants USING btree (oncall_rotation_id, is_removed);
CREATE UNIQUE INDEX index_inc_mgmnt_oncall_rotations_on_oncall_schedule_id_and_id ON incident_management_oncall_rotations USING btree (oncall_schedule_id, id); CREATE UNIQUE INDEX index_inc_mgmnt_oncall_rotations_on_oncall_schedule_id_and_id ON incident_management_oncall_rotations USING btree (oncall_schedule_id, id);
CREATE UNIQUE INDEX index_inc_mgmnt_oncall_rotations_on_oncall_schedule_id_and_name ON incident_management_oncall_rotations USING btree (oncall_schedule_id, name); CREATE UNIQUE INDEX index_inc_mgmnt_oncall_rotations_on_oncall_schedule_id_and_name ON incident_management_oncall_rotations USING btree (oncall_schedule_id, name);
CREATE INDEX index_incident_management_oncall_participants_is_removed ON incident_management_oncall_participants USING btree (is_removed);
CREATE INDEX index_incident_management_oncall_schedules_on_project_id ON incident_management_oncall_schedules USING btree (project_id); CREATE INDEX index_incident_management_oncall_schedules_on_project_id ON incident_management_oncall_schedules USING btree (project_id);
CREATE INDEX index_incident_management_oncall_shifts_on_participant_id ON incident_management_oncall_shifts USING btree (participant_id); CREATE INDEX index_incident_management_oncall_shifts_on_participant_id ON incident_management_oncall_shifts USING btree (participant_id);
...@@ -30,8 +30,8 @@ module IncidentManagement ...@@ -30,8 +30,8 @@ module IncidentManagement
NAME_LENGTH = 200 NAME_LENGTH = 200
belongs_to :schedule, class_name: 'OncallSchedule', inverse_of: 'rotations', foreign_key: 'oncall_schedule_id' belongs_to :schedule, class_name: 'OncallSchedule', inverse_of: 'rotations', foreign_key: 'oncall_schedule_id'
# Note! If changing the order of participants, also change the :with_shift_generation_associations scope.
has_many :participants, -> { order(id: :asc) }, class_name: 'OncallParticipant', inverse_of: :rotation has_many :participants, -> { order(id: :asc) }, class_name: 'OncallParticipant', inverse_of: :rotation
# Note! If changing the order of participants, also change the :with_shift_generation_associations scope.
has_many :active_participants, -> { not_removed.order(id: :asc) }, class_name: 'OncallParticipant', inverse_of: :rotation has_many :active_participants, -> { not_removed.order(id: :asc) }, class_name: 'OncallParticipant', inverse_of: :rotation
has_many :users, through: :participants has_many :users, through: :participants
has_many :shifts, class_name: 'OncallShift', inverse_of: :rotation, foreign_key: :rotation_id has_many :shifts, class_name: 'OncallShift', inverse_of: :rotation, foreign_key: :rotation_id
......
...@@ -175,7 +175,7 @@ module IncidentManagement ...@@ -175,7 +175,7 @@ module IncidentManagement
def participants def participants
strong_memoize(:participants) do strong_memoize(:participants) do
rotation.participants.not_removed rotation.active_participants
end end
end end
......
...@@ -40,7 +40,7 @@ RSpec.describe IncidentManagement::OncallParticipant do ...@@ -40,7 +40,7 @@ RSpec.describe IncidentManagement::OncallParticipant do
end end
describe 'scopes' do describe 'scopes' do
let_it_be(:removed) { create(:incident_management_oncall_participant, :removed, rotation: rotation) } let_it_be(:removed_participant) { create(:incident_management_oncall_participant, :removed, rotation: rotation) }
describe '.not_removed' do describe '.not_removed' do
subject { described_class.not_removed } subject { described_class.not_removed }
...@@ -51,18 +51,14 @@ RSpec.describe IncidentManagement::OncallParticipant do ...@@ -51,18 +51,14 @@ RSpec.describe IncidentManagement::OncallParticipant do
describe '.removed' do describe '.removed' do
subject { described_class.removed } subject { described_class.removed }
it { is_expected.to contain_exactly(removed) } it { is_expected.to contain_exactly(removed_participant) }
end end
end end
describe '#mark_as_removed' do describe '#mark_as_removed' do
around do |example|
freeze_time { example.run }
end
subject { participant.mark_as_removed } subject { participant.mark_as_removed }
it 'updates is_removed to the current time' do it 'updates is_removed to true' do
expect { subject }.to change { participant.reload.is_removed }.to(true) expect { subject }.to change { participant.reload.is_removed }.to(true)
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment