diff --git a/danger/gitlab_schema_validation/Dangerfile b/danger/gitlab_schema_validation/Dangerfile deleted file mode 100644 index 3d44ad592ae8722e15a76beb29929eeceda4f4e7..0000000000000000000000000000000000000000 --- a/danger/gitlab_schema_validation/Dangerfile +++ /dev/null @@ -1,3 +0,0 @@ -# frozen_string_literal: true - -gitlab_schema_validation.add_suggestions_on_using_clusterwide_schema diff --git a/danger/plugins/gitlab_schema_validation.rb b/danger/plugins/gitlab_schema_validation.rb deleted file mode 100644 index ca4bc1a12be365648adb696683c595618e69aa35..0000000000000000000000000000000000000000 --- a/danger/plugins/gitlab_schema_validation.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../tooling/danger/gitlab_schema_validation_suggestion' - -module Danger - class GitlabSchemaValidation < ::Danger::Plugin - include Tooling::Danger::GitlabSchemaValidationSuggestion - end -end diff --git a/lib/gitlab/database/gitlab_schema.rb b/lib/gitlab/database/gitlab_schema.rb index 52fb75a4a570ca28e0bbaf960d1fbf6d89c7de4f..de993b78c79321489153a06412eaf1b756553aef 100644 --- a/lib/gitlab/database/gitlab_schema.rb +++ b/lib/gitlab/database/gitlab_schema.rb @@ -27,7 +27,6 @@ def self.table_schemas!(tables) # It maps table names prefixes to gitlab_schemas. # The order of keys matter. Prefixes that contain other prefixes should come first. IMPLICIT_GITLAB_SCHEMAS = { - '_test_gitlab_main_clusterwide_' => :gitlab_main_clusterwide, '_test_gitlab_main_cell_' => :gitlab_main_cell, '_test_gitlab_main_org_' => :gitlab_main_org, '_test_gitlab_main_' => :gitlab_main, diff --git a/lib/gitlab/database/query_analyzers/restrict_allowed_schemas.rb b/lib/gitlab/database/query_analyzers/restrict_allowed_schemas.rb index 9ec48c8ca07fa568bf32dfb90ebcd0cdb42c26ac..820b536858e9f96407ee08de7fdede8bc1106c4c 100644 --- a/lib/gitlab/database/query_analyzers/restrict_allowed_schemas.rb +++ b/lib/gitlab/database/query_analyzers/restrict_allowed_schemas.rb @@ -19,7 +19,6 @@ class RestrictAllowedSchemas < Base gitlab_internal: nil, # Cells specific changes - gitlab_main_clusterwide: :gitlab_main, gitlab_main_cell: :gitlab_main, gitlab_main_org: :gitlab_main, gitlab_main_cell_local: :gitlab_main, diff --git a/spec/lib/gitlab/database/gitlab_schema_spec.rb b/spec/lib/gitlab/database/gitlab_schema_spec.rb index 8899d7ec0b8f148875a44f7b281d2305462b9cc8..d35416071a3df14d6725b7212302c071c4470cf7 100644 --- a/spec/lib/gitlab/database/gitlab_schema_spec.rb +++ b/spec/lib/gitlab/database/gitlab_schema_spec.rb @@ -38,7 +38,6 @@ 'audit_events_part_5fc467ac26' | :gitlab_main '_test_gitlab_main_table' | :gitlab_main '_test_gitlab_ci_table' | :gitlab_ci - '_test_gitlab_main_clusterwide_table' | :gitlab_main_clusterwide '_test_gitlab_main_cell_table' | :gitlab_main_cell '_test_gitlab_main_org_table' | :gitlab_main_org '_test_gitlab_pm_table' | :gitlab_pm diff --git a/spec/lib/gitlab/database/query_analyzers/restrict_allowed_schemas_spec.rb b/spec/lib/gitlab/database/query_analyzers/restrict_allowed_schemas_spec.rb index 59a6ce663f5fa5a61effbd7cd4c8c2e192e9c5c0..14006905d94d8e6f3c278eb7539a830c66dd5fad 100644 --- a/spec/lib/gitlab/database/query_analyzers/restrict_allowed_schemas_spec.rb +++ b/spec/lib/gitlab/database/query_analyzers/restrict_allowed_schemas_spec.rb @@ -16,7 +16,6 @@ expected_allowed_gitlab_schemas: { no_schema: :dml_not_allowed, gitlab_main: :success, - gitlab_main_clusterwide: :success, gitlab_main_cell: :success, gitlab_main_org: :success, gitlab_ci: :dml_access_denied # cross-schema access @@ -27,7 +26,6 @@ expected_allowed_gitlab_schemas: { no_schema: :dml_not_allowed, gitlab_main: :success, - gitlab_main_clusterwide: :success, gitlab_main_cell: :success, gitlab_main_org: :success, gitlab_ci: :dml_access_denied # cross-schema access @@ -38,7 +36,6 @@ expected_allowed_gitlab_schemas: { no_schema: :dml_not_allowed, gitlab_main: :success, - gitlab_main_clusterwide: :success, gitlab_main_cell: :success, gitlab_main_org: :success, gitlab_ci: :dml_access_denied # cross-schema access @@ -49,7 +46,6 @@ expected_allowed_gitlab_schemas: { no_schema: :dml_not_allowed, gitlab_main: :success, - gitlab_main_clusterwide: :success, gitlab_main_cell: :success, gitlab_main_org: :success, gitlab_ci: :dml_access_denied # cross-schema access diff --git a/spec/tooling/danger/gitlab_schema_validation_suggestion_spec.rb b/spec/tooling/danger/gitlab_schema_validation_suggestion_spec.rb deleted file mode 100644 index 759188176b43d01c669494cc17e17431d5ee185f..0000000000000000000000000000000000000000 --- a/spec/tooling/danger/gitlab_schema_validation_suggestion_spec.rb +++ /dev/null @@ -1,108 +0,0 @@ -# frozen_string_literal: true - -require 'fast_spec_helper' -require 'gitlab/dangerfiles/spec_helper' - -require_relative '../../../tooling/danger/gitlab_schema_validation_suggestion' -require_relative '../../../tooling/danger/project_helper' - -RSpec.describe Tooling::Danger::GitlabSchemaValidationSuggestion, feature_category: :cell do - include_context "with dangerfile" - - let(:fake_danger) { DangerSpecHelper.fake_danger.include(described_class) } - let(:fake_project_helper) { instance_double(Tooling::Danger::ProjectHelper) } - let(:filename) { 'db/docs/application_settings.yml' } - let(:file_lines) do - file_diff.map { |line| line.delete_prefix('+') } - end - - let(:file_diff) do - [ - "+---", - "+table_name: application_settings", - "+classes:", - "+- ApplicationSetting", - "+feature_categories:", - "+- continuous_integration", - "+description: GitLab application settings", - "+introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/commit/8589b4e137f50293952923bb07e2814257d7784d", - "+milestone: '7.7'", - "+gitlab_schema: #{schema}" - ] - end - - subject(:gitlab_schema_validation) { fake_danger.new(helper: fake_helper) } - - before do - allow(gitlab_schema_validation).to receive(:project_helper).and_return(fake_project_helper) - allow(gitlab_schema_validation.project_helper).to receive(:file_lines).and_return(file_lines) - allow(gitlab_schema_validation.helper).to receive(:changed_lines).with(filename).and_return(file_diff) - allow(gitlab_schema_validation.helper).to receive(:all_changed_files).and_return([filename]) - end - - shared_examples_for 'does not add a comment' do - it do - expect(gitlab_schema_validation).not_to receive(:markdown) - - gitlab_schema_validation.add_suggestions_on_using_clusterwide_schema - end - end - - context 'for discouraging the use of gitlab_main_clusterwide schema' do - let(:schema) { 'gitlab_main_clusterwide' } - - context 'when the file path matches' do - it 'adds the comment' do - expected_comment = "\n#{described_class::SUGGESTION.chomp}" - - expect(gitlab_schema_validation).to receive(:markdown).with(expected_comment, file: filename, line: 10) - - gitlab_schema_validation.add_suggestions_on_using_clusterwide_schema - end - end - - context 'when the file path does not match' do - let(:filename) { 'some_path/application_settings.yml' } - - it_behaves_like 'does not add a comment' - end - - context 'for EE' do - let(:filename) { 'ee/db/docs/application_settings.yml' } - - it_behaves_like 'does not add a comment' - end - - context 'for a deleted table' do - let(:filename) { 'db/docs/deleted_tables/application_settings.yml' } - - it_behaves_like 'does not add a comment' - end - end - - context 'on removing the gitlab_main_clusterwide schema' do - let(:file_diff) do - [ - "+---", - "+table_name: application_settings", - "+classes:", - "+- ApplicationSetting", - "+feature_categories:", - "+- continuous_integration", - "+description: GitLab application settings", - "+introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/commit/8589b4e137f50293952923bb07e2814257d7784d", - "+milestone: '7.7'", - "-gitlab_schema: gitlab_main_clusterwide", - "+gitlab_schema: gitlab_main_org" - ] - end - - it_behaves_like 'does not add a comment' - end - - context 'when a different schema is added' do - let(:schema) { 'gitlab_main' } - - it_behaves_like 'does not add a comment' - end -end diff --git a/tooling/danger/gitlab_schema_validation_suggestion.rb b/tooling/danger/gitlab_schema_validation_suggestion.rb deleted file mode 100644 index 0806bc51fb3c0af357b7d5443b6a76b57dc4eef1..0000000000000000000000000000000000000000 --- a/tooling/danger/gitlab_schema_validation_suggestion.rb +++ /dev/null @@ -1,35 +0,0 @@ -# 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` (deprecated) as the schema for this table. We expect most tables to use the - `gitlab_main_org` schema instead. - - Please see the [guidelines on choosing gitlab schema](https://docs.gitlab.com/ee/development/cells/#what-schema-to-choose-if-the-feature-can-be-cluster-wide) for more information. - - Please consult with `@gitlab-com/gl-infra/tenant-scale/cells-infrastructure` 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