Commit 76c88a70 authored by Ryan Cobb's avatar Ryan Cobb Committed by Mayra Cabrera

Change PrometheusMetrics Identifier index

Enforce uniqueness for PrometheusMetrics identifier when project_id is
null.
parent 654c89e7
---
title: Change PrometheusMetrics identifier index
merge_request: 35912
author:
type: fixed
# frozen_string_literal: true
class ChangePrometheusMetricsIdentifierIndex < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
NEW_INDEX = :index_prometheus_metrics_on_identifier_and_null_project
OLD_INDEX = :index_prometheus_metrics_on_identifier
disable_ddl_transaction!
def up
add_concurrent_index :prometheus_metrics, :identifier, name: NEW_INDEX, unique: true, where: 'project_id IS NULL'
remove_concurrent_index_by_name :prometheus_metrics, OLD_INDEX
end
def down
add_concurrent_index :prometheus_metrics, :identifier, name: OLD_INDEX, unique: true
remove_concurrent_index_by_name :prometheus_metrics, NEW_INDEX
end
end
......@@ -20025,7 +20025,7 @@ CREATE INDEX index_prometheus_metrics_on_common ON public.prometheus_metrics USI
CREATE INDEX index_prometheus_metrics_on_group ON public.prometheus_metrics USING btree ("group");
CREATE UNIQUE INDEX index_prometheus_metrics_on_identifier ON public.prometheus_metrics USING btree (identifier);
CREATE UNIQUE INDEX index_prometheus_metrics_on_identifier_and_null_project ON public.prometheus_metrics USING btree (identifier) WHERE (project_id IS NULL);
CREATE UNIQUE INDEX index_prometheus_metrics_on_identifier_and_project_id ON public.prometheus_metrics USING btree (identifier, project_id);
......@@ -23718,6 +23718,7 @@ COPY "schema_migrations" (version) FROM STDIN;
20200701093859
20200701205710
20200702123805
20200702201039
20200703064117
20200703121557
20200703154822
......
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