summaryrefslogtreecommitdiff
path: root/db/post_migrate/20220915192521_prepare_async_trigram_index_for_vulnerability_reads_container_images.rb
blob: 18ed1b2cd2b08b754a03729006b0ee503cc4f6cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# frozen_string_literal: true

class PrepareAsyncTrigramIndexForVulnerabilityReadsContainerImages < Gitlab::Database::Migration[2.0]
  disable_ddl_transaction!

  INDEX_NAME = 'index_vulnerability_reads_on_location_image_trigram'
  REPORT_TYPES = { container_scanning: 2, cluster_image_scanning: 7 }.freeze

  def up
    prepare_async_index :vulnerability_reads, :location_image,
      name: INDEX_NAME,
      using: :gin, opclass: { location_image: :gin_trgm_ops },
      where: "report_type = ANY (ARRAY[#{REPORT_TYPES.values.join(', ')}]) AND location_image IS NOT NULL"
  end

  def down
    unprepare_async_index :vulnerability_reads, :location_image, name: INDEX_NAME
  end
end