From 73f86a7bbd06a3d507dcf4bf50410e3ebe494980 Mon Sep 17 00:00:00 2001 From: Shane Maglangit Date: Thu, 4 Sep 2025 09:31:43 +0800 Subject: [PATCH 1/3] Prepare tmp_idx_events_where_project_target_type_missing database index Changelog: other --- ...vents_where_project_target_type_missing.rb | 22 +++++++++++++++++++ db/schema_migrations/20250904012006 | 1 + spec/db/schema_spec.rb | 2 +- 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 db/post_migrate/20250904012006_prepare_tmp_idx_events_where_project_target_type_missing.rb create mode 100644 db/schema_migrations/20250904012006 diff --git a/db/post_migrate/20250904012006_prepare_tmp_idx_events_where_project_target_type_missing.rb b/db/post_migrate/20250904012006_prepare_tmp_idx_events_where_project_target_type_missing.rb new file mode 100644 index 00000000000000..7c5d9e4cb238be --- /dev/null +++ b/db/post_migrate/20250904012006_prepare_tmp_idx_events_where_project_target_type_missing.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class PrepareTmpIdxEventsWhereProjectTargetTypeMissing < Gitlab::Database::Migration[2.3] + milestone '18.4' + + INDEX_NAME = :tmp_idx_events_where_project_target_type_missing + PROJECT_ACTIONS = [1, 8, 9, 11].freeze # Defined in `/app/models/event.rb` + + def up + # rubocop:disable Migration/PreventIndexCreation -- temporary index for https://gitlab.com/gitlab-org/gitlab/-/issues/565788 + prepare_async_index( + :events, :id, + where: "target_type IS NULL AND action IN (#{PROJECT_ACTIONS.join(',')}) AND project_id IS NOT NULL", + name: INDEX_NAME + ) + # rubocop:enable Migration/PreventIndexCreation + end + + def down + unprepare_async_index_by_name :events, INDEX_NAME + end +end diff --git a/db/schema_migrations/20250904012006 b/db/schema_migrations/20250904012006 new file mode 100644 index 00000000000000..fb35178dc89edf --- /dev/null +++ b/db/schema_migrations/20250904012006 @@ -0,0 +1 @@ +3894e3e2c419f341ea7e58cffbac542fcf6cd930b954d0230041da412e8000ad \ No newline at end of file diff --git a/spec/db/schema_spec.rb b/spec/db/schema_spec.rb index f5ebb788fce7f0..5cd5f22fca0a79 100644 --- a/spec/db/schema_spec.rb +++ b/spec/db/schema_spec.rb @@ -296,7 +296,7 @@ ci_runners: 16, deployments: 18, epics: 19, - events: 16, + events: 17, # Decrement by 1 after the removal of a temporary index https://gitlab.com/gitlab-org/gitlab/-/issues/566147 group_type_ci_runners: 17, instance_type_ci_runners: 17, issues: 32, -- GitLab From 429a6d03dfa0b504322ab3584a5987adddb9b29e Mon Sep 17 00:00:00 2001 From: Shane Maglangit Date: Thu, 4 Sep 2025 13:45:36 +0800 Subject: [PATCH 2/3] Revert index count exception --- spec/db/schema_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/db/schema_spec.rb b/spec/db/schema_spec.rb index 5cd5f22fca0a79..f5ebb788fce7f0 100644 --- a/spec/db/schema_spec.rb +++ b/spec/db/schema_spec.rb @@ -296,7 +296,7 @@ ci_runners: 16, deployments: 18, epics: 19, - events: 17, # Decrement by 1 after the removal of a temporary index https://gitlab.com/gitlab-org/gitlab/-/issues/566147 + events: 16, group_type_ci_runners: 17, instance_type_ci_runners: 17, issues: 32, -- GitLab From 565cc884be19d92a4ae943d12052142190f38af3 Mon Sep 17 00:00:00 2001 From: Shane Maglangit Date: Fri, 5 Sep 2025 14:39:03 +0800 Subject: [PATCH 3/3] Index push events --- ..._prepare_tmp_idx_events_where_project_target_type_missing.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/post_migrate/20250904012006_prepare_tmp_idx_events_where_project_target_type_missing.rb b/db/post_migrate/20250904012006_prepare_tmp_idx_events_where_project_target_type_missing.rb index 7c5d9e4cb238be..7a4a70f28129f2 100644 --- a/db/post_migrate/20250904012006_prepare_tmp_idx_events_where_project_target_type_missing.rb +++ b/db/post_migrate/20250904012006_prepare_tmp_idx_events_where_project_target_type_missing.rb @@ -4,7 +4,7 @@ class PrepareTmpIdxEventsWhereProjectTargetTypeMissing < Gitlab::Database::Migra milestone '18.4' INDEX_NAME = :tmp_idx_events_where_project_target_type_missing - PROJECT_ACTIONS = [1, 8, 9, 11].freeze # Defined in `/app/models/event.rb` + PROJECT_ACTIONS = [1, 5, 8, 9, 11].freeze # Defined in `/app/models/event.rb` def up # rubocop:disable Migration/PreventIndexCreation -- temporary index for https://gitlab.com/gitlab-org/gitlab/-/issues/565788 -- GitLab