blob: 1d4601d33b248b352e5f21348a41cb4ee860b235 (
plain)
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
|
# frozen_string_literal: true
SEE_DB_DOC = "See the [database dictionary documentation](https://docs.gitlab.com/ee/development/database/database_dictionary.html)."
PARTITIONING_COMMENT = <<~SUGGEST_COMMENT
When adding new CI tables, consider [partitioning](https://docs.gitlab.com/ee/development/cicd/cicd_tables.html) the table
from the start if it references any of the larger CI tables: `ci_pipelines`, `ci_stages`, `ci_builds`, `p_ci_builds_metadata`, `ci_job_artifacts`, `ci_pipeline_variables`.
SUGGEST_COMMENT
def check_database_dictionary_yaml(database_dictionary)
return unless database_dictionary.ci_schema?
# `p_` prefix is used by the partitioned tables, so we can assume that the table is already partitioned
return if database_dictionary.table_name.to_s.start_with?('p_')
mr_line = database_dictionary.raw.lines.find_index { |line| line.start_with?('table_name:') }
return unless mr_line
markdown(PARTITIONING_COMMENT, file: database_dictionary.path, line: mr_line.succ)
rescue Psych::Exception
# YAML could not be parsed, fail the build.
fail "#{helper.html_link(database_ditionary.path)} isn't valid YAML! #{SEE_DB_DOC}" # rubocop:disable Style/SignalException
rescue StandardError => e
warn "There was a problem trying to check the database dictionary file. Exception: #{e.class.name} - #{e.message}"
end
def added_database_dictionary_files
database_dictionary.database_dictionary_files(change_type: :added)
end
added_database_dictionary_files.each do |database_dictionary|
check_database_dictionary_yaml(database_dictionary)
end
|