blob: 5881869ee3ccc7e20ec2f2de2bc1923860a82e7a (
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
31
32
33
34
35
|
# frozen_string_literal: true
class CompleteNamespaceSettingsMigration < ActiveRecord::Migration[5.2]
DOWNTIME = false
BATCH_SIZE = 10000
class Namespace < ActiveRecord::Base
include EachBatch
self.table_name = 'namespaces'
end
def up
Gitlab::BackgroundMigration.steal('BackfillNamespaceSettings')
ensure_data_migration
end
def down
# no-op
end
private
def ensure_data_migration
Namespace.each_batch(of: BATCH_SIZE) do |query|
missing_count = query.where("NOT EXISTS (SELECT 1 FROM namespace_settings WHERE namespace_settings.namespace_id=namespaces.id)").limit(1).size
if missing_count > 0
min, max = query.pluck("MIN(id), MAX(id)").flatten
# we expect low record count so inline execution is fine.
Gitlab::BackgroundMigration::BackfillNamespaceSettings.new.perform(min, max)
end
end
end
end
|