20181119132520_add_indexes_to_ci_builds_and_pipelines.rb 1.08 KB
Newer Older
1 2
# frozen_string_literal: true

3
class AddIndexesToCiBuildsAndPipelines < ActiveRecord::Migration[5.0]
4 5 6 7 8 9 10
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false

  disable_ddl_transaction!

  def up
11 12 13
    indexes.each do |index|
      add_concurrent_index(*index)
    end
14 15 16
  end

  def down
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
    indexes.each do |index|
      remove_concurrent_index(*index)
    end
  end

  private

  def indexes
    [
      [
        :ci_pipelines,
        [:project_id, :ref, :id],
        {
          order: { id: :desc },
          name: 'index_ci_pipelines_on_project_idandrefandiddesc'
        }
      ],
      [
        :ci_builds,
        [:commit_id, :artifacts_expire_at, :id],
        {
          where: "type::text = 'Ci::Build'::text AND (retried = false OR retried IS NULL) AND (name::text = ANY (ARRAY['sast'::character varying, 'dependency_scanning'::character varying, 'sast:container'::character varying, 'container_scanning'::character varying, 'dast'::character varying]::text[]))",
          name: 'index_ci_builds_on_commit_id_and_artifacts_expireatandidpartial'
        }
      ]
    ]
43 44
  end
end