Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2018-11-07 09:51:48 +0300
committerSean McGivern <sean@mcgivern.me.uk>2018-11-07 09:51:48 +0300
commit1b788c66a1b1861d8dcca14785d22c59e31713fd (patch)
tree90bcb8aca6fba513bda4296b0143febce1f4a21f /db/post_migrate
parent6da118095b6d3b7a1cf306a82841cb265d7d8016 (diff)
parentbb55bcddb80adf017d82758587761f413674d985 (diff)
Merge branch 'sh-fix-issue-52649' into 'master'
Fix statement timeouts in RemoveRestrictedTodos migration Closes #52649 See merge request gitlab-org/gitlab-ce!22795
Diffstat (limited to 'db/post_migrate')
-rw-r--r--db/post_migrate/20181107054254_remove_restricted_todos_again.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/db/post_migrate/20181107054254_remove_restricted_todos_again.rb b/db/post_migrate/20181107054254_remove_restricted_todos_again.rb
new file mode 100644
index 00000000000..644e0074c46
--- /dev/null
+++ b/db/post_migrate/20181107054254_remove_restricted_todos_again.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+# rescheduling of the revised RemoveRestrictedTodosWithCte background migration
+class RemoveRestrictedTodosAgain < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ 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