Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-06-16 21:25:58 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-06-16 21:25:58 +0300
commita5f4bba440d7f9ea47046a0a561d49adf0a1e6d4 (patch)
treefb69158581673816a8cd895f9d352dcb3c678b1e /db/migrate/20210611100359_rebuild_index_for_cadence_iterations_automation.rb
parentd16b2e8639e99961de6ddc93909f3bb5c1445ba1 (diff)
Add latest changes from gitlab-org/gitlab@14-0-stable-eev14.0.0-rc42
Diffstat (limited to 'db/migrate/20210611100359_rebuild_index_for_cadence_iterations_automation.rb')
-rw-r--r--db/migrate/20210611100359_rebuild_index_for_cadence_iterations_automation.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/db/migrate/20210611100359_rebuild_index_for_cadence_iterations_automation.rb b/db/migrate/20210611100359_rebuild_index_for_cadence_iterations_automation.rb
new file mode 100644
index 00000000000..ecd8bac22be
--- /dev/null
+++ b/db/migrate/20210611100359_rebuild_index_for_cadence_iterations_automation.rb
@@ -0,0 +1,39 @@
+# frozen_string_literal: true
+
+class RebuildIndexForCadenceIterationsAutomation < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ INDEX_NAME = 'cadence_create_iterations_automation'
+
+ disable_ddl_transaction!
+
+ def up
+ return if index_exists_and_is_valid?
+
+ remove_concurrent_index_by_name :iterations_cadences, INDEX_NAME
+
+ disable_statement_timeout do
+ execute(
+ <<-SQL
+ CREATE INDEX CONCURRENTLY #{INDEX_NAME} ON iterations_cadences
+ USING BTREE(automatic, duration_in_weeks, (DATE ((COALESCE("iterations_cadences"."last_run_date", DATE('01-01-1970')) + "iterations_cadences"."duration_in_weeks" * INTERVAL '1 week'))))
+ WHERE duration_in_weeks IS NOT NULL
+ SQL
+ )
+ end
+ end
+
+ def down
+ remove_concurrent_index_by_name :iterations_cadences, INDEX_NAME
+ end
+
+ def index_exists_and_is_valid?
+ execute(
+ <<-SQL
+ SELECT identifier
+ FROM postgres_indexes
+ WHERE identifier LIKE '%#{INDEX_NAME}' AND valid_index=TRUE
+ SQL
+ ).any?
+ end
+end