diff options
Diffstat (limited to 'db/migrate/20210617022324_create_incident_management_pending_alert_escalations.rb')
-rw-r--r-- | db/migrate/20210617022324_create_incident_management_pending_alert_escalations.rb | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/db/migrate/20210617022324_create_incident_management_pending_alert_escalations.rb b/db/migrate/20210617022324_create_incident_management_pending_alert_escalations.rb new file mode 100644 index 00000000000..32249c9ed56 --- /dev/null +++ b/db/migrate/20210617022324_create_incident_management_pending_alert_escalations.rb @@ -0,0 +1,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 |