summaryrefslogtreecommitdiff
path: root/db/migrate/20210617022324_create_incident_management_pending_alert_escalations.rb
blob: 32249c9ed5641db322bfdf61cf0a56687ae11bc7 (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# frozen_string_literal: true

class CreateIncidentManagementPendingAlertEscalations < ActiveRecord::Migration[6.1]
  include Gitlab::Database::MigrationHelpers

  def up
    with_lock_retries do
      execute(<<~SQL)

        CREATE TABLE incident_management_pending_alert_escalations (
          id bigserial NOT NULL,
          rule_id bigint,
          alert_id bigint NOT NULL,
          schedule_id bigint NOT NULL,
          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 NOT NULL,
          PRIMARY KEY (id, process_at)
        ) PARTITION BY RANGE (process_at);

        CREATE INDEX index_incident_management_pending_alert_escalations_on_alert_id
          ON incident_management_pending_alert_escalations USING btree (alert_id);

        CREATE INDEX index_incident_management_pending_alert_escalations_on_rule_id
          ON incident_management_pending_alert_escalations USING btree (rule_id);

        CREATE INDEX index_incident_management_pending_alert_escalations_on_schedule_id
          ON incident_management_pending_alert_escalations USING btree (schedule_id);

        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 incident_management_pending_alert_escalations ADD CONSTRAINT fk_rails_057c1e3d87
          FOREIGN KEY (rule_id) REFERENCES incident_management_escalation_rules(id) ON DELETE SET NULL;

        ALTER TABLE incident_management_pending_alert_escalations ADD CONSTRAINT fk_rails_8d8de95da9
          FOREIGN KEY (alert_id) REFERENCES alert_management_alerts(id) ON DELETE CASCADE;
      SQL
    end
  end

  def down
    with_lock_retries do
      drop_table :incident_management_pending_alert_escalations
    end
  end
end