Commit 54268903 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'rc/enforce_unique_metrics_id_across_project' into 'master'

Composite metric identifier index

See merge request gitlab-org/gitlab!35566
parents 46311254 28afab28
......@@ -11,6 +11,7 @@ class PrometheusMetric < ApplicationRecord
validates :group, presence: true
validates :y_label, presence: true
validates :unit, presence: true
validates :identifier, uniqueness: { scope: :project_id }, allow_nil: true
validates :project, presence: true, unless: :common?
validates :project, absence: true, if: :common?
......
---
title: Enforce prometheus metric uniqueness across project scope
merge_request: 35566
author:
type: fixed
# frozen_string_literal: true
class AddUniqIndexOnMetricIdentifierAndProjectId < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_concurrent_index :prometheus_metrics, [:identifier, :project_id], unique: true
end
def down
remove_concurrent_index :prometheus_metrics, [:identifier, :project_id]
end
end
......@@ -19929,6 +19929,8 @@ CREATE INDEX index_prometheus_metrics_on_group ON public.prometheus_metrics USIN
CREATE UNIQUE INDEX index_prometheus_metrics_on_identifier ON public.prometheus_metrics USING btree (identifier);
CREATE UNIQUE INDEX index_prometheus_metrics_on_identifier_and_project_id ON public.prometheus_metrics USING btree (identifier, project_id);
CREATE INDEX index_prometheus_metrics_on_project_id ON public.prometheus_metrics USING btree (project_id);
CREATE INDEX index_protected_branch_merge_access ON public.protected_branch_merge_access_levels USING btree (protected_branch_id);
......@@ -23582,6 +23584,7 @@ COPY "schema_migrations" (version) FROM STDIN;
20200625190458
20200626060151
20200626130220
20200629192638
20200630110826
20200701093859
20200702123805
......
......@@ -11,6 +11,7 @@ RSpec.describe PrometheusMetric do
it { is_expected.to validate_presence_of(:title) }
it { is_expected.to validate_presence_of(:query) }
it { is_expected.to validate_presence_of(:group) }
it { is_expected.to validate_uniqueness_of(:identifier).scoped_to(:project_id).allow_nil }
describe 'common metrics' do
using RSpec::Parameterized::TableSyntax
......
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