Class: Gitlab::BackgroundMigration::PopulateUserHighestRolesTable

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/background_migration/populate_user_highest_roles_table.rb

Overview

This background migration creates records on user_highest_roles according to the given user IDs range. IDs will load users with a left outer joins to have a record for users without a Group or Project. One INSERT per ID is issued.

Defined Under Namespace

Classes: User

Constant Summary collapse

BATCH_SIZE =
100

Instance Method Summary collapse

Instance Method Details

#perform(from_id, to_id) ⇒ Object


22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/gitlab/background_migration/populate_user_highest_roles_table.rb', line 22

def perform(from_id, to_id)
  return unless User.column_names.include?('bot_type')

  (from_id..to_id).each_slice(BATCH_SIZE) do |ids|
    execute(
      <<-EOF
        INSERT INTO user_highest_roles (updated_at, user_id, highest_access_level)
        #{select_sql(from_id, to_id)}
        ON CONFLICT (user_id) DO
        UPDATE SET highest_access_level = EXCLUDED.highest_access_level
      EOF
    )
  end
end