Commit fa2f5ed4 authored by Sarah Yasonik's avatar Sarah Yasonik Committed by Peter Leitzen

Drop schedule and status columns from alert escalations

parent ba527d74
# frozen_string_literal: true
class RemoveScheduleAndStatusFromPendingAlertEscalations < Gitlab::Database::Migration[1.0]
include Gitlab::Database::PartitioningMigrationHelpers
disable_ddl_transaction!
ESCALATIONS_TABLE = :incident_management_pending_alert_escalations
SCHEDULES_TABLE = :incident_management_oncall_schedules
INDEX_NAME = 'index_incident_management_pending_alert_escalations_on_schedule'
CONSTRAINT_NAME = 'fk_rails_fcbfd9338b'
def up
with_lock_retries do
remove_column ESCALATIONS_TABLE, :schedule_id
remove_column ESCALATIONS_TABLE, :status
end
end
def down
with_lock_retries do
add_column ESCALATIONS_TABLE, :schedule_id, :bigint unless column_exists?(ESCALATIONS_TABLE, :schedule_id)
add_column ESCALATIONS_TABLE, :status, :smallint unless column_exists?(ESCALATIONS_TABLE, :status)
end
add_concurrent_partitioned_index ESCALATIONS_TABLE, :schedule_id, name: INDEX_NAME
add_concurrent_partitioned_foreign_key ESCALATIONS_TABLE, SCHEDULES_TABLE, column: :schedule_id, name: CONSTRAINT_NAME
end
end
0a9317419b856ba2abf3cad07c43ccfc79abfcd5efd02c464ee76f4debe362c8
\ No newline at end of file
......@@ -110,11 +110,9 @@ CREATE TABLE incident_management_pending_alert_escalations (
id bigint NOT NULL,
rule_id bigint NOT NULL,
alert_id bigint NOT NULL,
schedule_id bigint,
process_at timestamp with time zone NOT NULL,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
status smallint
updated_at timestamp with time zone NOT NULL
)
PARTITION BY RANGE (process_at);
......@@ -25444,8 +25442,6 @@ CREATE INDEX index_incident_management_pending_alert_escalations_on_alert_id ON
CREATE INDEX index_incident_management_pending_alert_escalations_on_rule_id ON ONLY incident_management_pending_alert_escalations USING btree (rule_id);
CREATE INDEX index_incident_management_pending_alert_escalations_on_schedule ON ONLY incident_management_pending_alert_escalations USING btree (schedule_id);
CREATE INDEX index_incident_management_pending_issue_escalations_on_issue_id ON ONLY incident_management_pending_issue_escalations USING btree (issue_id);
CREATE INDEX index_incident_management_pending_issue_escalations_on_rule_id ON ONLY incident_management_pending_issue_escalations USING btree (rule_id);
......@@ -29977,9 +29973,6 @@ ALTER TABLE ONLY ci_job_variables
ALTER TABLE ONLY packages_nuget_metadata
ADD CONSTRAINT fk_rails_fc0c19f5b4 FOREIGN KEY (package_id) REFERENCES packages_packages(id) ON DELETE CASCADE;
ALTER TABLE incident_management_pending_alert_escalations
ADD CONSTRAINT fk_rails_fcbfd9338b FOREIGN KEY (schedule_id) REFERENCES incident_management_oncall_schedules(id) ON DELETE CASCADE;
ALTER TABLE ONLY customer_relations_contacts
ADD CONSTRAINT fk_rails_fd3f2e7572 FOREIGN KEY (organization_id) REFERENCES customer_relations_organizations(id) ON DELETE CASCADE;
......@@ -6,7 +6,7 @@ module IncidentManagement
include ::IncidentManagement::BasePendingEscalation
include IgnorableColumns
ignore_columns :schedule_id, :status, remove_with: '14.4', remove_after: '2021-09-22'
ignore_columns :schedule_id, :status, remove_with: '14.5', remove_after: '2021-10-22'
self.table_name = 'incident_management_pending_alert_escalations'
......
......@@ -16,7 +16,6 @@ module IncidentManagement
return unless ::Gitlab::IncidentManagement.escalation_policies_available?(project)
return if too_early_to_process?
return if target_already_resolved?
return unless rule # Remove in %14.3; Rule might be unavailable after deploy, but before post-migrations complete.
return if target_status_exceeded_rule?
notify_recipients
......
# frozen_string_literal: true
require 'spec_helper'
require_migration!
RSpec.describe RemoveScheduleAndStatusFromPendingAlertEscalations do
let(:escalations) { table(:incident_management_pending_alert_escalations) }
let(:schedule_index) { 'index_incident_management_pending_alert_escalations_on_schedule' }
let(:schedule_foreign_key) { 'fk_rails_fcbfd9338b' }
it 'correctly migrates up and down' do
reversible_migration do |migration|
migration.before -> {
expect(escalations.column_names).to include('schedule_id', 'status')
expect(escalations_indexes).to include(schedule_index)
expect(escalations_constraints).to include(schedule_foreign_key)
}
migration.after -> {
escalations.reset_column_information
expect(escalations.column_names).not_to include('schedule_id', 'status')
expect(escalations_indexes).not_to include(schedule_index)
expect(escalations_constraints).not_to include(schedule_foreign_key)
}
end
end
private
def escalations_indexes
ActiveRecord::Base.connection.indexes(:incident_management_pending_alert_escalations).collect(&:name)
end
def escalations_constraints
ActiveRecord::Base.connection.foreign_keys(:incident_management_pending_alert_escalations).collect(&:name)
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