diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-01 18:07:45 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-01 18:07:45 +0300 |
commit | 1219a9dce91f4edbc135dfc08299b4122b4825a8 (patch) | |
tree | e7d12a55d75a2d56e60d9527bef3724e3578866d /db/post_migrate | |
parent | 1a0d6dbdc2ac3047f4953a359ef27ba6e26074ae (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'db/post_migrate')
-rw-r--r-- | db/post_migrate/20200311130802_schedule_populate_user_highest_roles_table.rb | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/db/post_migrate/20200311130802_schedule_populate_user_highest_roles_table.rb b/db/post_migrate/20200311130802_schedule_populate_user_highest_roles_table.rb new file mode 100644 index 00000000000..36f0d42a855 --- /dev/null +++ b/db/post_migrate/20200311130802_schedule_populate_user_highest_roles_table.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +class SchedulePopulateUserHighestRolesTable < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + BATCH_SIZE = 10_000 + DELAY = 5.minutes.to_i + DOWNTIME = false + MIGRATION = 'PopulateUserHighestRolesTable' + + disable_ddl_transaction! + + class User < ActiveRecord::Base + include EachBatch + + scope :active, -> { + where(state: 'active', user_type: nil, bot_type: nil) + .where('ghost IS NOT TRUE') + } + end + + def up + # We currently have ~5_300_000 users with the state active on GitLab.com. + # This means it'll schedule ~530 jobs (10k Users each) with a 5 minutes gap, + # so this should take ~44 hours for all background migrations to complete. + User.active.each_batch(of: BATCH_SIZE) do |batch, index| + range = batch.pluck(Arel.sql('MIN(id)'), Arel.sql('MAX(id)')).first + delay = index * DELAY + + migrate_in(delay.seconds, MIGRATION, [*range]) + end + end + + def down + # nothing + end +end |