diff --git a/db/post_migrate/20210730104800_schedule_extract_project_topics_into_separate_table.rb b/db/post_migrate/20210730104800_schedule_extract_project_topics_into_separate_table.rb index bb498f89015b3e5221083c64f2a5d066b22ac2e7..3102561a12915942cff70713f72596d9f1c620eb 100644 --- a/db/post_migrate/20210730104800_schedule_extract_project_topics_into_separate_table.rb +++ b/db/post_migrate/20210730104800_schedule_extract_project_topics_into_separate_table.rb @@ -20,7 +20,7 @@ class Tagging < ActiveRecord::Base def up # this index is used in 20210730104800_schedule_extract_project_topics_into_separate_table - add_concurrent_index :taggings, :id, where: INDEX_CONDITION, name: INDEX_NAME + add_concurrent_index :taggings, :id, where: INDEX_CONDITION, name: INDEX_NAME # rubocop:disable Migration/PreventIndexCreation queue_background_migration_jobs_by_range_at_intervals( Tagging.where(taggable_type: 'Project'), diff --git a/rubocop/cop/migration/prevent_index_creation.rb b/rubocop/cop/migration/prevent_index_creation.rb index c90f911d24e55e3987cf8a160ed1f571320ff390..1486607acbe8ca14671d3ed9dc5ad866825018b2 100644 --- a/rubocop/cop/migration/prevent_index_creation.rb +++ b/rubocop/cop/migration/prevent_index_creation.rb @@ -8,7 +8,7 @@ module Migration class PreventIndexCreation < RuboCop::Cop::Cop include MigrationHelpers - FORBIDDEN_TABLES = %i[ci_builds].freeze + FORBIDDEN_TABLES = %i[ci_builds taggings ci_builds_metadata events].freeze MSG = "Adding new index to #{FORBIDDEN_TABLES.join(", ")} is forbidden, see https://gitlab.com/gitlab-org/gitlab/-/issues/332886" diff --git a/spec/rubocop/cop/migration/prevent_index_creation_spec.rb b/spec/rubocop/cop/migration/prevent_index_creation_spec.rb index a3965f54bbd5ffd57e0db4e76007aa08670a8b89..aa1779a8cd563776ed046ff66e444fad2051ef93 100644 --- a/spec/rubocop/cop/migration/prevent_index_creation_spec.rb +++ b/spec/rubocop/cop/migration/prevent_index_creation_spec.rb @@ -6,28 +6,35 @@ RSpec.describe RuboCop::Cop::Migration::PreventIndexCreation do subject(:cop) { described_class.new } + let(:forbidden_tables) { %w(ci_builds taggings ci_builds_metadata events) } + let(:forbidden_tables_list) { forbidden_tables.join(', ') } + context 'when in migration' do before do allow(cop).to receive(:in_migration?).and_return(true) end context 'when adding an index to a forbidden table' do - it 'registers an offense when add_index is used' do - expect_offense(<<~RUBY) - def change - add_index :ci_builds, :protected - ^^^^^^^^^ Adding new index to ci_builds is forbidden, see https://gitlab.com/gitlab-org/gitlab/-/issues/332886 - end - RUBY + it "registers an offense when add_index is used", :aggregate_failures do + forbidden_tables.each do |table| + expect_offense(<<~RUBY) + def change + add_index :#{table}, :protected + ^^^^^^^^^ Adding new index to #{forbidden_tables_list} is forbidden, see https://gitlab.com/gitlab-org/gitlab/-/issues/332886 + end + RUBY + end end - it 'registers an offense when add_concurrent_index is used' do - expect_offense(<<~RUBY) - def change - add_concurrent_index :ci_builds, :protected - ^^^^^^^^^^^^^^^^^^^^ Adding new index to ci_builds is forbidden, see https://gitlab.com/gitlab-org/gitlab/-/issues/332886 - end - RUBY + it "registers an offense when add_concurrent_index is used", :aggregate_failures do + forbidden_tables.each do |table| + expect_offense(<<~RUBY) + def change + add_concurrent_index :#{table}, :protected + ^^^^^^^^^^^^^^^^^^^^ Adding new index to #{forbidden_tables_list} is forbidden, see https://gitlab.com/gitlab-org/gitlab/-/issues/332886 + end + RUBY + end end end