diff options
author | Jarka Kadlecová <jarka@gitlab.com> | 2018-07-26 13:35:37 +0300 |
---|---|---|
committer | Jarka Kadlecová <jarka@gitlab.com> | 2018-08-07 18:34:59 +0300 |
commit | 8338f9b89bfbc2e2db28041b271f471ed7a7960e (patch) | |
tree | e38e0edb81c485167fc2e79a8916a4e229583101 /db/migrate | |
parent | 0d729d5c54b8c1f87f915eb365e8abc189828b68 (diff) |
Remove todos of users without access to targets migration
Diffstat (limited to 'db/migrate')
-rw-r--r-- | db/migrate/20180717125853_remove_restricted_todos.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/db/migrate/20180717125853_remove_restricted_todos.rb b/db/migrate/20180717125853_remove_restricted_todos.rb new file mode 100644 index 00000000000..fdf43921a73 --- /dev/null +++ b/db/migrate/20180717125853_remove_restricted_todos.rb @@ -0,0 +1,31 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. +# frozen_string_literal: true + +class RemoveRestrictedTodos < ActiveRecord::Migration + DOWNTIME = false + disable_ddl_transaction! + + MIGRATION = 'RemoveRestrictedTodos'.freeze + BATCH_SIZE = 1000 + DELAY_INTERVAL = 5.minutes.to_i + + class Project < ActiveRecord::Base + include EachBatch + + self.table_name = 'projects' + end + + def up + Project.where('EXISTS (SELECT 1 FROM todos WHERE todos.project_id = projects.id)') + .each_batch(of: BATCH_SIZE) do |batch, index| + range = batch.pluck('MIN(id)', 'MAX(id)').first + + BackgroundMigrationWorker.perform_in(index * DELAY_INTERVAL, MIGRATION, range) + end + end + + def down + # nothing to do + end +end |