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.
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'),
......
......@@ -8,7 +8,7 @@ module RuboCop
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"
......
......@@ -6,30 +6,37 @@ require_relative '../../../../rubocop/cop/migration/prevent_index_creation'
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
it "registers an offense when add_index is used", :aggregate_failures do
forbidden_tables.each do |table|
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
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
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 :ci_builds, :protected
^^^^^^^^^^^^^^^^^^^^ Adding new index to ci_builds is forbidden, see https://gitlab.com/gitlab-org/gitlab/-/issues/332886
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
context 'when adding an index to a regular table' do
it 'does not register an offense' do
......
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