From 9ddde107b8015bc5b503d1d074e64b8b90864448 Mon Sep 17 00:00:00 2001
From: Payton Burdette <pburdette@gitlab.com>
Date: Thu, 15 Dec 2022 10:15:20 -0500
Subject: [PATCH] Add name to ci_builds index

Add name to ci_builds index and
remove old index without name async

Changelog: added
---
 ..._ci_builds_gitlab_monitor_metrics_v1_index.rb | 16 ++++++++++++++++
 ...ove_ci_builds_gitlab_monitor_metrics_index.rb | 15 +++++++++++++++
 db/schema_migrations/20221215150803              |  1 +
 db/schema_migrations/20221215150847              |  1 +
 4 files changed, 33 insertions(+)
 create mode 100644 db/post_migrate/20221215150803_add_ci_builds_gitlab_monitor_metrics_v1_index.rb
 create mode 100644 db/post_migrate/20221215150847_remove_ci_builds_gitlab_monitor_metrics_index.rb
 create mode 100644 db/schema_migrations/20221215150803
 create mode 100644 db/schema_migrations/20221215150847

diff --git a/db/post_migrate/20221215150803_add_ci_builds_gitlab_monitor_metrics_v1_index.rb b/db/post_migrate/20221215150803_add_ci_builds_gitlab_monitor_metrics_v1_index.rb
new file mode 100644
index 0000000000000000..989776633b8d183c
--- /dev/null
+++ b/db/post_migrate/20221215150803_add_ci_builds_gitlab_monitor_metrics_v1_index.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class AddCiBuildsGitlabMonitorMetricsV1Index < Gitlab::Database::Migration[2.1]
+  INDEX_NAME = 'ci_builds_gitlab_monitor_metrics_v1'
+
+  def up
+    prepare_async_index :ci_builds,
+    [:status, :created_at, :project_id, :name],
+    where: "(type)::text = 'Ci::Build'::text",
+    name: INDEX_NAME
+  end
+
+  def down
+    unprepare_async_index_by_name :ci_builds, INDEX_NAME
+  end
+end
diff --git a/db/post_migrate/20221215150847_remove_ci_builds_gitlab_monitor_metrics_index.rb b/db/post_migrate/20221215150847_remove_ci_builds_gitlab_monitor_metrics_index.rb
new file mode 100644
index 0000000000000000..24b43aaacde65228
--- /dev/null
+++ b/db/post_migrate/20221215150847_remove_ci_builds_gitlab_monitor_metrics_index.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class RemoveCiBuildsGitlabMonitorMetricsIndex < Gitlab::Database::Migration[2.1]
+  INDEX_NAME = 'ci_builds_gitlab_monitor_metrics'
+
+  def up
+    prepare_async_index_removal :ci_builds,
+    [:status, :created_at, :project_id],
+    name: INDEX_NAME
+  end
+
+  def down
+    unprepare_async_index_by_name :ci_builds, INDEX_NAME
+  end
+end
diff --git a/db/schema_migrations/20221215150803 b/db/schema_migrations/20221215150803
new file mode 100644
index 0000000000000000..41da682c5706bb72
--- /dev/null
+++ b/db/schema_migrations/20221215150803
@@ -0,0 +1 @@
+2403d4a78eed2eaab07b0b566236da53896bcfaf572a113d05a76e3ee9f21e75
\ No newline at end of file
diff --git a/db/schema_migrations/20221215150847 b/db/schema_migrations/20221215150847
new file mode 100644
index 0000000000000000..fee367756890ed5d
--- /dev/null
+++ b/db/schema_migrations/20221215150847
@@ -0,0 +1 @@
+88973f3aba4c2dfdee825a4c7e8400f0c808098a61183d3566315b5bfc82e070
\ No newline at end of file
-- 
GitLab