summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2018-03-09 12:57:06 +0000
committerYorick Peterse <yorickpeterse@gmail.com>2018-03-09 12:57:06 +0000
commitcd7fcfd5779716c302608ce462996809f952ceec (patch)
treecd928742fc7bced2c6b3a260177f525ef5bfc268 /db
parent1221035824fa35490765e34ed7633edd6f44fae3 (diff)
parent7b22381603d4f2cddc87b1b70e5be076df63cf01 (diff)
downloadgitlab-ce-cd7fcfd5779716c302608ce462996809f952ceec.tar.gz
Merge branch 'jprovazn-commits-count-reschedule' into 'master'
Reschedule commits_count background migration See merge request gitlab-org/gitlab-ce!17599
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20180309121820_reschedule_commits_count_for_merge_request_diff.rb30
-rw-r--r--db/schema.rb2
2 files changed, 31 insertions, 1 deletions
diff --git a/db/migrate/20180309121820_reschedule_commits_count_for_merge_request_diff.rb b/db/migrate/20180309121820_reschedule_commits_count_for_merge_request_diff.rb
new file mode 100644
index 00000000000..990759104b0
--- /dev/null
+++ b/db/migrate/20180309121820_reschedule_commits_count_for_merge_request_diff.rb
@@ -0,0 +1,30 @@
+class RescheduleCommitsCountForMergeRequestDiff < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ MIGRATION = 'AddMergeRequestDiffCommitsCount'.freeze
+ BATCH_SIZE = 5000
+ DELAY_INTERVAL = 5.minutes.to_i
+
+ class MergeRequestDiff < ActiveRecord::Base
+ self.table_name = 'merge_request_diffs'
+
+ include ::EachBatch
+ end
+
+ disable_ddl_transaction!
+
+ def up
+ say 'Populating the MergeRequestDiff `commits_count` (reschedule)'
+
+ execute("SET statement_timeout TO '60s'") if Gitlab::Database.postgresql?
+
+ MergeRequestDiff.where(commits_count: nil).each_batch(of: BATCH_SIZE) do |relation, index|
+ start_id, end_id = relation.pluck('MIN(id), MAX(id)').first
+ delay = index * DELAY_INTERVAL
+
+ BackgroundMigrationWorker.perform_in(delay, MIGRATION, [start_id, end_id])
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 75a094bbbb6..970b1ad9948 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20180308052825) do
+ActiveRecord::Schema.define(version: 20180309121820) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"