Commit c839197f authored by Kamil Trzciński's avatar Kamil Trzciński

Fix multiple prometheus alerts migration

parent c56edb40
......@@ -2271,7 +2271,7 @@ ActiveRecord::Schema.define(version: 20180831164910) do
add_index "prometheus_alerts", ["environment_id"], name: "index_prometheus_alerts_on_environment_id", using: :btree
add_index "prometheus_alerts", ["project_id", "prometheus_metric_id"], name: "index_prometheus_alerts_on_project_id_and_prometheus_metric_id", unique: true, using: :btree
add_index "prometheus_alerts", ["prometheus_metric_id"], name: "index_prometheus_alerts_on_prometheus_metric_id_non_unique", using: :btree
add_index "prometheus_alerts", ["prometheus_metric_id"], name: "index_prometheus_alerts_on_prometheus_metric_id", using: :btree
create_table "prometheus_metrics", force: :cascade do |t|
t.integer "project_id"
......
......@@ -9,17 +9,17 @@ class AllowManyPrometheusAlerts < ActiveRecord::Migration
# and convert it into project+prometheus_metric unique
def up
rebuild_foreign_key do
add_concurrent_index :prometheus_alerts, [:project_id, :prometheus_metric_id], unique: true
add_concurrent_index :prometheus_alerts, :prometheus_metric_id, name: :index_prometheus_alerts_on_prometheus_metric_id_non_unique
remove_concurrent_index :prometheus_alerts, :prometheus_metric_id, unique: true
add_concurrent_index :prometheus_alerts, :prometheus_metric_id
add_concurrent_index :prometheus_alerts, [:project_id, :prometheus_metric_id], unique: true
end
end
def down
rebuild_foreign_key do
add_concurrent_index :prometheus_alerts, :prometheus_metric_id, unique: true
remove_concurrent_index :prometheus_alerts, [:project_id, :prometheus_metric_id], unique: true
remove_concurrent_index :prometheus_alerts, :prometheus_metric_id, name: :index_prometheus_alerts_on_prometheus_metric_id_non_unique
remove_concurrent_index :prometheus_alerts, :prometheus_metric_id
add_concurrent_index :prometheus_alerts, :prometheus_metric_id, unique: true
end
end
......@@ -29,6 +29,7 @@ class AllowManyPrometheusAlerts < ActiveRecord::Migration
def rebuild_foreign_key
if Gitlab::Database.mysql?
remove_foreign_key_without_error :prometheus_alerts, :prometheus_metrics
remove_foreign_key_without_error :prometheus_alerts, :projects
end
yield
......@@ -36,6 +37,8 @@ class AllowManyPrometheusAlerts < ActiveRecord::Migration
if Gitlab::Database.mysql?
add_concurrent_foreign_key :prometheus_alerts, :prometheus_metrics,
column: :prometheus_metric_id, on_delete: :cascade
add_concurrent_foreign_key :prometheus_alerts, :projects,
column: :project_id, on_delete: :cascade
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment