summaryrefslogtreecommitdiff
path: root/db/post_migrate/20210302074524_backfill_namespace_statistics_with_wiki_size.rb
blob: e04f69f4206cfd470e2832b263005b5198de72c3 (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 BackfillNamespaceStatisticsWithWikiSize < ActiveRecord::Migration[6.0]
  include Gitlab::Database::MigrationHelpers

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

  disable_ddl_transaction!

  def up
    return unless Gitlab.ee?

    groups = exec_query <<~SQL
      SELECT group_wiki_repositories.group_id
      FROM group_wiki_repositories
    SQL

    groups.rows.flatten.in_groups_of(BATCH_SIZE, false).each_with_index do |group_ids, index|
      migrate_in(index * DELAY_INTERVAL, MIGRATION, [group_ids, [:wiki_size]])
    end
  end

  def down
    # No-op
  end
end