diff --git a/lib/gitlab/database/dictionary.rb b/lib/gitlab/database/dictionary.rb index 26094b27ed5cda82d9ccbcfdcf7e02197f792205..78a9dca578f39c98f29533bb031b89d32f795e34 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 e16a68bc185b14b436f7cedcba20cdfe97cb4d96..1847de4f7e1b4d11a12f1be541edf2c251a82980 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?