From abedf003a700bb4d77bbb4eb9ed486c40d612987 Mon Sep 17 00:00:00 2001
From: Maxime Orefice <morefice@gitlab.com>
Date: Tue, 3 Dec 2024 09:58:56 +0100
Subject: [PATCH] Prevent index creation on over_limit tables

---
 ...ex_sent_notifications_on_issue_email_participant_id.rb | 2 ++
 ...4507_add_merge_request_diffs_project_id_index_async.rb | 2 ++
 ...1121040153_add_merge_request_diffs_project_id_index.rb | 2 ++
 ...155340_prepare_iid_namespace_unique_index_in_issues.rb | 2 ++
 ...1207211418_add_iid_namespace_unique_index_to_issues.rb | 2 ++
 ...o_events_author_group_action_target_type_created_at.rb | 2 +-
 ...owasp_top_10_with_project_id_on_vulnerability_reads.rb | 2 ++
 ...add_index_to_events_author_group_action_target_type.rb | 2 +-
 ...111294_add_index_on_issues_table_tmp_epic_id_column.rb | 2 ++
 ..._schedule_index_merge_requests_on_unmerged_state_id.rb | 2 ++
 ...85542_add_index_merge_requests_on_unmerged_state_id.rb | 2 ++
 ...n_state_report_type_severity_traversal_ids_archived.rb | 2 ++
 ...ex_vulnerability_reads_for_common_group_level_query.rb | 2 ++
 .../20240514121644_replace_issues_milestone_index.rb      | 2 +-
 ...0131_add_issues_milestone_and_id_index_concurrently.rb | 2 +-
 ...create_idx_vulnerability_occurences_on_prim_iden_id.rb | 2 +-
 ...2511_add_index_owasp_top_10_for_group_level_reports.rb | 2 ++
 .../20240719033346_tmp_index_on_vulnerability_reads.rb    | 2 ++
 ...are_index_vulnerability_finding_links_on_project_id.rb | 2 ++
 ...05205657_tmp_index_for_owasp_on_vulnerability_reads.rb | 2 ++
 ...dd_revised_idx_owasp_top_10_for_group_level_reports.rb | 2 ++
 ...0_async_add_index_on_events_personal_namespace_id_2.rb | 2 +-
 ..._index_on_events_personal_namespace_id_self_managed.rb | 2 +-
 ...d_index_on_vulnerability_reads_for_filtered_removal.rb | 2 ++
 ...ndex_on_issues_by_project_correct_type_where_closed.rb | 2 ++
 ...on_issues_project_health_id_desc_state_correct_type.rb | 2 ++
 ..._on_issues_project_health_id_asc_state_correct_type.rb | 2 ++
 ...dex_on_issues_correct_type_project_created_at_state.rb | 2 ++
 ...ndex_on_issues_by_project_correct_type_where_closed.rb | 2 ++
 ...on_issues_project_health_id_desc_state_correct_type.rb | 2 ++
 ..._on_issues_project_health_id_asc_state_correct_type.rb | 2 ++
 ...dex_on_issues_correct_type_project_created_at_state.rb | 2 ++
 ...6125627_update_sent_notifications_index_on_noteable.rb | 2 ++
 ..._sent_notifications_index_on_noteable_synchronously.rb | 2 ++
 rubocop/cop/migration/prevent_index_creation.rb           | 2 +-
 rubocop/migration_helpers.rb                              | 8 ++++++--
 spec/rubocop/cop/migration/prevent_index_creation_spec.rb | 2 +-
 37 files changed, 69 insertions(+), 11 deletions(-)

diff --git a/db/migrate/20240104142200_add_index_sent_notifications_on_issue_email_participant_id.rb b/db/migrate/20240104142200_add_index_sent_notifications_on_issue_email_participant_id.rb
index c9b755294702d..7a564f13fb0fc 100644
--- a/db/migrate/20240104142200_add_index_sent_notifications_on_issue_email_participant_id.rb
+++ b/db/migrate/20240104142200_add_index_sent_notifications_on_issue_email_participant_id.rb
@@ -8,7 +8,9 @@ class AddIndexSentNotificationsOnIssueEmailParticipantId < Gitlab::Database::Mig
   INDEX_NAME = 'index_sent_notifications_on_issue_email_participant_id'
 
   def up
+    # rubocop:disable Migration/PreventIndexCreation -- Legacy migration
     add_concurrent_index :sent_notifications, :issue_email_participant_id, name: INDEX_NAME
+    # rubocop:enable Migration/PreventIndexCreation
   end
 
   def down
diff --git a/db/post_migrate/20231114034507_add_merge_request_diffs_project_id_index_async.rb b/db/post_migrate/20231114034507_add_merge_request_diffs_project_id_index_async.rb
index 1c783b922ae86..a55e56e600e4a 100644
--- a/db/post_migrate/20231114034507_add_merge_request_diffs_project_id_index_async.rb
+++ b/db/post_migrate/20231114034507_add_merge_request_diffs_project_id_index_async.rb
@@ -7,7 +7,9 @@ class AddMergeRequestDiffsProjectIdIndexAsync < Gitlab::Database::Migration[2.2]
   INDEX_NAME = 'index_merge_request_diffs_on_project_id'
 
   def up
+    # rubocop:disable Migration/PreventIndexCreation -- Legacy migration
     prepare_async_index :merge_request_diffs, :project_id, name: INDEX_NAME
+    # rubocop:enable Migration/PreventIndexCreation
   end
 
   def down
diff --git a/db/post_migrate/20231121040153_add_merge_request_diffs_project_id_index.rb b/db/post_migrate/20231121040153_add_merge_request_diffs_project_id_index.rb
index 5576e9d534e8f..b71e03e20fb29 100644
--- a/db/post_migrate/20231121040153_add_merge_request_diffs_project_id_index.rb
+++ b/db/post_migrate/20231121040153_add_merge_request_diffs_project_id_index.rb
@@ -7,7 +7,9 @@ class AddMergeRequestDiffsProjectIdIndex < Gitlab::Database::Migration[2.2]
   INDEX_NAME = 'index_merge_request_diffs_on_project_id'
 
   def up
+    # rubocop:disable Migration/PreventIndexCreation -- Legacy migration
     add_concurrent_index :merge_request_diffs, :project_id, name: INDEX_NAME
+    # rubocop:enable Migration/PreventIndexCreation
   end
 
   def down
diff --git a/db/post_migrate/20231207155340_prepare_iid_namespace_unique_index_in_issues.rb b/db/post_migrate/20231207155340_prepare_iid_namespace_unique_index_in_issues.rb
index a0149a79f83f9..d5e4aadc5c3ff 100644
--- a/db/post_migrate/20231207155340_prepare_iid_namespace_unique_index_in_issues.rb
+++ b/db/post_migrate/20231207155340_prepare_iid_namespace_unique_index_in_issues.rb
@@ -7,7 +7,9 @@ class PrepareIidNamespaceUniqueIndexInIssues < Gitlab::Database::Migration[2.2]
 
   # TODO: Index to be created synchronously in https://gitlab.com/gitlab-org/gitlab/-/issues/435856
   def up
+    # rubocop:disable Migration/PreventIndexCreation -- Legacy migration
     prepare_async_index :issues, [:namespace_id, :iid], unique: true, name: INDEX_NAME
+    # rubocop:enable Migration/PreventIndexCreation
   end
 
   def down
diff --git a/db/post_migrate/20231207211418_add_iid_namespace_unique_index_to_issues.rb b/db/post_migrate/20231207211418_add_iid_namespace_unique_index_to_issues.rb
index 4c2439f33ea77..490d91ea13157 100644
--- a/db/post_migrate/20231207211418_add_iid_namespace_unique_index_to_issues.rb
+++ b/db/post_migrate/20231207211418_add_iid_namespace_unique_index_to_issues.rb
@@ -8,7 +8,9 @@ class AddIidNamespaceUniqueIndexToIssues < Gitlab::Database::Migration[2.2]
   milestone '16.8'
 
   def up
+    # rubocop:disable Migration/PreventIndexCreation -- Legacy migration
     add_concurrent_index :issues, [:namespace_id, :iid], name: INDEX_NAME, unique: true
+    # rubocop:enable Migration/PreventIndexCreation
   end
 
   def down
diff --git a/db/post_migrate/20231215130625_schedule_index_to_events_author_group_action_target_type_created_at.rb b/db/post_migrate/20231215130625_schedule_index_to_events_author_group_action_target_type_created_at.rb
index 1e3658aa69741..bddecce9c054b 100644
--- a/db/post_migrate/20231215130625_schedule_index_to_events_author_group_action_target_type_created_at.rb
+++ b/db/post_migrate/20231215130625_schedule_index_to_events_author_group_action_target_type_created_at.rb
@@ -7,7 +7,7 @@ class ScheduleIndexToEventsAuthorGroupActionTargetTypeCreatedAt < Gitlab::Databa
   COLUMNS = [:author_id, :group_id, :action, :target_type, :created_at]
 
   def up
-    prepare_async_index :events, COLUMNS, name: INDEX_NAME
+    prepare_async_index :events, COLUMNS, name: INDEX_NAME # rubocop:disable Migration/PreventIndexCreation -- Legacy migration
   end
 
   def down
diff --git a/db/post_migrate/20240104223119_add_index_owasp_top_10_with_project_id_on_vulnerability_reads.rb b/db/post_migrate/20240104223119_add_index_owasp_top_10_with_project_id_on_vulnerability_reads.rb
index 99a2dccc8f54d..7af57a7f40082 100644
--- a/db/post_migrate/20240104223119_add_index_owasp_top_10_with_project_id_on_vulnerability_reads.rb
+++ b/db/post_migrate/20240104223119_add_index_owasp_top_10_with_project_id_on_vulnerability_reads.rb
@@ -8,7 +8,9 @@ class AddIndexOwaspTop10WithProjectIdOnVulnerabilityReads < Gitlab::Database::Mi
   INDEX_NAME = 'index_vuln_reads_on_project_id_owasp_top_10'
 
   def up
+    # rubocop:disable Migration/PreventIndexCreation -- Legacy migration
     add_concurrent_index :vulnerability_reads, [:project_id, :owasp_top_10], name: INDEX_NAME
+    # rubocop:enable Migration/PreventIndexCreation
   end
 
   def down
diff --git a/db/post_migrate/20240112143548_add_index_to_events_author_group_action_target_type.rb b/db/post_migrate/20240112143548_add_index_to_events_author_group_action_target_type.rb
index 88e5f95ef68fe..70d7c325a68d2 100644
--- a/db/post_migrate/20240112143548_add_index_to_events_author_group_action_target_type.rb
+++ b/db/post_migrate/20240112143548_add_index_to_events_author_group_action_target_type.rb
@@ -9,7 +9,7 @@ class AddIndexToEventsAuthorGroupActionTargetType < Gitlab::Database::Migration[
   COLUMNS = [:author_id, :group_id, :action, :target_type, :created_at]
 
   def up
-    add_concurrent_index :events, COLUMNS, name: INDEX_NAME
+    add_concurrent_index :events, COLUMNS, name: INDEX_NAME # rubocop:disable Migration/PreventIndexCreation -- Legacy migration
   end
 
   def down
diff --git a/db/post_migrate/20240201111294_add_index_on_issues_table_tmp_epic_id_column.rb b/db/post_migrate/20240201111294_add_index_on_issues_table_tmp_epic_id_column.rb
index 76e8323973b9c..34dbd32d35a89 100644
--- a/db/post_migrate/20240201111294_add_index_on_issues_table_tmp_epic_id_column.rb
+++ b/db/post_migrate/20240201111294_add_index_on_issues_table_tmp_epic_id_column.rb
@@ -7,7 +7,9 @@ class AddIndexOnIssuesTableTmpEpicIdColumn < Gitlab::Database::Migration[2.2]
   INDEX_NAME = "tmp_index_issues_on_tmp_epic_id"
 
   def up
+    # rubocop:disable Migration/PreventIndexCreation -- Legacy migration
     add_concurrent_index :issues, :tmp_epic_id, unique: true, name: INDEX_NAME
+    # rubocop:enable Migration/PreventIndexCreation
   end
 
   def down
diff --git a/db/post_migrate/20240213125429_schedule_index_merge_requests_on_unmerged_state_id.rb b/db/post_migrate/20240213125429_schedule_index_merge_requests_on_unmerged_state_id.rb
index e7b1fbe68a48e..ef25716edceb5 100644
--- a/db/post_migrate/20240213125429_schedule_index_merge_requests_on_unmerged_state_id.rb
+++ b/db/post_migrate/20240213125429_schedule_index_merge_requests_on_unmerged_state_id.rb
@@ -7,7 +7,9 @@ class ScheduleIndexMergeRequestsOnUnmergedStateId < Gitlab::Database::Migration[
   TABLE_NAME = :merge_requests
 
   def up
+    # rubocop:disable Migration/PreventIndexCreation -- Legacy migration
     prepare_async_index(TABLE_NAME, :id, name: INDEX_NAME, where: "state_id <> 3")
+    # rubocop:enable Migration/PreventIndexCreation
   end
 
   def down
diff --git a/db/post_migrate/20240325085542_add_index_merge_requests_on_unmerged_state_id.rb b/db/post_migrate/20240325085542_add_index_merge_requests_on_unmerged_state_id.rb
index 800dc23e7e562..9e08088480ec7 100644
--- a/db/post_migrate/20240325085542_add_index_merge_requests_on_unmerged_state_id.rb
+++ b/db/post_migrate/20240325085542_add_index_merge_requests_on_unmerged_state_id.rb
@@ -9,7 +9,9 @@ class AddIndexMergeRequestsOnUnmergedStateId < Gitlab::Database::Migration[2.2]
   TABLE_NAME = :merge_requests
 
   def up
+    # rubocop:disable Migration/PreventIndexCreation -- Legacy migration
     add_concurrent_index(TABLE_NAME, :id, name: INDEX_NAME, where: "state_id <> 3")
+    # rubocop:enable Migration/PreventIndexCreation
   end
 
   def down
diff --git a/db/post_migrate/20240410104838_index_vulnerability_reads_on_state_report_type_severity_traversal_ids_archived.rb b/db/post_migrate/20240410104838_index_vulnerability_reads_on_state_report_type_severity_traversal_ids_archived.rb
index 6b750eb3fe018..599612f72019b 100644
--- a/db/post_migrate/20240410104838_index_vulnerability_reads_on_state_report_type_severity_traversal_ids_archived.rb
+++ b/db/post_migrate/20240410104838_index_vulnerability_reads_on_state_report_type_severity_traversal_ids_archived.rb
@@ -8,7 +8,9 @@ class IndexVulnerabilityReadsOnStateReportTypeSeverityTraversalIdsArchived < Git
   COLUMNS = %i[resolved_on_default_branch state report_type severity traversal_ids vulnerability_id].freeze
 
   def up
+    # rubocop:disable Migration/PreventIndexCreation -- Legacy migration
     add_concurrent_index :vulnerability_reads, COLUMNS, name: INDEX_NAME, where: 'archived = false'
+    # rubocop:enable Migration/PreventIndexCreation
   end
 
   def down
diff --git a/db/post_migrate/20240502120047_index_vulnerability_reads_for_common_group_level_query.rb b/db/post_migrate/20240502120047_index_vulnerability_reads_for_common_group_level_query.rb
index 7f1eb48e627dd..5f3ab47f2c2d8 100644
--- a/db/post_migrate/20240502120047_index_vulnerability_reads_for_common_group_level_query.rb
+++ b/db/post_migrate/20240502120047_index_vulnerability_reads_for_common_group_level_query.rb
@@ -8,7 +8,9 @@ class IndexVulnerabilityReadsForCommonGroupLevelQuery < Gitlab::Database::Migrat
   milestone '17.0'
 
   def up
+    # rubocop:disable Migration/PreventIndexCreation -- Legacy migration
     add_concurrent_index :vulnerability_reads, COLUMNS, name: INDEX_NAME, where: 'archived = false'
+    # rubocop:enable Migration/PreventIndexCreation
   end
 
   def down
diff --git a/db/post_migrate/20240514121644_replace_issues_milestone_index.rb b/db/post_migrate/20240514121644_replace_issues_milestone_index.rb
index eb3d67ae8dfa4..23f50215b4b2e 100644
--- a/db/post_migrate/20240514121644_replace_issues_milestone_index.rb
+++ b/db/post_migrate/20240514121644_replace_issues_milestone_index.rb
@@ -7,7 +7,7 @@ class ReplaceIssuesMilestoneIndex < Gitlab::Database::Migration[2.2]
 
   # TODO: Index to be created synchronously in https://gitlab.com/gitlab-org/gitlab/-/issues/461627
   def up
-    prepare_async_index :issues, %i[milestone_id id], name: INDEX_NAME
+    prepare_async_index :issues, %i[milestone_id id], name: INDEX_NAME # rubocop:disable Migration/PreventIndexCreation -- Legacy migration
   end
 
   def down
diff --git a/db/post_migrate/20240531140131_add_issues_milestone_and_id_index_concurrently.rb b/db/post_migrate/20240531140131_add_issues_milestone_and_id_index_concurrently.rb
index 94f234f67b912..10fa634f21549 100644
--- a/db/post_migrate/20240531140131_add_issues_milestone_and_id_index_concurrently.rb
+++ b/db/post_migrate/20240531140131_add_issues_milestone_and_id_index_concurrently.rb
@@ -8,7 +8,7 @@ class AddIssuesMilestoneAndIdIndexConcurrently < Gitlab::Database::Migration[2.2
   disable_ddl_transaction!
 
   def up
-    add_concurrent_index :issues, %i[milestone_id id], name: INDEX_NAME
+    add_concurrent_index :issues, %i[milestone_id id], name: INDEX_NAME # rubocop:disable Migration/PreventIndexCreation -- Legacy migration
   end
 
   def down
diff --git a/db/post_migrate/20240610125054_create_idx_vulnerability_occurences_on_prim_iden_id.rb b/db/post_migrate/20240610125054_create_idx_vulnerability_occurences_on_prim_iden_id.rb
index e1ca68e1f4046..5ab8fc80d759d 100644
--- a/db/post_migrate/20240610125054_create_idx_vulnerability_occurences_on_prim_iden_id.rb
+++ b/db/post_migrate/20240610125054_create_idx_vulnerability_occurences_on_prim_iden_id.rb
@@ -9,7 +9,7 @@ class CreateIdxVulnerabilityOccurencesOnPrimIdenId < Gitlab::Database::Migration
 
   # -- This index was created async previously, check https://gitlab.com/gitlab-org/gitlab/-/merge_requests/131647
   def up
-    add_concurrent_index(
+    add_concurrent_index( # rubocop:disable Migration/PreventIndexCreation -- Legacy migration
       TABLE_NAME, [:primary_identifier_id, :vulnerability_id],
       name: NEW_INDEX_NAME
     )
diff --git a/db/post_migrate/20240703142511_add_index_owasp_top_10_for_group_level_reports.rb b/db/post_migrate/20240703142511_add_index_owasp_top_10_for_group_level_reports.rb
index a2631fe43db0a..1f8082be50645 100644
--- a/db/post_migrate/20240703142511_add_index_owasp_top_10_for_group_level_reports.rb
+++ b/db/post_migrate/20240703142511_add_index_owasp_top_10_for_group_level_reports.rb
@@ -8,7 +8,9 @@ class AddIndexOwaspTop10ForGroupLevelReports < Gitlab::Database::Migration[2.2]
 
   # -- Legacy migration
   def up
+    # rubocop:disable Migration/PreventIndexCreation -- Legacy migration
     add_concurrent_index :vulnerability_reads, [:owasp_top_10, :state, :report_type,
+      # rubocop:enable Migration/PreventIndexCreation
       :severity, :traversal_ids, :vulnerability_id, :resolved_on_default_branch],
       where: 'archived = false',
       name: INDEX_NAME
diff --git a/db/post_migrate/20240719033346_tmp_index_on_vulnerability_reads.rb b/db/post_migrate/20240719033346_tmp_index_on_vulnerability_reads.rb
index c7117461ac575..725dc037da68f 100644
--- a/db/post_migrate/20240719033346_tmp_index_on_vulnerability_reads.rb
+++ b/db/post_migrate/20240719033346_tmp_index_on_vulnerability_reads.rb
@@ -13,7 +13,9 @@ class TmpIndexOnVulnerabilityReads < Gitlab::Database::Migration[2.2]
 
   # -- Legacy migration
   def up
+    # rubocop:disable Migration/PreventIndexCreation -- Legacy migration
     add_concurrent_index TABLE_NAME, :id, name: INDEX_NAME, where: "state = 1"
+    # rubocop:enable Migration/PreventIndexCreation
   end
 
   def down
diff --git a/db/post_migrate/20240729133633_prepare_index_vulnerability_finding_links_on_project_id.rb b/db/post_migrate/20240729133633_prepare_index_vulnerability_finding_links_on_project_id.rb
index 145fb53ad9480..aec20205f5fae 100644
--- a/db/post_migrate/20240729133633_prepare_index_vulnerability_finding_links_on_project_id.rb
+++ b/db/post_migrate/20240729133633_prepare_index_vulnerability_finding_links_on_project_id.rb
@@ -8,7 +8,9 @@ class PrepareIndexVulnerabilityFindingLinksOnProjectId < Gitlab::Database::Migra
 
   # -- Legacy migration
   def up
+    # rubocop:disable Migration/PreventIndexCreation -- Legacy migration
     prepare_async_index :vulnerability_finding_links, :project_id, name: INDEX_NAME
+    # rubocop:enable Migration/PreventIndexCreation
   end
 
   def down
diff --git a/db/post_migrate/20240805205657_tmp_index_for_owasp_on_vulnerability_reads.rb b/db/post_migrate/20240805205657_tmp_index_for_owasp_on_vulnerability_reads.rb
index 3158fc7a8e918..2db1881f74dee 100644
--- a/db/post_migrate/20240805205657_tmp_index_for_owasp_on_vulnerability_reads.rb
+++ b/db/post_migrate/20240805205657_tmp_index_for_owasp_on_vulnerability_reads.rb
@@ -10,7 +10,9 @@ class TmpIndexForOwaspOnVulnerabilityReads < Gitlab::Database::Migration[2.2]
 
   # -- Legacy migration
   def up
+    # rubocop:disable Migration/PreventIndexCreation -- Legacy migration
     add_concurrent_index :vulnerability_reads, COLUMNS, name: INDEX_NAME, where: WHERE_CLAUSE
+    # rubocop:enable Migration/PreventIndexCreation
   end
 
   def down
diff --git a/db/post_migrate/20240828173211_add_revised_idx_owasp_top_10_for_group_level_reports.rb b/db/post_migrate/20240828173211_add_revised_idx_owasp_top_10_for_group_level_reports.rb
index 7074e911f7b7f..d8a45208ed36d 100644
--- a/db/post_migrate/20240828173211_add_revised_idx_owasp_top_10_for_group_level_reports.rb
+++ b/db/post_migrate/20240828173211_add_revised_idx_owasp_top_10_for_group_level_reports.rb
@@ -11,7 +11,9 @@ class AddRevisedIdxOwaspTop10ForGroupLevelReports < Gitlab::Database::Migration[
 
   # -- Legacy migration
   def up
+    # rubocop:disable Migration/PreventIndexCreation -- Legacy migration
     add_concurrent_index :vulnerability_reads, [:owasp_top_10, :state, :report_type, :resolved_on_default_branch,
+      # rubocop:enable Migration/PreventIndexCreation
       :severity, :traversal_ids, :vulnerability_id],
       where: 'archived = false',
       name: INDEX_NAME
diff --git a/db/post_migrate/20240905023750_async_add_index_on_events_personal_namespace_id_2.rb b/db/post_migrate/20240905023750_async_add_index_on_events_personal_namespace_id_2.rb
index 7d1d9648d156b..3ce6679f1c504 100644
--- a/db/post_migrate/20240905023750_async_add_index_on_events_personal_namespace_id_2.rb
+++ b/db/post_migrate/20240905023750_async_add_index_on_events_personal_namespace_id_2.rb
@@ -9,7 +9,7 @@ class AsyncAddIndexOnEventsPersonalNamespaceId2 < Gitlab::Database::Migration[2.
   def up
     return unless Gitlab.com_except_jh?
 
-    prepare_async_index :events, :personal_namespace_id, name: INDEX_NAME,
+    prepare_async_index :events, :personal_namespace_id, name: INDEX_NAME, # rubocop:disable Migration/PreventIndexCreation -- Legacy migration
       where: 'personal_namespace_id IS NOT NULL'
   end
 
diff --git a/db/post_migrate/20240909230748_add_index_on_events_personal_namespace_id_self_managed.rb b/db/post_migrate/20240909230748_add_index_on_events_personal_namespace_id_self_managed.rb
index a36498752de5d..c3b5de0fa1b6e 100644
--- a/db/post_migrate/20240909230748_add_index_on_events_personal_namespace_id_self_managed.rb
+++ b/db/post_migrate/20240909230748_add_index_on_events_personal_namespace_id_self_managed.rb
@@ -11,7 +11,7 @@ class AddIndexOnEventsPersonalNamespaceIdSelfManaged < Gitlab::Database::Migrati
   def up
     return if Gitlab.com_except_jh?
 
-    add_concurrent_index :events,
+    add_concurrent_index :events, # rubocop:disable Migration/PreventIndexCreation -- Legacy migration
       :personal_namespace_id,
       where: 'personal_namespace_id IS NOT NULL',
       name: INDEX
diff --git a/db/post_migrate/20240923114603_add_index_on_vulnerability_reads_for_filtered_removal.rb b/db/post_migrate/20240923114603_add_index_on_vulnerability_reads_for_filtered_removal.rb
index 1d3e5f10a62b6..daa6d7c1e6689 100644
--- a/db/post_migrate/20240923114603_add_index_on_vulnerability_reads_for_filtered_removal.rb
+++ b/db/post_migrate/20240923114603_add_index_on_vulnerability_reads_for_filtered_removal.rb
@@ -9,7 +9,9 @@ class AddIndexOnVulnerabilityReadsForFilteredRemoval < Gitlab::Database::Migrati
 
   # -- Legacy migration
   def up
+    # rubocop:disable Migration/PreventIndexCreation -- Legacy migration
     add_concurrent_index :vulnerability_reads, %i[project_id resolved_on_default_branch], name: INDEX_NAME
+    # rubocop:enable Migration/PreventIndexCreation
   end
 
   def down
diff --git a/db/post_migrate/20241021221146_prepare_async_index_on_issues_by_project_correct_type_where_closed.rb b/db/post_migrate/20241021221146_prepare_async_index_on_issues_by_project_correct_type_where_closed.rb
index 2f08cec6b0215..00684157988da 100644
--- a/db/post_migrate/20241021221146_prepare_async_index_on_issues_by_project_correct_type_where_closed.rb
+++ b/db/post_migrate/20241021221146_prepare_async_index_on_issues_by_project_correct_type_where_closed.rb
@@ -8,7 +8,9 @@ class PrepareAsyncIndexOnIssuesByProjectCorrectTypeWhereClosed < Gitlab::Databas
   def up
     # Temporary index to be removed with https://gitlab.com/gitlab-org/gitlab/-/issues/500165
     # TODO: Index to be created synchronously in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/170005
+    # rubocop:disable Migration/PreventIndexCreation -- Legacy migration
     prepare_async_index :issues, # -- Tmp index needed to fix work item type ids
+      # rubocop:enable Migration/PreventIndexCreation
       [:project_id, :correct_work_item_type_id, :closed_at],
       where: 'state_id = 2',
       name: INDEX_NAME
diff --git a/db/post_migrate/20241021221626_prepare_async_index_on_issues_project_health_id_desc_state_correct_type.rb b/db/post_migrate/20241021221626_prepare_async_index_on_issues_project_health_id_desc_state_correct_type.rb
index 4c20d1fe744a7..8503ccf31a8a4 100644
--- a/db/post_migrate/20241021221626_prepare_async_index_on_issues_project_health_id_desc_state_correct_type.rb
+++ b/db/post_migrate/20241021221626_prepare_async_index_on_issues_project_health_id_desc_state_correct_type.rb
@@ -9,7 +9,9 @@ class PrepareAsyncIndexOnIssuesProjectHealthIdDescStateCorrectType < Gitlab::Dat
   def up
     # Temporary index to be removed with https://gitlab.com/gitlab-org/gitlab/-/issues/500165
     # TODO: Index to be created synchronously in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/170005
+    # rubocop:disable Migration/PreventIndexCreation -- Legacy migration
     prepare_async_index :issues, # -- Tmp index needed to fix work item type ids
+      # rubocop:enable Migration/PreventIndexCreation
       [:project_id, :health_status, :id, :state_id, :correct_work_item_type_id],
       order: { health_status: 'DESC NULLS LAST', id: :desc },
       name: INDEX_NAME
diff --git a/db/post_migrate/20241021221755_prepare_async_index_on_issues_project_health_id_asc_state_correct_type.rb b/db/post_migrate/20241021221755_prepare_async_index_on_issues_project_health_id_asc_state_correct_type.rb
index a32e782a7ddd8..add09338380b0 100644
--- a/db/post_migrate/20241021221755_prepare_async_index_on_issues_project_health_id_asc_state_correct_type.rb
+++ b/db/post_migrate/20241021221755_prepare_async_index_on_issues_project_health_id_asc_state_correct_type.rb
@@ -9,7 +9,9 @@ class PrepareAsyncIndexOnIssuesProjectHealthIdAscStateCorrectType < Gitlab::Data
   def up
     # Temporary index to be removed with https://gitlab.com/gitlab-org/gitlab/-/issues/500165
     # TODO: Index to be created synchronously in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/170005
+    # rubocop:disable Migration/PreventIndexCreation -- Legacy migration
     prepare_async_index :issues, # -- Tmp index needed to fix work item type ids
+      # rubocop:enable Migration/PreventIndexCreation
       [:project_id, :health_status, :id, :state_id, :correct_work_item_type_id],
       order: { health_status: 'ASC NULLS LAST', id: :desc },
       name: INDEX_NAME
diff --git a/db/post_migrate/20241021221938_prepare_async_index_on_issues_correct_type_project_created_at_state.rb b/db/post_migrate/20241021221938_prepare_async_index_on_issues_correct_type_project_created_at_state.rb
index 3103ceebc8daf..e4cf21a27eeb7 100644
--- a/db/post_migrate/20241021221938_prepare_async_index_on_issues_correct_type_project_created_at_state.rb
+++ b/db/post_migrate/20241021221938_prepare_async_index_on_issues_correct_type_project_created_at_state.rb
@@ -9,7 +9,9 @@ class PrepareAsyncIndexOnIssuesCorrectTypeProjectCreatedAtState < Gitlab::Databa
   def up
     # Temporary index to be removed with https://gitlab.com/gitlab-org/gitlab/-/issues/500165
     # TODO: Index to be created synchronously in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/170005
+    # rubocop:disable Migration/PreventIndexCreation -- Legacy migration
     prepare_async_index :issues, # -- Tmp index needed to fix work item type ids
+      # rubocop:enable Migration/PreventIndexCreation
       [:correct_work_item_type_id, :project_id, :created_at, :state_id],
       name: INDEX_NAME
   end
diff --git a/db/post_migrate/20241105213841_create_tmp_index_on_issues_by_project_correct_type_where_closed.rb b/db/post_migrate/20241105213841_create_tmp_index_on_issues_by_project_correct_type_where_closed.rb
index 17a47df2d91e2..688905c5da9da 100644
--- a/db/post_migrate/20241105213841_create_tmp_index_on_issues_by_project_correct_type_where_closed.rb
+++ b/db/post_migrate/20241105213841_create_tmp_index_on_issues_by_project_correct_type_where_closed.rb
@@ -8,7 +8,9 @@ class CreateTmpIndexOnIssuesByProjectCorrectTypeWhereClosed < Gitlab::Database::
 
   def up
     # Temporary index to be removed with https://gitlab.com/gitlab-org/gitlab/-/issues/500165
+    # rubocop:disable Migration/PreventIndexCreation -- Legacy migration
     add_concurrent_index :issues, # -- Tmp index needed to fix work item type ids
+      # rubocop:enable Migration/PreventIndexCreation
       [:project_id, :correct_work_item_type_id, :closed_at],
       where: 'state_id = 2',
       name: INDEX_NAME
diff --git a/db/post_migrate/20241105215409_create_tmp_index_on_issues_project_health_id_desc_state_correct_type.rb b/db/post_migrate/20241105215409_create_tmp_index_on_issues_project_health_id_desc_state_correct_type.rb
index c6e1e462b2be8..12a24feff6921 100644
--- a/db/post_migrate/20241105215409_create_tmp_index_on_issues_project_health_id_desc_state_correct_type.rb
+++ b/db/post_migrate/20241105215409_create_tmp_index_on_issues_project_health_id_desc_state_correct_type.rb
@@ -8,7 +8,9 @@ class CreateTmpIndexOnIssuesProjectHealthIdDescStateCorrectType < Gitlab::Databa
 
   def up
     # Temporary index to be removed with https://gitlab.com/gitlab-org/gitlab/-/issues/500165
+    # rubocop:disable Migration/PreventIndexCreation -- Legacy migration
     add_concurrent_index :issues, # -- Tmp index needed to fix work item type ids
+      # rubocop:enable Migration/PreventIndexCreation
       [:project_id, :health_status, :id, :state_id, :correct_work_item_type_id],
       order: { health_status: 'DESC NULLS LAST', id: :desc },
       name: INDEX_NAME
diff --git a/db/post_migrate/20241105215907_create_tmp_index_on_issues_project_health_id_asc_state_correct_type.rb b/db/post_migrate/20241105215907_create_tmp_index_on_issues_project_health_id_asc_state_correct_type.rb
index a4091559d2ced..edd2c1f690046 100644
--- a/db/post_migrate/20241105215907_create_tmp_index_on_issues_project_health_id_asc_state_correct_type.rb
+++ b/db/post_migrate/20241105215907_create_tmp_index_on_issues_project_health_id_asc_state_correct_type.rb
@@ -8,7 +8,9 @@ class CreateTmpIndexOnIssuesProjectHealthIdAscStateCorrectType < Gitlab::Databas
 
   def up
     # Temporary index to be removed with https://gitlab.com/gitlab-org/gitlab/-/issues/500165
+    # rubocop:disable Migration/PreventIndexCreation -- Legacy migration
     add_concurrent_index :issues, # -- Tmp index needed to fix work item type ids
+      # rubocop:enable Migration/PreventIndexCreation
       [:project_id, :health_status, :id, :state_id, :correct_work_item_type_id],
       order: { health_status: 'ASC NULLS LAST', id: :desc },
       name: INDEX_NAME
diff --git a/db/post_migrate/20241105220155_create_tmp_index_on_issues_correct_type_project_created_at_state.rb b/db/post_migrate/20241105220155_create_tmp_index_on_issues_correct_type_project_created_at_state.rb
index 33dd943726253..99d46fc7e5899 100644
--- a/db/post_migrate/20241105220155_create_tmp_index_on_issues_correct_type_project_created_at_state.rb
+++ b/db/post_migrate/20241105220155_create_tmp_index_on_issues_correct_type_project_created_at_state.rb
@@ -8,7 +8,9 @@ class CreateTmpIndexOnIssuesCorrectTypeProjectCreatedAtState < Gitlab::Database:
 
   def up
     # Temporary index to be removed with https://gitlab.com/gitlab-org/gitlab/-/issues/500165
+    # rubocop:disable Migration/PreventIndexCreation -- Legacy migration
     add_concurrent_index :issues, # -- Tmp index needed to fix work item type ids
+      # rubocop:enable Migration/PreventIndexCreation
       [:correct_work_item_type_id, :project_id, :created_at, :state_id],
       name: INDEX_NAME
   end
diff --git a/db/post_migrate/20241106125627_update_sent_notifications_index_on_noteable.rb b/db/post_migrate/20241106125627_update_sent_notifications_index_on_noteable.rb
index dc4e4232d6aa6..9354a8a79b38d 100644
--- a/db/post_migrate/20241106125627_update_sent_notifications_index_on_noteable.rb
+++ b/db/post_migrate/20241106125627_update_sent_notifications_index_on_noteable.rb
@@ -15,7 +15,9 @@ class UpdateSentNotificationsIndexOnNoteable < Gitlab::Database::Migration[2.2]
   # "index_sent_notifications_on_noteable_type_noteable_id_id" btree (noteable_id, id) WHERE noteable_type = 'Issue'
   # to improve iterating over issue related sent notification records in batches.
   def up
+    # rubocop:disable Migration/PreventIndexCreation -- Legacy migration
     prepare_async_index :sent_notifications, COLUMN_NAMES, where: "noteable_type = 'Issue'", name: INDEX_NAME
+    # rubocop:enable Migration/PreventIndexCreation
   end
 
   def down
diff --git a/db/post_migrate/20241129104531_create_sent_notifications_index_on_noteable_synchronously.rb b/db/post_migrate/20241129104531_create_sent_notifications_index_on_noteable_synchronously.rb
index 13cb20c5069f4..ac02f3da4e150 100644
--- a/db/post_migrate/20241129104531_create_sent_notifications_index_on_noteable_synchronously.rb
+++ b/db/post_migrate/20241129104531_create_sent_notifications_index_on_noteable_synchronously.rb
@@ -10,7 +10,9 @@ class CreateSentNotificationsIndexOnNoteableSynchronously < Gitlab::Database::Mi
   # Creating prepared index in 20241106125627_update_sent_notifications_index_on_noteable
   # https://gitlab.com/gitlab-org/gitlab/-/merge_requests/171687
   def up
+    # rubocop:disable Migration/PreventIndexCreation -- Legacy migration
     add_concurrent_index :sent_notifications, COLUMN_NAMES, where: "noteable_type = 'Issue'", name: INDEX_NAME
+    # rubocop:enable Migration/PreventIndexCreation
   end
 
   def down
diff --git a/rubocop/cop/migration/prevent_index_creation.rb b/rubocop/cop/migration/prevent_index_creation.rb
index 8871886588585..a1e84ad685d81 100644
--- a/rubocop/cop/migration/prevent_index_creation.rb
+++ b/rubocop/cop/migration/prevent_index_creation.rb
@@ -74,7 +74,7 @@ def on_def(node)
         private
 
         def forbidden_tables?(node)
-          FORBIDDEN_TABLES.include?(node.to_sym) || large_tables.include?(node.to_sym)
+          FORBIDDEN_TABLES.include?(node.to_sym) || large_or_over_limit_tables.include?(node.to_sym)
         end
 
         def offense?(node)
diff --git a/rubocop/migration_helpers.rb b/rubocop/migration_helpers.rb
index eb4d5491ff658..c8727aebc8cdc 100644
--- a/rubocop/migration_helpers.rb
+++ b/rubocop/migration_helpers.rb
@@ -32,8 +32,8 @@ def over_limit_tables
       @over_limit_table ||= rubocop_migrations_config.dig('Migration/UpdateLargeTable', 'OverLimitTables')
     end
 
-    def large_tables
-      @large_tables ||= rubocop_migrations_config.dig('Migration/UpdateLargeTable', 'LargeTables')
+    def large_or_over_limit_tables
+      @large_or_over_limit_tables ||= large_tables + over_limit_tables
     end
 
     # Returns true if the given node originated from the db/migrate directory.
@@ -87,6 +87,10 @@ def array_column?(node)
 
     private
 
+    def large_tables
+      @large_tables ||= rubocop_migrations_config.dig('Migration/UpdateLargeTable', 'LargeTables')
+    end
+
     def filepath(node)
       node.location.expression.source_buffer.name
     end
diff --git a/spec/rubocop/cop/migration/prevent_index_creation_spec.rb b/spec/rubocop/cop/migration/prevent_index_creation_spec.rb
index 3a3409b67db87..0cb44a4619bab 100644
--- a/spec/rubocop/cop/migration/prevent_index_creation_spec.rb
+++ b/spec/rubocop/cop/migration/prevent_index_creation_spec.rb
@@ -7,7 +7,7 @@
   include RuboCop::MigrationHelpers
 
   let(:forbidden_tables) do
-    described_class::FORBIDDEN_TABLES + large_tables
+    described_class::FORBIDDEN_TABLES + large_or_over_limit_tables
   end
 
   context 'when in migration' do
-- 
GitLab