diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-17 19:05:49 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-17 19:05:49 +0300 |
commit | 43a25d93ebdabea52f99b05e15b06250cd8f07d7 (patch) | |
tree | dceebdc68925362117480a5d672bcff122fb625b /danger/ci_tables/Dangerfile | |
parent | 20c84b99005abd1c82101dfeff264ac50d2df211 (diff) |
Add latest changes from gitlab-org/gitlab@16-0-stable-eev16.0.0-rc42
Diffstat (limited to 'danger/ci_tables/Dangerfile')
-rw-r--r-- | danger/ci_tables/Dangerfile | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/danger/ci_tables/Dangerfile b/danger/ci_tables/Dangerfile new file mode 100644 index 00000000000..1d4601d33b2 --- /dev/null +++ b/danger/ci_tables/Dangerfile @@ -0,0 +1,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 |