From d13c032c17d8137c0dcb7ea748f7b25234a994de Mon Sep 17 00:00:00 2001
From: Leonardo Rosa <ldarosa@gitlab.com>
Date: Tue, 7 May 2024 16:47:32 -0300
Subject: [PATCH] Remove duplicated index from
 alert_management_http_integrations

## What does this MR do and why?

Remove duplicated index from `alert_management_http_integrations` table.

### It removes:

Drop `index_alert_management_http_integrations_on_project_id` as it's already covered by:
| Index | Columns |
| ----- | ------ |
| `index_http_integrations_on_project_and_endpoint` | `project_id asc`, `endpoint_identifier asc` |

It is possible that this MR will still need some changes to drop the index from the database.
Currently, the `gitlab-housekeeper` is not always capable of removing all references, so you must check the diff and pipeline failures to confirm if there are any issues.
Ensure that the index exists in the production database by checking Joe Bot trough https://console.postgres.ai/gitlab.
If the index was already removed or if the index it's being removed in another merge request, consider closing this merge request.

This change was generated by
[gitlab-housekeeper](https://gitlab.com/gitlab-org/gitlab/-/tree/master/gems/gitlab-housekeeper)
using the Keeps::RemoveDuplicatedIndexes keep.

To provide feedback on your experience with `gitlab-housekeeper` please comment in
<https://gitlab.com/gitlab-org/gitlab/-/issues/442003>.

Changelog: other
---
 ...agement_http_integrations_on_project_id.rb | 19 +++++++++++++++++++
 db/schema_migrations/20240507194634           |  1 +
 db/structure.sql                              |  2 --
 3 files changed, 20 insertions(+), 2 deletions(-)
 create mode 100644 db/migrate/20240507194634_drop_index_alert_management_http_integrations_on_project_id.rb
 create mode 100644 db/schema_migrations/20240507194634

diff --git a/db/migrate/20240507194634_drop_index_alert_management_http_integrations_on_project_id.rb b/db/migrate/20240507194634_drop_index_alert_management_http_integrations_on_project_id.rb
new file mode 100644
index 0000000000000..ec2fe0ddb5981
--- /dev/null
+++ b/db/migrate/20240507194634_drop_index_alert_management_http_integrations_on_project_id.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class DropIndexAlertManagementHttpIntegrationsOnProjectId < Gitlab::Database::Migration[2.2]
+  milestone '17.0'
+
+  disable_ddl_transaction!
+
+  TABLE_NAME = :alert_management_http_integrations
+  INDEX_NAME = :index_alert_management_http_integrations_on_project_id
+  COLUMN_NAMES = [:project_id]
+
+  def up
+    remove_concurrent_index_by_name(TABLE_NAME, INDEX_NAME)
+  end
+
+  def down
+    add_concurrent_index(TABLE_NAME, COLUMN_NAMES, name: INDEX_NAME)
+  end
+end
diff --git a/db/schema_migrations/20240507194634 b/db/schema_migrations/20240507194634
new file mode 100644
index 0000000000000..61472588a719a
--- /dev/null
+++ b/db/schema_migrations/20240507194634
@@ -0,0 +1 @@
+e59b68e02cc30c3881e9904514b57301dc0bb47ec47a32941165e3f3760e2e61
\ No newline at end of file
diff --git a/db/structure.sql b/db/structure.sql
index f64d462f3bd45..9cc0962fdf411 100644
--- a/db/structure.sql
+++ b/db/structure.sql
@@ -24487,8 +24487,6 @@ CREATE UNIQUE INDEX index_alert_management_alerts_on_project_id_and_iid ON alert
 
 CREATE INDEX index_alert_management_alerts_on_prometheus_alert_id ON alert_management_alerts USING btree (prometheus_alert_id) WHERE (prometheus_alert_id IS NOT NULL);
 
-CREATE INDEX index_alert_management_http_integrations_on_project_id ON alert_management_http_integrations USING btree (project_id);
-
 CREATE UNIQUE INDEX index_alert_user_mentions_on_alert_id ON alert_management_alert_user_mentions USING btree (alert_management_alert_id) WHERE (note_id IS NULL);
 
 CREATE UNIQUE INDEX index_alert_user_mentions_on_alert_id_and_note_id ON alert_management_alert_user_mentions USING btree (alert_management_alert_id, note_id);
-- 
GitLab