Commit 2b91a247 authored by Krasimir Angelov's avatar Krasimir Angelov

Update list of forbidden tables when creating indexes

Add taggings, ci_builds_metadata, and events to the list.

https://gitlab.com/gitlab-org/gitlab/-/issues/339280
parent 50a6c22d
...@@ -20,7 +20,7 @@ class ScheduleExtractProjectTopicsIntoSeparateTable < ActiveRecord::Migration[6. ...@@ -20,7 +20,7 @@ class ScheduleExtractProjectTopicsIntoSeparateTable < ActiveRecord::Migration[6.
def up def up
# this index is used in 20210730104800_schedule_extract_project_topics_into_separate_table # 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( queue_background_migration_jobs_by_range_at_intervals(
Tagging.where(taggable_type: 'Project'), Tagging.where(taggable_type: 'Project'),
......
...@@ -8,7 +8,7 @@ module RuboCop ...@@ -8,7 +8,7 @@ module RuboCop
class PreventIndexCreation < RuboCop::Cop::Cop class PreventIndexCreation < RuboCop::Cop::Cop
include MigrationHelpers 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" MSG = "Adding new index to #{FORBIDDEN_TABLES.join(", ")} is forbidden, see https://gitlab.com/gitlab-org/gitlab/-/issues/332886"
......
...@@ -6,28 +6,35 @@ require_relative '../../../../rubocop/cop/migration/prevent_index_creation' ...@@ -6,28 +6,35 @@ require_relative '../../../../rubocop/cop/migration/prevent_index_creation'
RSpec.describe RuboCop::Cop::Migration::PreventIndexCreation do RSpec.describe RuboCop::Cop::Migration::PreventIndexCreation do
subject(:cop) { described_class.new } 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 context 'when in migration' do
before do before do
allow(cop).to receive(:in_migration?).and_return(true) allow(cop).to receive(:in_migration?).and_return(true)
end end
context 'when adding an index to a forbidden table' do context 'when adding an index to a forbidden table' do
it 'registers an offense when add_index is used' do it "registers an offense when add_index is used", :aggregate_failures do
expect_offense(<<~RUBY) forbidden_tables.each do |table|
def change expect_offense(<<~RUBY)
add_index :ci_builds, :protected def change
^^^^^^^^^ Adding new index to ci_builds is forbidden, see https://gitlab.com/gitlab-org/gitlab/-/issues/332886 add_index :#{table}, :protected
end ^^^^^^^^^ Adding new index to #{forbidden_tables_list} is forbidden, see https://gitlab.com/gitlab-org/gitlab/-/issues/332886
RUBY end
RUBY
end
end end
it 'registers an offense when add_concurrent_index is used' do it "registers an offense when add_concurrent_index is used", :aggregate_failures do
expect_offense(<<~RUBY) forbidden_tables.each do |table|
def change expect_offense(<<~RUBY)
add_concurrent_index :ci_builds, :protected def change
^^^^^^^^^^^^^^^^^^^^ Adding new index to ci_builds is forbidden, see https://gitlab.com/gitlab-org/gitlab/-/issues/332886 add_concurrent_index :#{table}, :protected
end ^^^^^^^^^^^^^^^^^^^^ Adding new index to #{forbidden_tables_list} is forbidden, see https://gitlab.com/gitlab-org/gitlab/-/issues/332886
RUBY end
RUBY
end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment