From 8fab7c31f08a3af96f3ea634f90709b5011b493c Mon Sep 17 00:00:00 2001 From: Tiger Watson <twatson@gitlab.com> Date: Tue, 16 Apr 2024 23:28:06 +0000 Subject: [PATCH] Apply 1 suggestion(s) to 1 file(s) Co-authored-by: Dylan Griffith <dyl.griffith@gmail.com> --- lib/gitlab/database/dictionary.rb | 4 ++++ spec/lib/gitlab/database/sharding_key_spec.rb | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/gitlab/database/dictionary.rb b/lib/gitlab/database/dictionary.rb index 26094b27ed5cd..78a9dca578f39 100644 --- a/lib/gitlab/database/dictionary.rb +++ b/lib/gitlab/database/dictionary.rb @@ -110,6 +110,10 @@ def desired_sharding_key data['desired_sharding_key'] end + def sharding_key_issue_url + data['sharding_key_issue_url'] + end + def exempt_from_sharding? !!data['exempt_from_sharding'] end diff --git a/spec/lib/gitlab/database/sharding_key_spec.rb b/spec/lib/gitlab/database/sharding_key_spec.rb index e16a68bc185b1..1847de4f7e1b4 100644 --- a/spec/lib/gitlab/database/sharding_key_spec.rb +++ b/spec/lib/gitlab/database/sharding_key_spec.rb @@ -210,6 +210,21 @@ "Please change the `gitlab_schema` of these tables accordingly." end + it 'does not allow invalid follow-up issue URLs', :aggregate_failures do + issue_url_regex = %r{\Ahttps://gitlab\.com/gitlab-org/gitlab/-/issues/\d+\z} + + entries_with_issue_link.each do |entry| + if entry.sharding_key.present? + expect(entry.sharding_key_issue_url).not_to be_present, + "You must remove `sharding_key_issue_url` from #{entry.table_name} now that it has a valid sharding key." \ + else + expect(entry.sharding_key_issue_url).to match(issue_url_regex), + "Invalid `sharding_key_issue_url` url for #{entry.table_name}. Please use the following format: " \ + "https://gitlab.com/gitlab-org/gitlab/-/issues/XXX" + end + end + end + private def error_message(table_name) @@ -231,6 +246,12 @@ def tables_missing_sharding_key(starting_from_milestone:) end end + def entries_with_issue_link + ::Gitlab::Database::Dictionary.entries.select do |entry| + entry.sharding_key_issue_url.present? + end + end + def all_tables_to_sharding_key entries_with_sharding_key = ::Gitlab::Database::Dictionary.entries.select do |entry| entry.sharding_key.present? -- GitLab