File: gitlab_schema_validation_suggestion.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (35 lines) | stat: -rw-r--r-- 1,304 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# frozen_string_literal: true

require_relative 'suggestion'

module Tooling
  module Danger
    module GitlabSchemaValidationSuggestion
      include ::Tooling::Danger::Suggestor

      MATCH = %r{gitlab_schema: gitlab_main_clusterwide}
      REPLACEMENT = nil
      DB_DOCS_PATH = %r{\Adb/docs/[^/]+\.ya?ml\z}

      SUGGESTION = <<~MESSAGE_MARKDOWN
        :warning: You have added `gitlab_main_clusterwide` as the schema for this table. We expect most tables to use the
        `gitlab_main_cell` schema instead, as using the clusterwide schema can have significant scaling implications.

        Please see the [guidelines on choosing gitlab schema](https://docs.gitlab.com/ee/development/cells/index.html#guidelines-on-choosing-between-gitlab_main_cell-and-gitlab_main_clusterwide-schema) for more information.

        Please consult with ~"group::tenant scale" if you believe that the clusterwide schema is the best fit for this table.
      MESSAGE_MARKDOWN

      def add_suggestions_on_using_clusterwide_schema
        helper.all_changed_files.grep(DB_DOCS_PATH).each do |filename|
          add_suggestion(
            filename: filename,
            regex: MATCH,
            replacement: REPLACEMENT,
            comment_text: SUGGESTION
          )
        end
      end
    end
  end
end