Commit 1aa67247 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Add temporary partial index to speed up the migration

Closes #32469
parent 01a7f333
...@@ -8,6 +8,7 @@ class UpateRetriedForCiBuild < ActiveRecord::Migration ...@@ -8,6 +8,7 @@ class UpateRetriedForCiBuild < ActiveRecord::Migration
def up def up
disable_statement_timeout disable_statement_timeout
with_temporary_partial_index do
latest_id = <<-SQL.strip_heredoc latest_id = <<-SQL.strip_heredoc
SELECT MAX(ci_builds2.id) SELECT MAX(ci_builds2.id)
FROM ci_builds ci_builds2 FROM ci_builds ci_builds2
...@@ -23,7 +24,20 @@ class UpateRetriedForCiBuild < ActiveRecord::Migration ...@@ -23,7 +24,20 @@ class UpateRetriedForCiBuild < ActiveRecord::Migration
query.where(table[:retried].eq(nil)) query.where(table[:retried].eq(nil))
end end
end end
end
def down def down
end end
def with_temporary_partial_index
if Gitlab::Database.postgresql?
execute 'CREATE INDEX CONCURRENTLY IF NOT EXISTS index_for_ci_builds_retried_migration ON ci_builds (id) WHERE retried IS NULL;'
end
yield
if Gitlab::Database.postgresql?
execute 'DROP INDEX CONCURRENTLY IF EXISTS index_for_ci_builds_retried_migration'
end
end
end end
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