blob: 89adaf89693d23a203d7ea2ca18f45e0a2d38ce2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# frozen_string_literal: true
class RemoveScheduleAndStatusNullConstraintsFromPendingEscalationsAlert < ActiveRecord::Migration[6.1]
include Gitlab::Database::MigrationHelpers
# In preparation of removal of these columns in 14.3.
def up
with_lock_retries do
change_column_null :incident_management_pending_alert_escalations, :status, true
change_column_null :incident_management_pending_alert_escalations, :schedule_id, true
end
end
def down
backfill_from_rules_and_disallow_column_null :status, value: :status
backfill_from_rules_and_disallow_column_null :schedule_id, value: :oncall_schedule_id
end
private
def backfill_from_rules_and_disallow_column_null(column, value:)
with_lock_retries do
execute <<~SQL
UPDATE incident_management_pending_alert_escalations AS escalations
SET #{column} = rules.#{value}
FROM incident_management_escalation_rules AS rules
WHERE rule_id = rules.id
AND escalations.#{column} IS NULL
SQL
change_column_null :incident_management_pending_alert_escalations, column, false
end
end
end
|