From f20e34af2a91a1e3a0c3861ed5b04493b196391c Mon Sep 17 00:00:00 2001
From: Max Orefice <morefice@gitlab.com>
Date: Tue, 4 Jul 2023 13:42:34 +0000
Subject: [PATCH] Drop
 tmp_index_ci_job_artifacts_on_id_expire_at_file_type_trace

Changelog: removed
---
 ...mp_index_job_artifacts_id_and_expire_at.rb | 28 +++++++++++++++++++
 db/schema_migrations/20230626072436           |  1 +
 db/structure.sql                              |  2 --
 3 files changed, 29 insertions(+), 2 deletions(-)
 create mode 100644 db/post_migrate/20230626072436_drop_tmp_index_job_artifacts_id_and_expire_at.rb
 create mode 100644 db/schema_migrations/20230626072436

diff --git a/db/post_migrate/20230626072436_drop_tmp_index_job_artifacts_id_and_expire_at.rb b/db/post_migrate/20230626072436_drop_tmp_index_job_artifacts_id_and_expire_at.rb
new file mode 100644
index 0000000000000..3b986a0dc5d6e
--- /dev/null
+++ b/db/post_migrate/20230626072436_drop_tmp_index_job_artifacts_id_and_expire_at.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+class DropTmpIndexJobArtifactsIdAndExpireAt < Gitlab::Database::Migration[2.1]
+  disable_ddl_transaction!
+
+  TABLE_NAME = :ci_job_artifacts
+  INDEX_NAME = :tmp_index_ci_job_artifacts_on_id_expire_at_file_type_trace
+
+  EXPIRE_AT_ON_22_MIDNIGHT_IN_TIMEZONE_OR_TRACE = <<~SQL
+    (EXTRACT(day FROM timezone('UTC', expire_at)) IN (21, 22, 23)
+    AND EXTRACT(minute FROM timezone('UTC', expire_at)) IN (0, 30, 45)
+    AND EXTRACT(second FROM timezone('UTC', expire_at)) = 0)
+    OR file_type = 3
+  SQL
+
+  def up
+    remove_concurrent_index_by_name(TABLE_NAME, INDEX_NAME)
+  end
+
+  def down
+    add_concurrent_index(
+      TABLE_NAME,
+      :id,
+      where: EXPIRE_AT_ON_22_MIDNIGHT_IN_TIMEZONE_OR_TRACE,
+      name: INDEX_NAME
+    )
+  end
+end
diff --git a/db/schema_migrations/20230626072436 b/db/schema_migrations/20230626072436
new file mode 100644
index 0000000000000..1800699ff544f
--- /dev/null
+++ b/db/schema_migrations/20230626072436
@@ -0,0 +1 @@
+7169f6ef838ca3992d32b92a8cda4063d147c7ffe64cc382d69ae92eca525d0b
\ No newline at end of file
diff --git a/db/structure.sql b/db/structure.sql
index 876ec746da6b3..11cbcfc934493 100644
--- a/db/structure.sql
+++ b/db/structure.sql
@@ -33629,8 +33629,6 @@ CREATE INDEX tmp_idx_vulnerability_occurrences_on_id_where_report_type_7_99 ON v
 
 CREATE INDEX tmp_index_ci_job_artifacts_on_expire_at_where_locked_unknown ON ci_job_artifacts USING btree (expire_at, job_id) WHERE ((locked = 2) AND (expire_at IS NOT NULL));
 
-CREATE INDEX tmp_index_ci_job_artifacts_on_id_expire_at_file_type_trace ON ci_job_artifacts USING btree (id) WHERE (((date_part('day'::text, timezone('UTC'::text, expire_at)) = ANY (ARRAY[(21)::double precision, (22)::double precision, (23)::double precision])) AND (date_part('minute'::text, timezone('UTC'::text, expire_at)) = ANY (ARRAY[(0)::double precision, (30)::double precision, (45)::double precision])) AND (date_part('second'::text, timezone('UTC'::text, expire_at)) = (0)::double precision)) OR (file_type = 3));
-
 CREATE INDEX tmp_index_cis_vulnerability_reads_on_id ON vulnerability_reads USING btree (id) WHERE (report_type = 7);
 
 CREATE INDEX tmp_index_for_backfilling_resource_link_events ON system_note_metadata USING btree (id) WHERE (((action)::text = 'relate_to_parent'::text) OR ((action)::text = 'unrelate_from_parent'::text));
-- 
GitLab