summaryrefslogtreecommitdiff
path: root/db/post_migrate/20201103192526_schedule_populate_has_vulnerabilities.rb
diff options
context:
space:
mode:
Diffstat (limited to 'db/post_migrate/20201103192526_schedule_populate_has_vulnerabilities.rb')
-rw-r--r--db/post_migrate/20201103192526_schedule_populate_has_vulnerabilities.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/db/post_migrate/20201103192526_schedule_populate_has_vulnerabilities.rb b/db/post_migrate/20201103192526_schedule_populate_has_vulnerabilities.rb
new file mode 100644
index 00000000000..bed90af09dc
--- /dev/null
+++ b/db/post_migrate/20201103192526_schedule_populate_has_vulnerabilities.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+class SchedulePopulateHasVulnerabilities < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+ BATCH_SIZE = 1_000
+ DELAY_INTERVAL = 2.minutes
+ MIGRATION_CLASS = 'PopulateHasVulnerabilities'
+
+ disable_ddl_transaction!
+
+ def up
+ Gitlab::BackgroundMigration::PopulateHasVulnerabilities::Vulnerability.distinct.each_batch(of: BATCH_SIZE, column: :project_id) do |batch, index|
+ project_ids = batch.pluck(:project_id)
+
+ migrate_in(index * DELAY_INTERVAL, MIGRATION_CLASS, project_ids)
+ end
+ end
+
+ def down
+ # no-op
+ end
+end