diff --git a/db/post_migrate/20240708130252_remove_idx_project_statistics_wiki_size_and_project_id_sync.rb b/db/post_migrate/20240708130252_remove_idx_project_statistics_wiki_size_and_project_id_sync.rb new file mode 100644 index 0000000000000000000000000000000000000000..002b458fcf5b0ab72762928faf1b323b01bfd173 --- /dev/null +++ b/db/post_migrate/20240708130252_remove_idx_project_statistics_wiki_size_and_project_id_sync.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class RemoveIdxProjectStatisticsWikiSizeAndProjectIdSync < Gitlab::Database::Migration[2.2] + milestone '17.3' + disable_ddl_transaction! + + INDEX_NAME = 'index_project_statistics_on_wiki_size_and_project_id' + COLUMNS = %i[wiki_size project_id] + + def up + return unless should_run? + + remove_concurrent_index_by_name :project_statistics, name: INDEX_NAME + end + + def down + return unless should_run? + + add_concurrent_index :project_statistics, COLUMNS, name: INDEX_NAME + end + + def should_run? + Gitlab.com_except_jh? + end +end diff --git a/db/schema_migrations/20240708130252 b/db/schema_migrations/20240708130252 new file mode 100644 index 0000000000000000000000000000000000000000..b83f4634d8b33382b4fa95e38e38e12a1fb96747 --- /dev/null +++ b/db/schema_migrations/20240708130252 @@ -0,0 +1 @@ +4b1b5505a9becd13c4001b16f07a2fa2f0e331b97fed81a93b098ba82fc95715 \ No newline at end of file diff --git a/spec/migrations/20240611122408_remove_project_statistics_wiki_size_and_project_id_index_spec.rb b/spec/migrations/20240611122408_remove_project_statistics_wiki_size_and_project_id_index_spec.rb index bd357e09404a174cc42a1a2ae22e149e6af04361..c97731ca00296a792596048bbb354fc10fd7de03 100644 --- a/spec/migrations/20240611122408_remove_project_statistics_wiki_size_and_project_id_index_spec.rb +++ b/spec/migrations/20240611122408_remove_project_statistics_wiki_size_and_project_id_index_spec.rb @@ -4,7 +4,9 @@ require_migration! -RSpec.describe RemoveProjectStatisticsWikiSizeAndProjectIdIndex, feature_category: :consumables_cost_management do +RSpec.describe RemoveProjectStatisticsWikiSizeAndProjectIdIndex, + feature_category: :consumables_cost_management, + schema: 20240611122408 do let(:migration) { described_class.new } let(:postgres_async_indexes) { table(:postgres_async_indexes) } diff --git a/spec/migrations/20240708130252_remove_idx_project_statistics_wiki_size_and_project_id_sync_spec.rb b/spec/migrations/20240708130252_remove_idx_project_statistics_wiki_size_and_project_id_sync_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..031e3a258d0c72272aebbefbaecf193d846db83a --- /dev/null +++ b/spec/migrations/20240708130252_remove_idx_project_statistics_wiki_size_and_project_id_sync_spec.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +require 'spec_helper' + +require_migration! + +RSpec.describe RemoveIdxProjectStatisticsWikiSizeAndProjectIdSync, + feature_category: :consumables_cost_management, + schema: 20240708130252 do + let(:migration) { described_class.new } + + describe '#up' do + it 'does nothing when not on gitlab.com' do + expect(migration).not_to receive(:remove_concurrent_index_by_name) + + migration.up + end + + it 'removes the index when on gitlab.com', :saas do + expect(migration).to receive(:remove_concurrent_index_by_name) + + migration.up + end + end + + describe '#down' do + it 'does nothing when not on gitlab.com' do + expect(migration).not_to receive(:add_concurrent_index) + + migration.down + end + + it 're-adds the index when on gitlab.com', :saas do + expect(migration).to receive(:add_concurrent_index) + + migration.down + end + end +end