Commit 203638a4 authored by Andreas Brandl's avatar Andreas Brandl

Merge branch '339280-prevent-index-creation-on-tables-with-pk-migration-in-progress' into 'master'

Update list of forbidden tables when creating indexes

See merge request gitlab-org/gitlab!68913
parents 43b9da64 2b91a247
......@@ -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,28 +6,35 @@ 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
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
......
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