diff --git a/db/post_migrate/20250909093241_reprepare_tmp_idx_events_where_project_target_type_missing.rb b/db/post_migrate/20250909093241_reprepare_tmp_idx_events_where_project_target_type_missing.rb new file mode 100644 index 0000000000000000000000000000000000000000..18e0e09a216c4b5b06d202632e20d10dd876a9f5 --- /dev/null +++ b/db/post_migrate/20250909093241_reprepare_tmp_idx_events_where_project_target_type_missing.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +class ReprepareTmpIdxEventsWhereProjectTargetTypeMissing < Gitlab::Database::Migration[2.3] + milestone '18.4' + + INDEX_NAME = :tmp_idx_events_where_project_target_type_missing + + PREV_PROJECT_ACTIONS = [1, 5, 8, 9, 11].freeze # Defined in `/app/models/event.rb` + NEW_PROJECT_ACTIONS = [1, 8, 9, 11].freeze # Defined in `/app/models/event.rb` + + def up + unprepare_async_index_by_name :events, INDEX_NAME + + # 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 (#{NEW_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 + + prepare_async_index( + :events, :id, + where: "target_type IS NULL AND action IN (#{PREV_PROJECT_ACTIONS.join(',')}) AND project_id IS NOT NULL", + name: INDEX_NAME + ) + end +end diff --git a/db/schema_migrations/20250909093241 b/db/schema_migrations/20250909093241 new file mode 100644 index 0000000000000000000000000000000000000000..dfa6e33d8c9b53e1c5a31492b4dc6212beddcebc --- /dev/null +++ b/db/schema_migrations/20250909093241 @@ -0,0 +1 @@ +c94aa95e126cdf962140c4367800fdf51852e4f645b0e5c4b4abb8705e0506f5 \ No newline at end of file