summaryrefslogtreecommitdiff
path: root/db/post_migrate/20170711145558_migrate_stages_statuses.rb
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-07-11 14:31:04 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-07-11 14:31:04 +0200
commitbb67b4749b5b4c62d4235c90dc0320967f850cdd (patch)
treead8c213bfa95e7e2128f5eebdacdb54138ce7756 /db/post_migrate/20170711145558_migrate_stages_statuses.rb
parent65b3c220090d8fbfcfb2c4ba3b4d70d3c30fd7e3 (diff)
downloadgitlab-ce-bb67b4749b5b4c62d4235c90dc0320967f850cdd.tar.gz
Update version number of stages statuses migration
Diffstat (limited to 'db/post_migrate/20170711145558_migrate_stages_statuses.rb')
-rw-r--r--db/post_migrate/20170711145558_migrate_stages_statuses.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/db/post_migrate/20170711145558_migrate_stages_statuses.rb b/db/post_migrate/20170711145558_migrate_stages_statuses.rb
new file mode 100644
index 00000000000..1641e550480
--- /dev/null
+++ b/db/post_migrate/20170711145558_migrate_stages_statuses.rb
@@ -0,0 +1,35 @@
+class MigrateStagesStatuses < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ BATCH_SIZE = 10000
+ RANGE_SIZE = 1000
+ MIGRATION = 'MigrateStageStatus'.freeze
+
+ class Stage < ActiveRecord::Base
+ self.table_name = 'ci_stages'
+ include ::EachBatch
+ end
+
+ def up
+ Stage.where(status: nil).each_batch(of: BATCH_SIZE) do |relation, index|
+ relation.each_batch(of: RANGE_SIZE) do |batch|
+ range = relation.pluck('MIN(id)', 'MAX(id)').first
+ schedule = index * 5.minutes
+
+ BackgroundMigrationWorker.perform_in(schedule, MIGRATION, range)
+ end
+ end
+ end
+
+ def down
+ disable_statement_timeout
+
+ execute <<-SQL.strip_heredoc
+ UPDATE ci_stages SET status = null
+ SQL
+ end
+end