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

20200709101408_schedule_populate_project_snippet_statistics.rb « post_migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 28527e67f4ae404da44d6b9f4acd0e7c2cf77011 (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
25
26
27
28
29
30
# frozen_string_literal: true

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

  DOWNTIME = false
  DELAY_INTERVAL = 2.minutes.to_i
  BATCH_SIZE = 500
  MIGRATION = 'PopulateProjectSnippetStatistics'

  disable_ddl_transaction!

  def up
    snippets = exec_query <<~SQL
      SELECT snippets.id
      FROM snippets
      INNER JOIN projects ON projects.id = snippets.project_id
      WHERE snippets.type = 'ProjectSnippet'
      ORDER BY projects.namespace_id ASC, snippets.project_id ASC, snippets.id ASC
    SQL

    snippets.rows.flatten.in_groups_of(BATCH_SIZE, false).each_with_index do |snippet_ids, index|
      migrate_in(index * DELAY_INTERVAL, MIGRATION, [snippet_ids])
    end
  end

  def down
    # no-op
  end
end