diff --git a/db/post_migrate/20251016010313_add_missing_merge_requests_indexes_for_bigint_swap.rb b/db/post_migrate/20251016010313_add_missing_merge_requests_indexes_for_bigint_swap.rb new file mode 100644 index 0000000000000000000000000000000000000000..8a7e688174ab0c7a83584b888995a59a79e15a1f --- /dev/null +++ b/db/post_migrate/20251016010313_add_missing_merge_requests_indexes_for_bigint_swap.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +class AddMissingMergeRequestsIndexesForBigintSwap < Gitlab::Database::Migration[2.3] + milestone '18.6' + disable_ddl_transaction! + + TABLE_NAME = 'merge_requests' + INDEXES = [ + { + name: 'index_merge_requests_on_assignee_id', + columns: [:assignee_id] + }, + { + name: 'index_merge_requests_on_merge_user_id', + columns: [:merge_user_id], + options: { where: "merge_user_id IS NOT NULL" } + }, + { + name: 'index_merge_requests_on_updated_by_id', + columns: [:updated_by_id], + options: { where: "updated_by_id IS NOT NULL" } + }, + { + name: 'index_merge_requests_on_milestone_id', + columns: [:milestone_id] + }, + { + name: 'idx_merge_requests_on_source_project_and_branch_state_opened', + columns: [:source_project_id, :source_branch], + options: { where: "state_id = 1" } + }, + { + name: 'index_merge_requests_on_source_project_id_and_source_branch', + columns: [:source_project_id, :source_branch] + } + ].freeze + + def up + # rubocop:disable Migration/PreventIndexCreation -- add existing indexes for bigint migration + INDEXES.each do |index| + options = index[:options] || {} + add_concurrent_index TABLE_NAME, index[:columns], name: index[:name], if_not_exists: true, **options + end + # rubocop:enable Migration/PreventIndexCreation + end + + def down + # no-op + end +end diff --git a/db/schema_migrations/20251016010313 b/db/schema_migrations/20251016010313 new file mode 100644 index 0000000000000000000000000000000000000000..8c6bacfa8e32bca5ec08399765544eaf2f0ae5d7 --- /dev/null +++ b/db/schema_migrations/20251016010313 @@ -0,0 +1 @@ +17cbdf721008065d0d03032cb0574f5df66e1561b96ca7ccff64780020ac60ca \ No newline at end of file