summaryrefslogtreecommitdiff
path: root/db/migrate/20200625045442_add_idx_and_fk_for_prometheus_and_environment_to_alert_management_alerts.rb
blob: f4869b15735f1c0620e1603a05fa350058520056 (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
# frozen_string_literal: true

class AddIdxAndFkForPrometheusAndEnvironmentToAlertManagementAlerts < ActiveRecord::Migration[6.0]
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false

  disable_ddl_transaction!

  def up
    add_concurrent_index :alert_management_alerts, :prometheus_alert_id, where: 'prometheus_alert_id is not null'
    add_concurrent_foreign_key :alert_management_alerts, :prometheus_alerts, column: :prometheus_alert_id, on_delete: :cascade

    add_concurrent_index :alert_management_alerts, :environment_id, where: 'environment_id is not null'
    add_concurrent_foreign_key :alert_management_alerts, :environments, column: :environment_id, on_delete: :nullify
  end

  def down
    remove_concurrent_index :alert_management_alerts, :prometheus_alert_id
    remove_foreign_key_without_error :alert_management_alerts, column: :prometheus_alert_id

    remove_concurrent_index :alert_management_alerts, :environment_id
    remove_foreign_key_without_error :alert_management_alerts, column: :environment_id
  end
end