Commit 42c49873 authored by Alexandru Croitor's avatar Alexandru Croitor

Rebuild iterations automation index

For some reason the index creation failed on gitlab.com so
we are rebuilding it but we skip recreating the index if index
exists and is valid.

Changelog: fixed
parent a82ee22b
......@@ -8,18 +8,10 @@ class AddIndexForCadenceIterationsAutomation < ActiveRecord::Migration[6.0]
disable_ddl_transaction!
def up
return if index_exists_by_name?(:iterations_cadences, INDEX_NAME)
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
)
# no-op
end
def down
remove_concurrent_index_by_name :iterations_cadences, INDEX_NAME
# no-op
end
end
# 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
9429a8adca0bc85167f64e76d8d72b45d09d4303a01bd9c4ca39560bb4d89799
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment