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
path: root/db
diff options
context:
space:
mode:
authorOswaldo Ferreira <oswaldo@gitlab.com>2018-05-28 23:18:43 +0300
committerOswaldo Ferreira <oswaldo@gitlab.com>2018-05-30 17:51:29 +0300
commit54ad5fb8a2b9e90a83cd5714d935b8ea0664eb03 (patch)
treef8e3e0d4b5edde851a372d6d1bda479b88e0d29b /db
parenta8c97187f07cc4feeec9347967a12680cf5aec37 (diff)
Take two for MR metrics population background migration
Diffstat (limited to 'db')
-rw-r--r--db/post_migrate/20180521162137_migrate_remaining_mr_metrics_populating_background_migration.rb44
1 files changed, 44 insertions, 0 deletions
diff --git a/db/post_migrate/20180521162137_migrate_remaining_mr_metrics_populating_background_migration.rb b/db/post_migrate/20180521162137_migrate_remaining_mr_metrics_populating_background_migration.rb
new file mode 100644
index 00000000000..0282688fa40
--- /dev/null
+++ b/db/post_migrate/20180521162137_migrate_remaining_mr_metrics_populating_background_migration.rb
@@ -0,0 +1,44 @@
+class MigrateRemainingMrMetricsPopulatingBackgroundMigration < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+ BATCH_SIZE = 5_000
+ MIGRATION = 'PopulateMergeRequestMetricsWithEventsData'
+ DELAY_INTERVAL = 10.minutes
+
+ disable_ddl_transaction!
+
+ class MergeRequest < ActiveRecord::Base
+ self.table_name = 'merge_requests'
+
+ include ::EachBatch
+ end
+
+ def up
+ # Perform any ongoing background migration that might still be running. This
+ # avoids scheduling way too many of the same jobs on self-hosted instances
+ # if they're updating GitLab across multiple versions. The "Take one"
+ # migration was executed on 10.4 on
+ # SchedulePopulateMergeRequestMetricsWithEventsData.
+ Gitlab::BackgroundMigration.steal(MIGRATION)
+
+ metrics_not_exists_clause = <<~SQL
+ NOT EXISTS (SELECT 1 FROM merge_request_metrics
+ WHERE merge_request_metrics.merge_request_id = merge_requests.id)
+ SQL
+
+ relation = MergeRequest.where(metrics_not_exists_clause)
+
+ # We currently have ~400_000 MR records without metrics on GitLab.com.
+ # This means it'll schedule ~80 jobs (5000 MRs each) with a 10 minutes gap,
+ # so this should take ~14 hours for all background migrations to complete.
+ #
+ queue_background_migration_jobs_by_range_at_intervals(relation,
+ MIGRATION,
+ DELAY_INTERVAL,
+ batch_size: BATCH_SIZE)
+ end
+
+ def down
+ end
+end