diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2017-08-21 11:47:44 +0000 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2017-08-21 11:47:44 +0000 |
commit | e00e62c2c8ddf8d12145660a3478065caab4c4ca (patch) | |
tree | df5600704090efccaa399816556696e4487c4e36 /db/post_migrate | |
parent | d6547ce0e78e2eecac76af8509cc5f7eea5fc369 (diff) | |
parent | 3a1103fd9173e8cb7a70c871d6a54a846f6eee4a (diff) | |
download | gitlab-ce-e00e62c2c8ddf8d12145660a3478065caab4c4ca.tar.gz |
Merge branch 'backstage/gb/migrate-stages-statuses' into 'master'
Migrate CI/CD stages statuses
Closes #33453
See merge request !12584
Diffstat (limited to 'db/post_migrate')
-rw-r--r-- | db/post_migrate/20170711145558_migrate_stages_statuses.rb | 33 |
1 files changed, 33 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..5a24fb1307f --- /dev/null +++ b/db/post_migrate/20170711145558_migrate_stages_statuses.rb @@ -0,0 +1,33 @@ +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 + + update_column_in_batches(:ci_stages, :status, nil) + end +end |