diff options
Diffstat (limited to 'db/post_migrate/20200110121314_schedule_update_existing_subgroup_to_match_visibility_level_of_parent.rb')
-rw-r--r-- | db/post_migrate/20200110121314_schedule_update_existing_subgroup_to_match_visibility_level_of_parent.rb | 56 |
1 files changed, 0 insertions, 56 deletions
diff --git a/db/post_migrate/20200110121314_schedule_update_existing_subgroup_to_match_visibility_level_of_parent.rb b/db/post_migrate/20200110121314_schedule_update_existing_subgroup_to_match_visibility_level_of_parent.rb deleted file mode 100644 index 813cd600ddc..00000000000 --- a/db/post_migrate/20200110121314_schedule_update_existing_subgroup_to_match_visibility_level_of_parent.rb +++ /dev/null @@ -1,56 +0,0 @@ -# frozen_string_literal: true - -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class ScheduleUpdateExistingSubgroupToMatchVisibilityLevelOfParent < ActiveRecord::Migration[5.2] - include Gitlab::Database::MigrationHelpers - - DOWNTIME = false - MIGRATION = 'UpdateExistingSubgroupToMatchVisibilityLevelOfParent' - DELAY_INTERVAL = 5.minutes.to_i - BATCH_SIZE = 1000 - VISIBILITY_LEVELS = { - internal: 10, - private: 0 - } - - disable_ddl_transaction! - - def up - offset = update_groups(VISIBILITY_LEVELS[:internal]) - update_groups(VISIBILITY_LEVELS[:private], offset: offset) - end - - def down - # no-op - end - - private - - def update_groups(level, offset: 0) - groups = exec_query <<~SQL - SELECT id - FROM namespaces - WHERE visibility_level = #{level} - AND type = 'Group' - AND EXISTS (SELECT 1 - FROM namespaces AS children - WHERE children.parent_id = namespaces.id) - SQL - - ids = groups.rows.flatten - - iterator = 1 - - ids.in_groups_of(BATCH_SIZE, false) do |batch_of_ids| - delay = DELAY_INTERVAL * (iterator + offset) - BackgroundMigrationWorker.perform_in(delay, MIGRATION, [batch_of_ids, level]) - iterator += 1 - end - - say("Background jobs for visibility level #{level} scheduled in #{iterator} iterations") - - offset + iterator - end -end |