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

20200714075739_schedule_populate_personal_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: c3033da24fe975f1bc173e8877100d277cdbdf0d (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
# frozen_string_literal: true

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

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

  disable_ddl_transaction!

  def up
    snippets = exec_query <<~SQL
      SELECT id
      FROM snippets
      WHERE type = 'PersonalSnippet'
      ORDER BY author_id ASC, 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