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

20210505092746_create_partial_covering_index_for_pending_builds.rb « post_migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 81fe65c194527de31f9ae6d9b3e3beac112c6763 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# frozen_string_literal: true

class CreatePartialCoveringIndexForPendingBuilds < ActiveRecord::Migration[6.0]
  include Gitlab::Database::MigrationHelpers

  disable_ddl_transaction!

  EXISTING_INDEX = 'index_ci_builds_runner_id_pending'
  NEW_INDEX = 'index_ci_builds_runner_id_pending_covering'

  def up
    disable_statement_timeout do
      execute "CREATE INDEX CONCURRENTLY #{NEW_INDEX} ON ci_builds (runner_id, id) INCLUDE (project_id) WHERE status = 'pending' AND type = 'Ci::Build'" unless index_exists_by_name?(:ci_builds, NEW_INDEX)
    end

    remove_concurrent_index_by_name :ci_builds, EXISTING_INDEX
  end

  def down
    add_concurrent_index :ci_builds, :runner_id, where: "status = 'pending' AND type = 'Ci::Build'", name: EXISTING_INDEX

    remove_concurrent_index_by_name :ci_builds, NEW_INDEX
  end
end