debian-mirror-gitlab/db/migrate/20200625045442_add_idx_and_fk_for_prometheus_and_environment_to_alert_management_alerts.rb
2020-08-09 17:44:08 +05:30

26 lines
1 KiB
Ruby

# 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