summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Shutsin <pshutsin@gitlab.com>2019-08-01 10:42:34 +0300
committerPavel Shutsin <pshutsin@gitlab.com>2019-08-28 14:51:51 +0300
commit174fc98d7a48ba9ca7499fa0a98b0d38305ea882 (patch)
tree96fdb2632774a9a8c5b69f604797f35701447eff
parentf91b5d5840996736ee18ef457653cdd225f8445f (diff)
downloadgitlab-ce-backport-schedule-productivity-analytics-backfill.tar.gz
Schedule ProductivityAnalytics backfillbackport-schedule-productivity-analytics-backfill
-rw-r--r--changelogs/unreleased/backport-schedule-productivity-analytics-backfill.yml5
-rw-r--r--db/post_migrate/20190724091326_schedule_productivity_analytics_backfill.rb31
2 files changed, 36 insertions, 0 deletions
diff --git a/changelogs/unreleased/backport-schedule-productivity-analytics-backfill.yml b/changelogs/unreleased/backport-schedule-productivity-analytics-backfill.yml
new file mode 100644
index 00000000000..d611dac01ca
--- /dev/null
+++ b/changelogs/unreleased/backport-schedule-productivity-analytics-backfill.yml
@@ -0,0 +1,5 @@
+---
+title: Schedule productivity analytics recalculation for EE
+merge_request: 31367
+author:
+type: other
diff --git a/db/post_migrate/20190724091326_schedule_productivity_analytics_backfill.rb b/db/post_migrate/20190724091326_schedule_productivity_analytics_backfill.rb
new file mode 100644
index 00000000000..ba8a4243828
--- /dev/null
+++ b/db/post_migrate/20190724091326_schedule_productivity_analytics_backfill.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+class ScheduleProductivityAnalyticsBackfill < ActiveRecord::Migration[5.2]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ BATCH_SIZE = 100_000
+ INTERVAL = 2.minutes
+ MIGRATION = 'Gitlab::BackgroundMigration::RecalculateProductivityAnalytics'.freeze
+
+ disable_ddl_transaction!
+
+ def up
+ return unless MIGRATION.safe_constantize
+
+ metrics_model = Class.new(ActiveRecord::Base) do
+ self.table_name = 'merge_request_metrics'
+
+ include ::EachBatch
+ end
+
+ scope = metrics_model.where("merged_at >= ?", 3.months.ago)
+
+ queue_background_migration_jobs_by_range_at_intervals(scope, MIGRATION, INTERVAL, batch_size: BATCH_SIZE)
+ end
+
+ def down
+ # no-op
+ end
+end