Commit e0c78f31 authored by Sean Arnold's avatar Sean Arnold

Switch to using a boolean

Update migrations and schema
Update code and specs
parent 2b95ed39
......@@ -7,13 +7,11 @@ class AddRemovedAtToOncallParticipant < ActiveRecord::Migration[6.0]
def up
with_lock_retries do
add_column :incident_management_oncall_participants, :removed_at, :datetime_with_timezone
add_column :incident_management_oncall_participants, :is_removed, :boolean, default: false
end
end
def down
remove_column :incident_management_oncall_participants, :removed_at
remove_column :incident_management_oncall_participants, :is_removed
end
end
......@@ -3,14 +3,16 @@
class AddRemovedAtToOncallParticipantIndex < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
DOWNTIME = false
INDEX_NAME = 'index_incident_management_oncall_participants_is_removed'
def up
add_concurrent_index :incident_management_oncall_participants, :removed_at
add_concurrent_index :incident_management_oncall_participants, :is_removed, name: INDEX_NAME
end
def down
remove_concurrent_index :incident_management_oncall_participants, :removed_at
remove_concurrent_index_by_name(:incident_management_oncall_participants, INDEX_NAME)
end
end
......@@ -13234,7 +13234,7 @@ CREATE TABLE incident_management_oncall_participants (
user_id bigint NOT NULL,
color_palette smallint NOT NULL,
color_weight smallint NOT NULL,
removed_at timestamp with time zone
is_removed boolean DEFAULT false
);
CREATE SEQUENCE incident_management_oncall_participants_id_seq
......@@ -22461,7 +22461,7 @@ CREATE UNIQUE INDEX index_inc_mgmnt_oncall_rotations_on_oncall_schedule_id_and_n
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_participants_on_removed_at ON incident_management_oncall_participants USING btree (removed_at);
CREATE INDEX index_incident_management_oncall_participants_is_removed ON incident_management_oncall_participants USING btree (is_removed);
CREATE UNIQUE INDEX index_index_statuses_on_project_id ON index_statuses USING btree (project_id);
......@@ -21,11 +21,11 @@ module IncidentManagement
delegate :project, to: :rotation, allow_nil: true
scope :not_removed, -> { where(removed_at: nil) }
scope :removed, -> { where('removed_at is NOT NULL') }
scope :not_removed, -> { where(is_removed: false) }
scope :removed, -> { where(is_removed: true) }
def mark_as_removed
update_column(:removed_at, Time.current)
update_column(:is_removed, true)
end
end
end
......@@ -14,7 +14,7 @@ FactoryBot.define do
end
trait :removed do
removed_at { Time.current }
is_removed { true }
end
end
end
......@@ -62,8 +62,8 @@ RSpec.describe IncidentManagement::OncallParticipant do
subject { participant.mark_as_removed }
it 'updates removed_at to the current time' do
expect { subject }.to change { participant.reload.removed_at }.to(Time.current)
it 'updates is_removed to the current time' do
expect { subject }.to change { participant.reload.is_removed }.to(true)
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